Skip to content

Commit

Permalink
Deal with some tests failing when time-travelling
Browse files Browse the repository at this point in the history
See #472.
  • Loading branch information
MatthiasValvekens committed Oct 20, 2024
1 parent 0c5cd7f commit 5bbc2ea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pyhanko_tests/test_pades.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ def test_pades_revinfo_live_update(requests_mock):
assert emb_sig is r.embedded_regular_signatures[0]


@freeze_time('2020-11-01')
def test_update_no_timestamps():
r = PdfFileReader(BytesIO(MINIMAL))
output = PdfTimeStamper(DUMMY_TS).update_archival_timestamp_chain(
Expand Down Expand Up @@ -575,6 +576,7 @@ def _test_pades_revinfo_live_lta(w, requests_mock, **kwargs):
_test_pades_revinfo_live_lta_validate(out, requests_mock)


@freeze_time('2020-11-01')
def test_pades_lta_dss_indirect_arrs(requests_mock):
testfile = PDF_DATA_DIR + '/pades-lta-dss-indirect-arrs-test.pdf'
live_testing_vc(requests_mock)
Expand Down
21 changes: 21 additions & 0 deletions pyhanko_tests/test_seed_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ async def sign_with_sv(
return EmbeddedPdfSignature(r, s.sig_field, s.fq_name)


@freeze_time('2020-11-01')
@pytest.mark.asyncio
async def test_sv_sign_md_req():
sv = fields.SigSeedValueSpec(
Expand Down Expand Up @@ -460,6 +461,7 @@ async def test_sv_sign_md_req():
assert emb_sig.md_algorithm == 'sha512'


@freeze_time('2020-11-01')
@pytest.mark.asyncio
async def test_sv_sign_md_hint():
sv = fields.SigSeedValueSpec(digest_methods=['sha256', 'sha512'])
Expand All @@ -478,6 +480,7 @@ async def test_sv_sign_md_hint():
assert emb_sig.md_algorithm == 'sha512'


@freeze_time('2020-11-01')
@pytest.mark.asyncio
async def test_sv_sign_subfilter_req():
sv = fields.SigSeedValueSpec(
Expand Down Expand Up @@ -507,6 +510,7 @@ async def test_sv_sign_subfilter_req():
assert emb_sig.sig_object['/SubFilter'] == PADES.value


@freeze_time('2020-11-01')
@pytest.mark.asyncio
async def test_sv_sign_subfilter_hint():
sv = fields.SigSeedValueSpec(subfilters=[PADES])
Expand Down Expand Up @@ -656,6 +660,7 @@ async def test_add_revinfo_wrong_subfilter():
assert not status.seed_value_ok


@freeze_time('2020-11-01')
@pytest.mark.asyncio
async def test_sv_sign_cert_constraint():
# this is more thoroughly unit tested at a lower level (see further up),
Expand All @@ -680,6 +685,7 @@ async def test_sv_sign_cert_constraint():
)


@freeze_time('2020-11-01')
@pytest.mark.asyncio
async def test_sv_flag_unsupported():
sv = fields.SigSeedValueSpec(
Expand All @@ -695,6 +701,7 @@ async def test_sv_flag_unsupported():
await sign_with_sv(sv, meta, test_violation=True)


@freeze_time('2020-11-01')
@pytest.mark.asyncio
async def test_sv_cert_flag_unsupported():
sv = fields.SigSeedValueSpec(
Expand All @@ -707,6 +714,7 @@ async def test_sv_cert_flag_unsupported():
await sign_with_sv(sv, meta)


@freeze_time('2020-11-01')
@pytest.mark.asyncio
async def test_sv_flag_appearance_required():
sv = fields.SigSeedValueSpec(
Expand All @@ -717,6 +725,7 @@ async def test_sv_flag_appearance_required():
await sign_with_sv(sv, meta)


@freeze_time('2020-11-01')
@pytest.mark.asyncio
async def test_sv_mdp_no_certify():
sv = fields.SigSeedValueSpec(
Expand All @@ -733,6 +742,7 @@ async def test_sv_mdp_no_certify():
await sign_with_sv(sv, meta, test_violation=True)


@freeze_time('2020-11-01')
@pytest.mark.asyncio
async def test_sv_mdp_must_certify():
sv = fields.SigSeedValueSpec(
Expand All @@ -756,6 +766,7 @@ async def test_sv_mdp_must_certify():
await sign_with_sv(sv, meta, test_violation=True)


@freeze_time('2020-11-01')
@pytest.mark.asyncio
async def test_sv_mdp_must_certify_wrong_docmdp():
sv = fields.SigSeedValueSpec(
Expand All @@ -770,6 +781,7 @@ async def test_sv_mdp_must_certify_wrong_docmdp():
await sign_with_sv(sv, meta)


@freeze_time('2020-11-01')
def test_sv_subfilter_unsupported():
sv_spec = fields.SigSeedValueSpec(
flags=fields.SigSeedValFlags.SUBFILTER, subfilters=[PADES]
Expand Down Expand Up @@ -801,6 +813,7 @@ def test_sv_subfilter_unsupported():
)


@freeze_time('2020-11-01')
def test_sv_subfilter_unsupported_partial():
sv_spec = fields.SigSeedValueSpec(
flags=fields.SigSeedValFlags.SUBFILTER,
Expand Down Expand Up @@ -835,6 +848,7 @@ def test_sv_subfilter_unsupported_partial():
)


@freeze_time('2020-11-01')
@pytest.mark.asyncio
async def test_sv_timestamp_url(requests_mock):
# state issues (see comment in signers.py), so create a fresh signer
Expand All @@ -859,6 +873,7 @@ def ts_callback(*args, **kwargs):
assert ts_requested


@freeze_time('2020-11-01')
@pytest.mark.asyncio
async def test_sv_sign_reason_req():
sv = fields.SigSeedValueSpec(
Expand All @@ -882,6 +897,7 @@ async def test_sv_sign_reason_req():
assert emb_sig.sig_object['/Reason'] == 'I agree'


@freeze_time('2020-11-01')
@pytest.mark.parametrize('reasons_param', [None, [], ["."]])
@pytest.mark.asyncio
async def test_sv_sign_reason_prohibited(reasons_param):
Expand All @@ -904,6 +920,7 @@ async def test_sv_sign_reason_prohibited(reasons_param):
assert pdf_name('/Reason') not in emb_sig.sig_object


@freeze_time('2020-11-01')
@pytest.mark.asyncio
async def test_sv_lock_certify():
sv = fields.SigSeedValueSpec(
Expand Down Expand Up @@ -933,6 +950,7 @@ async def test_sv_lock_certify():
await sign_with_sv(sv, meta)


@freeze_time('2020-11-01')
@pytest.mark.asyncio
async def test_sv_no_lock_certify():
sv = fields.SigSeedValueSpec(
Expand Down Expand Up @@ -970,6 +988,7 @@ async def test_sv_no_lock_certify():
await sign_with_sv(sv, meta, test_violation=True)


@freeze_time('2020-11-01')
@pytest.mark.asyncio
async def test_field_lock_compat():
sv = fields.SigSeedValueSpec(
Expand All @@ -988,6 +1007,7 @@ async def test_field_lock_compat():
await sign_with_sv(sv, meta, add_field_lock=True)


@freeze_time('2020-11-01')
@pytest.mark.parametrize(
'must_have_set, forbidden_set, as_string',
[
Expand Down Expand Up @@ -1051,6 +1071,7 @@ def test_cert_constraint_deserialisation():
assert constr_parsed.subject_dn == signer1.subject


@freeze_time('2020-11-01')
@pytest.mark.asyncio
async def test_sign_with_sv_missing_cert():
w = IncrementalPdfFileWriter(
Expand Down

0 comments on commit 5bbc2ea

Please sign in to comment.