Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps): bump the pinned-test-dependencies group across 2 directories with 2 updates #499

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions repo/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ tuf-on-ci-update-targets = "tuf_on_ci:update_targets"

[project.optional-dependencies]
lint = [
"mypy == 1.13.0",
"ruff == 0.8.3",
"mypy == 1.14.1",
"ruff == 0.8.4",
]

[tool.hatch.version]
Expand Down
4 changes: 2 additions & 2 deletions signer/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ tuf-on-ci-sign = "tuf_on_ci_sign:sign"

[project.optional-dependencies]
lint = [
"mypy == 1.13.0",
"ruff == 0.8.3",
"mypy == 1.14.1",
"ruff == 0.8.4",
]

[tool.hatch.version]
Expand Down
35 changes: 33 additions & 2 deletions signer/test/test_user.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import os
import platform
import unittest
from tempfile import TemporaryDirectory

import click
from securesystemslib.signer import HSMSigner, SSlibKey

from tuf_on_ci_sign import _user
from tuf_on_ci_sign._user import User

# Long lines are ok here
# ruff: noqa: E501

REQUIRED = """
[settings]
user-name = @signer
push-remote = origin
pull-remote = myremote
"""

WITH_PYKCS11LIB = """
[settings]
pykcs11lib = /usr/lib/x86_64-linux-gnu/libykcs11.so
user-name = @signer
push-remote = origin
Expand Down Expand Up @@ -71,7 +79,7 @@ def test_required(self):
with TemporaryDirectory() as tempdir:
inifile = os.path.join(tempdir, ".tuf-on-ci-sign.ini")
with open(inifile, "w") as f:
f.write(REQUIRED)
f.write(WITH_PYKCS11LIB)

user = User(inifile)
self.assertEqual(user.name, "@signer")
Expand All @@ -90,6 +98,29 @@ def test_required(self):
with self.assertRaises(click.ClickException):
user = User(inifile)

def test_pkcs_prober(self):
with TemporaryDirectory() as tempdir:
inifile = os.path.join(tempdir, ".tuf-on-ci-sign.ini")
with open(inifile, "w") as f:
f.write(REQUIRED)

nonexistent_pkcs11lib = os.path.join(tempdir, "nonexistent-pkcs11lib")
mock_pkcs11lib = os.path.join(tempdir, "mock-pkcs11lib")
with open(mock_pkcs11lib, "w") as f:
f.write("")

# mock prober lookup locations so that a library is not found:
_user.LIBYKCS11_LOCATIONS = {platform.system(): [nonexistent_pkcs11lib]}
with self.assertRaises(click.ClickException):
User(inifile)

# mock prober lookup locations so that a library is found:
_user.LIBYKCS11_LOCATIONS = {
platform.system(): [nonexistent_pkcs11lib, mock_pkcs11lib]
}
user = User(inifile)
self.assertEqual(user.pykcs11lib, mock_pkcs11lib)

def test_signing_keys(self):
with TemporaryDirectory() as tempdir:
inifile = os.path.join(tempdir, ".tuf-on-ci-sign.ini")
Expand Down
9 changes: 5 additions & 4 deletions signer/tuf_on_ci_sign/_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,16 @@ def __init__(self, path: str):
self._signing_key_uris = {}

# probe for pykcs11lib if it's not set
self.pykcs11lib = self._config["settings"].get("pykcs11lib")
if self.pykcs11lib is None:
try:
self.pykcs11lib = self._config["settings"]["pykcs11lib"]
except KeyError:
for loc in LIBYKCS11_LOCATIONS.get(platform.system(), []):
if os.path.exists(loc):
self.pykcs11lib = loc
logger.debug("Using probed YKCS11 location %s", self.pykcs11lib)
break
if self.pykcs11lib is None:
else:
raise click.ClickException("Failed to find libykcs11")
logger.debug("Using probed YKCS11 location %s", self.pykcs11lib)

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