diff --git a/pyhanko_tests/test_ades_validation_report.py b/pyhanko_tests/test_ades_validation_report.py index e41bcb58..300f8fd9 100644 --- a/pyhanko_tests/test_ades_validation_report.py +++ b/pyhanko_tests/test_ades_validation_report.py @@ -8,6 +8,7 @@ from pyhanko.pdf_utils.reader import PdfFileReader from pyhanko.sign import signers from pyhanko.sign.validation import ades +from pyhanko.sign.validation.policy_decl import PdfSignatureValidationSpec from .samples import MINIMAL_ONE_FIELD from .signing_commons import DUMMY_TS, FROM_CA, FROM_ECC_CA, live_testing_vc @@ -19,6 +20,20 @@ ) +async def _generate_basic_report(requests_mock, out): + with freeze_time('2020-11-25'): + r = PdfFileReader(out) + live_testing_vc(requests_mock) + result = await ades.ades_basic_validation( + r.embedded_signatures[0].signed_data, + validation_spec=DEFAULT_SIG_VALIDATION_SPEC, + raw_digest=r.embedded_signatures[0].compute_digest(), + ) + from pyhanko.sign.validation.report.tools import generate_report + + return generate_report(r.embedded_signatures[0], result) + + @pytest.mark.asyncio @py38_only async def test_pades_basic_report_smoke_test(requests_mock): @@ -30,19 +45,8 @@ async def test_pades_basic_report_smoke_test(requests_mock): signer=FROM_CA, timestamper=DUMMY_TS, ) - - with freeze_time('2020-11-25'): - r = PdfFileReader(out) - live_testing_vc(requests_mock) - result = await ades.ades_basic_validation( - r.embedded_signatures[0].signed_data, - validation_spec=DEFAULT_SIG_VALIDATION_SPEC, - raw_digest=r.embedded_signatures[0].compute_digest(), - ) - from pyhanko.sign.validation.report.tools import generate_report - - report = generate_report(r.embedded_signatures[0], result) - assert 'urn:etsi:019102:mainindication:total-passed' in report + report = await _generate_basic_report(requests_mock, out) + assert 'urn:etsi:019102:mainindication:total-passed' in report @pytest.mark.asyncio @@ -59,18 +63,8 @@ async def test_pades_basic_failing_report_smoke_test(requests_mock): out.seek(10) out.write(b'@') - with freeze_time('2020-11-25'): - r = PdfFileReader(out) - live_testing_vc(requests_mock) - result = await ades.ades_basic_validation( - r.embedded_signatures[0].signed_data, - validation_spec=DEFAULT_SIG_VALIDATION_SPEC, - raw_digest=r.embedded_signatures[0].compute_digest(), - ) - from pyhanko.sign.validation.report.tools import generate_report - - report = generate_report(r.embedded_signatures[0], result) - assert 'urn:etsi:019102:mainindication:total-failed' in report + report = await _generate_basic_report(requests_mock, out) + assert 'urn:etsi:019102:mainindication:total-failed' in report @pytest.mark.asyncio @@ -85,15 +79,41 @@ async def test_pades_basic_indeteriminate_report_smoke_test(requests_mock): timestamper=DUMMY_TS, ) - with freeze_time('2020-11-25'): + report = await _generate_basic_report(requests_mock, out) + assert 'urn:etsi:019102:mainindication:indeterminate' in report + + +async def _generate_lta_report(requests_mock, out): + with freeze_time('2028-11-25'): r = PdfFileReader(out) live_testing_vc(requests_mock) - result = await ades.ades_basic_validation( - r.embedded_signatures[0].signed_data, - validation_spec=DEFAULT_SIG_VALIDATION_SPEC, - raw_digest=r.embedded_signatures[0].compute_digest(), + result = await ades.ades_lta_validation( + r.embedded_signatures[0], + pdf_validation_spec=PdfSignatureValidationSpec( + signature_validation_spec=DEFAULT_SIG_VALIDATION_SPEC + ), ) from pyhanko.sign.validation.report.tools import generate_report - report = generate_report(r.embedded_signatures[0], result) - assert 'urn:etsi:019102:mainindication:indeterminate' in report + return generate_report(r.embedded_signatures[0], result) + + +@pytest.mark.asyncio +@py38_only +async def test_pades_lta_report_smoke_test(requests_mock): + with freeze_time('2020-11-20'): + w = IncrementalPdfFileWriter(BytesIO(MINIMAL_ONE_FIELD)) + out = await signers.async_sign_pdf( + w, + signers.PdfSignatureMetadata( + field_name='Sig1', + subfilter=PADES, + use_pades_lta=True, + validation_context=live_testing_vc(requests_mock), + ), + signer=FROM_CA, + timestamper=DUMMY_TS, + ) + report = await _generate_lta_report(requests_mock, out) + assert 'urn:etsi:019102:mainindication:total-passed' in report + assert 'urn:etsi:019102:validationprocess:LTA' in report