Exemple #1
0
def test_sv_mdp_type():
    sv_dict = fields.SigSeedValueSpec().as_pdf_object()
    assert '/MDP' not in sv_dict
    sv_dict = fields.SigSeedValueSpec(
        seed_signature_type=fields.SeedSignatureType(None)).as_pdf_object()
    assert sv_dict['/MDP'] == generic.DictionaryObject(
        {pdf_name('/P'): generic.NumberObject(0)})
    sv_dict = fields.SigSeedValueSpec(
        seed_signature_type=fields.SeedSignatureType(
            fields.MDPPerm.NO_CHANGES)).as_pdf_object()
    assert sv_dict['/MDP'] == generic.DictionaryObject(
        {pdf_name('/P'): generic.NumberObject(1)})

    sv_spec = fields.SigSeedValueSpec.from_pdf_object(
        generic.DictionaryObject({
            pdf_name('/MDP'):
            generic.DictionaryObject({pdf_name('/P'): generic.NumberObject(0)})
        }))
    assert sv_spec.seed_signature_type == fields.SeedSignatureType(None)

    sv_spec = fields.SigSeedValueSpec.from_pdf_object(
        generic.DictionaryObject({
            pdf_name('/MDP'):
            generic.DictionaryObject({pdf_name('/P'): generic.NumberObject(2)})
        }))
    assert sv_spec.seed_signature_type == fields.SeedSignatureType(
        fields.MDPPerm.FILL_FORMS)

    with pytest.raises(SigningError):
        fields.SigSeedValueSpec.from_pdf_object(
            generic.DictionaryObject({
                pdf_name('/MDP'):
                generic.DictionaryObject(
                    {pdf_name('/P'): generic.NumberObject(5)})
            }))
    with pytest.raises(SigningError):
        fields.SigSeedValueSpec.from_pdf_object(
            generic.DictionaryObject({
                pdf_name('/MDP'):
                generic.DictionaryObject(
                    {pdf_name('/P'): generic.NullObject()})
            }))
    with pytest.raises(SigningError):
        fields.SigSeedValueSpec.from_pdf_object(
            generic.DictionaryObject(
                {pdf_name('/MDP'): generic.DictionaryObject()}))
    with pytest.raises(SigningError):
        fields.SigSeedValueSpec.from_pdf_object(
            generic.DictionaryObject({pdf_name('/MDP'): generic.NullObject()}))
Exemple #2
0
def test_sv_mdp_must_certify_wrong_docmdp():

    sv = fields.SigSeedValueSpec(seed_signature_type=fields.SeedSignatureType(
        fields.MDPPerm.FILL_FORMS), )
    meta = signers.PdfSignatureMetadata(
        field_name='Sig',
        certify=True,
        docmdp_permissions=fields.MDPPerm.NO_CHANGES)
    with pytest.raises(SigningError):
        sign_with_sv(sv, meta)
Exemple #3
0
def test_sv_mdp_no_certify():

    sv = fields.SigSeedValueSpec(
        seed_signature_type=fields.SeedSignatureType(), )
    meta = signers.PdfSignatureMetadata(field_name='Sig')
    sign_with_sv(sv, meta)

    meta = signers.PdfSignatureMetadata(field_name='Sig', certify=True)
    with pytest.raises(SigningError):
        sign_with_sv(sv, meta)

    meta = signers.PdfSignatureMetadata(field_name='Sig', certify=True)
    sign_with_sv(sv, meta, test_violation=True)