Skip to content

Commit f330501

Browse files
authored
Run the test suite with GitHub actions. (#190)
Run the test suite using GitHub actions. Other minor improvements: * Use `UV_PYTHON_PREFERENCE=only-system` (as recommended in uv docs, brings a minor speedup). * Fix a test case (OpenSSL now requires `-CAFile` for verification). * Add Dockerfile to test running on different distributions. * Remove `.travis.yml` file (no longer needed). Note that the Dockerfile can be used to indeed verify that OpenSSL 3.0.10 and oscrypto have a problem: On Ubuntu 24.04: ```console $ docker build --build-arg IMAGE=ubuntu:24.04 -t test . ... $ docker run --rm -it test OpenSSL 3.0.13 30 Jan 2024 (Library: OpenSSL 3.0.13 30 Jan 2024) $ docker run --rm -it test ... .venv/lib/python3.12/site-packages/oscrypto/_openssl/_libcrypto_cffi.py:44: LibraryNotFoundError ===================================================================================================================== short test summary info ====================================================================================================================== FAILED tests/test_public_key_external.py::ExternalPublicKeyTests::test_rsa - oscrypto.errors.LibraryNotFoundError: Error detecting the version of libcrypto FAILED tests/test_public_key_external.py::ExternalPublicKeyTests::test_terrible_hybrid_file_encryption_app - oscrypto.errors.LibraryNotFoundError: Error detecting the version of libcrypto == 2 failed, 82 passed, 5 skipped, 1 xfailed in 0.80s == ``` While on Ubuntu 22.04: ```console # docker build --build-arg IMAGE=ubuntu:22.04 -t test . ... $ docker run --rm -it test openssl version OpenSSL 3.0.2 15 Mar 2022 (Library: OpenSSL 3.0.2 15 Mar 2022) $ docker run --rm -it test == 84 passed, 5 skipped, 1 xfailed in 0.80s == ```
1 parent a71b7e6 commit f330501

File tree

7 files changed

+163
-54
lines changed

7 files changed

+163
-54
lines changed

.github/workflows/quality.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: Code quality
22
on:
33
push:
4+
env:
5+
UV_PYTHON_PREFERENCE: only-system
46
jobs:
57
run:
68
runs-on: ubuntu-latest
@@ -20,7 +22,7 @@ jobs:
2022
architecture: x64
2123

2224
- name: Install dev dependencies
23-
run: uv sync --python-preference only-system
25+
run: uv sync
2426

2527
- name: ruff format
2628
run: uv run ruff format --diff .

.github/workflows/tests.yml

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Tests
2+
on:
3+
push:
4+
env:
5+
UV_PYTHON_PREFERENCE: only-system
6+
PKCS11_TOKEN_LABEL: TEST
7+
PKCS11_TOKEN_PIN: 1234
8+
PKCS11_TOKEN_SO_PIN: 5678
9+
jobs:
10+
run:
11+
# Run in Ubuntu 22.04 right now, as oscrypto fails on OpenSSL versions with a
12+
# double-digit patch number (such as provided by Ubuntu 24.04):
13+
# https://community.snowflake.com/s/article/Python-Connector-fails-to-connect-with-LibraryNotFoundError-Error-detecting-the-version-of-libcrypto
14+
# https://github.com/wbond/oscrypto/issues/78
15+
runs-on: ubuntu-22.04
16+
strategy:
17+
matrix:
18+
python-version:
19+
- "3.9"
20+
- "3.10"
21+
- "3.11"
22+
- "3.12"
23+
- "3.13"
24+
25+
steps:
26+
- name: Acquire sources
27+
uses: actions/[email protected]
28+
29+
- name: Setup Python
30+
uses: actions/[email protected]
31+
with:
32+
python-version: ${{ matrix.python-version }}
33+
architecture: x64
34+
35+
- name: Install uv
36+
uses: astral-sh/setup-uv@v4
37+
with:
38+
enable-cache: true
39+
python-version: ${{ matrix.python-version }}
40+
41+
- name: Install dev dependencies
42+
run: uv sync --all-extras
43+
44+
# Locally compile softhsmv2. For unknown reasons, the version installed by Ubuntu fails on
45+
# Github Actions (while working e.g. in Docker).
46+
- name: Install Softhsm
47+
run: |
48+
curl https://dist.opendnssec.org/source/softhsm-2.6.1.tar.gz | tar -zxv
49+
(cd softhsm-2.6.1 && ./configure --prefix=$HOME --disable-p11-kit --disable-gost && make all install CC="gcc" CXX="g++")
50+
echo "$HOME/bin" >> "$GITHUB_PATH"
51+
echo "PKCS11_MODULE=$HOME/lib/softhsm/libsofthsm2.so" >> "$GITHUB_ENV"
52+
53+
- name: Initialize token
54+
run: softhsm2-util --init-token --free --label $PKCS11_TOKEN_LABEL --pin $PKCS11_TOKEN_PIN --so-pin $PKCS11_TOKEN_SO_PIN
55+
56+
- name: Run tests
57+
run: uv run pytest -v

.travis.yml

-45
This file was deleted.

Dockerfile

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
ARG IMAGE=debian:stable
2+
FROM $IMAGE
3+
4+
RUN apt-get update && \
5+
DEBIAN_FRONTEND="noninteractive" apt-get install -y gcc python3 python3-dev softhsm2 openssl && \
6+
rm -rf /var/lib/apt/lists/*
7+
8+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
9+
10+
WORKDIR /test
11+
12+
ADD uv.lock pyproject.toml setup.py .
13+
ADD pkcs11/ pkcs11/
14+
ADD extern/ extern/
15+
16+
ENV UV_LINK_MODE=copy
17+
RUN --mount=type=cache,target=/root/.cache/uv \
18+
uv sync --all-extras
19+
20+
ENV PKCS11_MODULE=/usr/lib/softhsm/libsofthsm2.so
21+
ENV PKCS11_TOKEN_LABEL=TEST
22+
ENV PKCS11_TOKEN_PIN=1234
23+
ENV PKCS11_TOKEN_SO_PIN=5678
24+
RUN softhsm2-util --init-token --free --label TEST --pin 1234 --so-pin 5678
25+
26+
ADD tests/ tests/
27+
CMD ["uv", "run", "pytest", "-v"]

pyproject.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@ include = ["pkcs11*"]
6060
dev = [
6161
"cryptography>=44.0.0",
6262
"oscrypto>=1.3.0",
63+
"parameterized>=0.9.0",
64+
"pytest>=8.3.4",
6365
"ruff>=0.8.3",
6466
"setuptools>=75.6.0",
6567
"setuptools-scm>=8.1.0",
6668
"sphinx>=7.4.7",
6769
"sphinx-rtd-theme>=3.0.2",
68-
]
70+
]

tests/test_x509.py

+16-7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import base64
66
import datetime
77
import subprocess
8+
import tempfile
89

910
from asn1crypto import pem
1011
from asn1crypto.csr import CertificationRequest, CertificationRequestInfo
@@ -223,13 +224,21 @@ def test_self_sign_certificate(self):
223224
}
224225
)
225226

226-
# Pipe our certificate to OpenSSL to verify it
227-
with subprocess.Popen(
228-
(OPENSSL, "verify"), stdin=subprocess.PIPE, stdout=subprocess.DEVNULL
229-
) as proc:
230-
proc.stdin.write(pem.armor("CERTIFICATE", cert.dump()))
231-
proc.stdin.close()
232-
self.assertEqual(proc.wait(), 0)
227+
pem_cert = pem.armor("CERTIFICATE", cert.dump())
228+
229+
with tempfile.NamedTemporaryFile() as pem_file:
230+
pem_file.write(pem_cert)
231+
pem_file.flush()
232+
233+
# Pipe our certificate to OpenSSL to verify it
234+
with subprocess.Popen(
235+
(OPENSSL, "verify", "-CAfile", pem_file.name),
236+
stdin=subprocess.PIPE,
237+
stdout=subprocess.DEVNULL,
238+
) as proc:
239+
proc.stdin.write(pem.armor("CERTIFICATE", cert.dump()))
240+
proc.stdin.close()
241+
self.assertEqual(proc.wait(), 0)
233242

234243
@Only.openssl
235244
@requires(Mechanism.RSA_PKCS_KEY_PAIR_GEN, Mechanism.SHA1_RSA_PKCS)

uv.lock

+57
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)