Skip to content

Commit c56f516

Browse files
committed
signer: run HSM tests as part of regular tests
Running HSM tests in a separate workflow on all Python version and os combinations requires 15 additional runners. This is a bit of an overkill. This patch integrates the HSMTests with regular CI: - Make hsm test module discoverable for aggregate_tests by changing the module name. - Skip HSM tests if PYKCS11LIB is not set, so aggregate_tests can be executed without SoftHSM installed. (e.g. locally by devs) - Remove dedicated HSM test env from tox.ini. Tests now run as part of default testenv. - Require PYKCS11LIB to be set for that testenv. - Remove dedicated HSM requirements files and add them to default requirement file, which already includes optional requirements. - Re-compile pinned requirements file. Signed-off-by: Lukas Puehringer <[email protected]>
1 parent 1bc3dd6 commit c56f516

8 files changed

+52
-91
lines changed

.github/workflows/ci.yml

+21
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,26 @@ jobs:
5252
python -m pip install --upgrade pip
5353
pip install --upgrade tox
5454
55+
- name: Install system dependencies
56+
shell: bash
57+
run: |
58+
if [ "$RUNNER_OS" == "Linux" ]; then
59+
sudo apt-get install -y softhsm2
60+
echo "PYKCS11LIB=/usr/lib/softhsm/libsofthsm2.so" >> $GITHUB_ENV
61+
62+
elif [ "$RUNNER_OS" == "macOS" ]; then
63+
brew install softhsm
64+
echo "PYKCS11LIB=$(brew --prefix softhsm)/lib/softhsm/libsofthsm2.so" >> $GITHUB_ENV
65+
66+
# TODO: Uncomment when testing on Windows
67+
# elif [ "$RUNNER_OS" == "Windows" ]; then
68+
# choco install softhsm.install
69+
# echo "PYKCS11LIB=C:\SoftHSM2\lib\softhsm2-x64.dll" >> $GITHUB_ENV
70+
71+
else
72+
echo "$RUNNER_OS not supported"
73+
exit 1
74+
fi
75+
5576
- name: Run tox
5677
run: tox -e ${{ matrix.toxenv }}

.github/workflows/hsm.yml

-59
This file was deleted.

requirements-hsm-pinned.txt

-16
This file was deleted.

requirements-hsm.txt

-3
This file was deleted.

requirements-pinned.txt

+22-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
1-
cffi==1.15.1 # via cryptography, pynacl
2-
cryptography==38.0.3
3-
pycparser==2.21 # via cffi
1+
#
2+
# This file is autogenerated by pip-compile with python 3.8
3+
# To update, run:
4+
#
5+
# pip-compile --output-file=requirements-pinned.txt requirements.txt
6+
#
7+
asn1crypto==1.5.1
8+
# via -r requirements.txt
9+
cffi==1.15.1
10+
# via
11+
# cryptography
12+
# pynacl
13+
# pyspx
14+
cryptography==38.0.3 ; python_version >= "3"
15+
# via -r requirements.txt
16+
pycparser==2.21
17+
# via cffi
18+
pykcs11==1.5.11
19+
# via -r requirements.txt
420
pynacl==1.5.0
5-
six==1.16.0 # via pynacl
6-
PySPX==0.5.0
21+
# via -r requirements.txt
22+
pyspx==0.5.0
23+
# via -r requirements.txt

requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@
3434
cryptography >= 37.0.0; python_version >= '3'
3535
pynacl
3636
PySPX
37+
PyKCS11
38+
asn1crypto

tests/check_hsm_signer.py tests/test_hsm_signer.py

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
from securesystemslib.signer import HSMSigner, SSlibKey
2727

2828

29+
@unittest.skipUnless(
30+
os.environ["PYKCS11LIB"], "set PYKCS11LIB to SoftHSM lib path"
31+
)
2932
class TestHSM(unittest.TestCase):
3033
"""Test HSMSigner with SoftHSM
3134

tox.ini

+4-8
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ skipsdist = True
1111
install_command =
1212
pip install {opts} {packages}
1313

14+
passenv =
15+
PYKCS11LIB
16+
1417
deps =
1518
-r{toxinidir}/requirements-pinned.txt
1619
-r{toxinidir}/requirements-test.txt
1720

1821
commands =
1922
python -m tests.check_gpg_available
23+
python -c '"{env:PYKCS11LIB}"' # Required for 'test_hsm_signer'
2024
coverage run tests/aggregate_tests.py
2125
coverage report -m --fail-under 95
2226

@@ -42,14 +46,6 @@ passenv =
4246
commands =
4347
python -m tests.check_kms_signers
4448

45-
[testenv:hsm]
46-
deps =
47-
-r{toxinidir}/requirements-hsm-pinned.txt
48-
passenv =
49-
PYKCS11LIB
50-
commands =
51-
python -m tests.check_hsm_signer
52-
5349
# This checks that importing securesystemslib.gpg.constants doesn't shell out on
5450
# import.
5551
[testenv:py311-test-gpg-fails]

0 commit comments

Comments
 (0)