Exemplo n.º 1
0
def test_assertion_with_authn_instant():
    ava = {}
    ast = Assertion(ava)
    policy = Policy({
        "default": {
            "lifetime": {"minutes": 240},
            "attribute_restrictions": None,  # means all I have
            "name_form": NAME_FORMAT_URI
        },
    })
    name_id = NameID(format=NAMEID_FORMAT_TRANSIENT, text="foobar")
    issuer = Issuer(text="entityid", format=NAMEID_FORMAT_ENTITY)
    msg = ast.construct("sp_entity_id", "in_response_to", "consumer_url",
                        name_id, [AttributeConverterNOOP(NAME_FORMAT_URI)],
                        policy, issuer=issuer, authn_decl=ACD,
                        authn_auth="authn_authn",
                        authn_instant=1234567890)

    print(msg)
    assert msg.authn_statement[0].authn_instant == "2009-02-13T23:31:30Z"
Exemplo n.º 2
0
def test_assertion_with_noop_attribute_conv():
    ava = {"urn:oid:2.5.4.4": "Roland", "urn:oid:2.5.4.42": "Hedberg"}
    ast = Assertion(ava)
    policy = Policy({
        "default": {
            "lifetime": {
                "minutes": 240
            },
            "attribute_restrictions": None,  # means all I have
            "name_form": NAME_FORMAT_URI
        },
    })
    name_id = NameID(format=NAMEID_FORMAT_TRANSIENT, text="foobar")
    issuer = Issuer(text="entityid", format=NAMEID_FORMAT_ENTITY)

    farg = add_path(
        {}, ['subject', 'subject_confirmation', 'method', saml.SCM_BEARER])
    add_path(farg['subject']['subject_confirmation'],
             ['subject_confirmation_data', 'in_response_to', 'in_response_to'])
    add_path(farg['subject']['subject_confirmation'],
             ['subject_confirmation_data', 'recipient', 'consumer_url'])

    msg = ast.construct("sp_entity_id",
                        [AttributeConverterNOOP(NAME_FORMAT_URI)],
                        policy,
                        issuer=issuer,
                        farg=farg,
                        authn_decl=ACD,
                        name_id=name_id,
                        authn_auth="authn_authn")

    print(msg)
    for attr in msg.attribute_statement[0].attribute:
        assert attr.name_format == NAME_FORMAT_URI
        assert len(attr.attribute_value) == 1
        if attr.name == "urn:oid:2.5.4.42":
            assert attr.attribute_value[0].text == "Hedberg"
        elif attr.name == "urn:oid:2.5.4.4":
            assert attr.attribute_value[0].text == "Roland"