Skip to content

Commit

Permalink
Add LTA test to report tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthiasValvekens committed Nov 16, 2023
1 parent 10e0b27 commit 8874d25
Showing 1 changed file with 52 additions and 32 deletions.
84 changes: 52 additions & 32 deletions pyhanko_tests/test_ades_validation_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

0 comments on commit 8874d25

Please sign in to comment.