Skip to content

Commit 2cff5eb

Browse files
dependabot[bot]jku
andauthored
build(deps): bump the pinned-test-dependencies group across 2 directories with 2 updates (#499)
* build(deps): bump the pinned-test-dependencies group across 2 directories with 2 updates Bumps the pinned-test-dependencies group with 2 updates in the /repo directory: [mypy](https://github.com/python/mypy) and [ruff](https://github.com/astral-sh/ruff). Bumps the pinned-test-dependencies group with 2 updates in the /signer directory: [mypy](https://github.com/python/mypy) and [ruff](https://github.com/astral-sh/ruff). Updates `mypy` from 1.13.0 to 1.14.1 - [Changelog](https://github.com/python/mypy/blob/master/CHANGELOG.md) - [Commits](python/mypy@v1.13.0...v1.14.1) Updates `ruff` from 0.8.3 to 0.8.4 - [Release notes](https://github.com/astral-sh/ruff/releases) - [Changelog](https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md) - [Commits](astral-sh/ruff@0.8.3...0.8.4) Updates `mypy` from 1.13.0 to 1.14.1 - [Changelog](https://github.com/python/mypy/blob/master/CHANGELOG.md) - [Commits](python/mypy@v1.13.0...v1.14.1) Updates `ruff` from 0.8.3 to 0.8.4 - [Release notes](https://github.com/astral-sh/ruff/releases) - [Changelog](https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md) - [Commits](astral-sh/ruff@0.8.3...0.8.4) --- updated-dependencies: - dependency-name: mypy dependency-type: direct:production update-type: version-update:semver-minor dependency-group: pinned-test-dependencies - dependency-name: ruff dependency-type: direct:production update-type: version-update:semver-patch dependency-group: pinned-test-dependencies - dependency-name: mypy dependency-type: direct:production update-type: version-update:semver-minor dependency-group: pinned-test-dependencies - dependency-name: ruff dependency-type: direct:production update-type: version-update:semver-patch dependency-group: pinned-test-dependencies ... Signed-off-by: dependabot[bot] <[email protected]> * signer: Fix typing issue in User class User.pykcs11lib cannot be None (not after initialization): make that visible to static analyzers by tweaking the code. Also add a test for the pykcs11lib probing. --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jussi Kukkonen <[email protected]>
1 parent b1daf4b commit 2cff5eb

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed

repo/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ tuf-on-ci-update-targets = "tuf_on_ci:update_targets"
2929

3030
[project.optional-dependencies]
3131
lint = [
32-
"mypy == 1.13.0",
33-
"ruff == 0.8.3",
32+
"mypy == 1.14.1",
33+
"ruff == 0.8.4",
3434
]
3535

3636
[tool.hatch.version]

signer/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ tuf-on-ci-sign = "tuf_on_ci_sign:sign"
2323

2424
[project.optional-dependencies]
2525
lint = [
26-
"mypy == 1.13.0",
27-
"ruff == 0.8.3",
26+
"mypy == 1.14.1",
27+
"ruff == 0.8.4",
2828
]
2929

3030
[tool.hatch.version]

signer/test/test_user.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
import os
2+
import platform
23
import unittest
34
from tempfile import TemporaryDirectory
45

56
import click
67
from securesystemslib.signer import HSMSigner, SSlibKey
78

9+
from tuf_on_ci_sign import _user
810
from tuf_on_ci_sign._user import User
911

1012
# Long lines are ok here
1113
# ruff: noqa: E501
12-
1314
REQUIRED = """
1415
[settings]
16+
user-name = @signer
17+
push-remote = origin
18+
pull-remote = myremote
19+
"""
20+
21+
WITH_PYKCS11LIB = """
22+
[settings]
1523
pykcs11lib = /usr/lib/x86_64-linux-gnu/libykcs11.so
1624
user-name = @signer
1725
push-remote = origin
@@ -71,7 +79,7 @@ def test_required(self):
7179
with TemporaryDirectory() as tempdir:
7280
inifile = os.path.join(tempdir, ".tuf-on-ci-sign.ini")
7381
with open(inifile, "w") as f:
74-
f.write(REQUIRED)
82+
f.write(WITH_PYKCS11LIB)
7583

7684
user = User(inifile)
7785
self.assertEqual(user.name, "@signer")
@@ -90,6 +98,29 @@ def test_required(self):
9098
with self.assertRaises(click.ClickException):
9199
user = User(inifile)
92100

101+
def test_pkcs_prober(self):
102+
with TemporaryDirectory() as tempdir:
103+
inifile = os.path.join(tempdir, ".tuf-on-ci-sign.ini")
104+
with open(inifile, "w") as f:
105+
f.write(REQUIRED)
106+
107+
nonexistent_pkcs11lib = os.path.join(tempdir, "nonexistent-pkcs11lib")
108+
mock_pkcs11lib = os.path.join(tempdir, "mock-pkcs11lib")
109+
with open(mock_pkcs11lib, "w") as f:
110+
f.write("")
111+
112+
# mock prober lookup locations so that a library is not found:
113+
_user.LIBYKCS11_LOCATIONS = {platform.system(): [nonexistent_pkcs11lib]}
114+
with self.assertRaises(click.ClickException):
115+
User(inifile)
116+
117+
# mock prober lookup locations so that a library is found:
118+
_user.LIBYKCS11_LOCATIONS = {
119+
platform.system(): [nonexistent_pkcs11lib, mock_pkcs11lib]
120+
}
121+
user = User(inifile)
122+
self.assertEqual(user.pykcs11lib, mock_pkcs11lib)
123+
93124
def test_signing_keys(self):
94125
with TemporaryDirectory() as tempdir:
95126
inifile = os.path.join(tempdir, ".tuf-on-ci-sign.ini")

signer/tuf_on_ci_sign/_user.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,16 @@ def __init__(self, path: str):
5555
self._signing_key_uris = {}
5656

5757
# probe for pykcs11lib if it's not set
58-
self.pykcs11lib = self._config["settings"].get("pykcs11lib")
59-
if self.pykcs11lib is None:
58+
try:
59+
self.pykcs11lib = self._config["settings"]["pykcs11lib"]
60+
except KeyError:
6061
for loc in LIBYKCS11_LOCATIONS.get(platform.system(), []):
6162
if os.path.exists(loc):
6263
self.pykcs11lib = loc
64+
logger.debug("Using probed YKCS11 location %s", self.pykcs11lib)
6365
break
64-
if self.pykcs11lib is None:
66+
else:
6567
raise click.ClickException("Failed to find libykcs11")
66-
logger.debug("Using probed YKCS11 location %s", self.pykcs11lib)
6768

6869
# signer cache gets populated as they are used the first time
6970
self._signers: dict[str, Signer] = {}

0 commit comments

Comments
 (0)