Add unit tests for timestamping_enricher

This commit is contained in:
Patrick Robertson
2025-01-29 12:20:52 +01:00
parent dcd5576f29
commit 4c1c8953ca
3 changed files with 58 additions and 8 deletions

Binary file not shown.

View File

@@ -0,0 +1,41 @@
import pytest
from auto_archiver.modules.timestamping_enricher.timestamping_enricher import TimestampingEnricher
@pytest.fixture
def digicert():
with open("tests/data/timestamp_token_digicert_com.crt", "rb") as f:
return f.read()
@pytest.mark.download
def test_sign_data(setup_module):
tsa_url = "http://timestamp.digicert.com"
tsp: TimestampingEnricher = setup_module("timestamping_enricher")
data = b"4b7b4e39f12b8c725e6e603e6d4422500316df94211070682ef10260ff5759ef"
result: bytes = tsp.sign_data(tsa_url, data)
assert isinstance(result, bytes)
try:
tsp.verify_signed(result, data)
except Exception as e:
pytest.fail(f"Verification failed: {e}")
def test_tsp_enricher_download_syndication(setup_module, digicert):
tsp: TimestampingEnricher = setup_module("timestamping_enricher")
try:
cert_chain = tsp.download_and_verify_certificate(digicert)
assert len(cert_chain) == 3
assert cert_chain[0].filename == "/var/folders/h7/g67pz_kx67q7qxzzrrhvry5r0000gn/T/74515005589773707779.crt"
assert cert_chain[1].filename == "/var/folders/h7/g67pz_kx67q7qxzzrrhvry5r0000gn/T/95861100433808324400.crt"
assert cert_chain[2].filename == "/var/folders/h7/g67pz_kx67q7qxzzrrhvry5r0000gn/T/15527051335772373346.crt"
except Exception as e:
pytest.fail(f"Verification failed: {e}")
def test_tst_cert_valid(setup_module, digicert):
tsp: TimestampingEnricher = setup_module("timestamping_enricher")
try:
tsp.verify_signed(digicert, b"4b7b4e39f12b8c725e6e603e6d4422500316df94211070682ef10260ff5759ef")
except Exception as e:
pytest.fail(f"Verification failed: {e}")