Ejemplo n.º 1
0
def test_construct_AttributeAuthorityDescriptor():
    aad = make_instance(
        md.AttributeAuthorityDescriptor,
        {
            "valid_until": time_util.in_a_while(30),  # 30 days from now
            "id": "aad.example.com",
            "protocol_support_enumeration": SAML2_NAMESPACE,
            "attribute_service": {"binding": BINDING_SOAP, "location": "http://example.com:6543/saml2/aad"},
            "name_id_format": [NAMEID_FORMAT_TRANSIENT],
            "key_descriptor": {"use": "signing", "key_info": {"key_name": "example.com"}},
        },
    )

    print aad
    assert _eq(
        aad.keyswv(),
        ["valid_until", "id", "attribute_service", "name_id_format", "key_descriptor", "protocol_support_enumeration"],
    )
    assert time_util.str_to_time(aad.valid_until)
    assert aad.id == "aad.example.com"
    assert aad.protocol_support_enumeration == SAML2_NAMESPACE
    assert len(aad.attribute_service) == 1
    atsr = aad.attribute_service[0]
    assert _eq(atsr.keyswv(), ["binding", "location"])
    assert atsr.binding == BINDING_SOAP
    assert atsr.location == "http://example.com:6543/saml2/aad"
    assert len(aad.name_id_format) == 1
    nif = aad.name_id_format[0]
    assert nif.text.strip() == NAMEID_FORMAT_TRANSIENT
    assert len(aad.key_descriptor) == 1
    kdesc = aad.key_descriptor[0]
    assert kdesc.use == "signing"
    assert kdesc.key_info.key_name[0].text.strip() == "example.com"
Ejemplo n.º 2
0
def test_construct_entity_descr_2():
    ed = make_instance(
        md.EntityDescriptor, {
            "organization": {
                "organization_name": "Catalogix",
                "organization_url": "http://www.catalogix.se/"
            },
            "entity_id": "urn:mace:catalogix.se:sp1",
            "contact_person": {
                "given_name": "Roland",
                "sur_name": "Hedberg",
                "email_address": "*****@*****.**",
            }
        })

    assert _eq(ed.keyswv(), ["entity_id", "contact_person", "organization"])
    assert ed.entity_id == "urn:mace:catalogix.se:sp1"
    org = ed.organization
    assert org
    assert _eq(org.keyswv(), ["organization_name", "organization_url"])
    assert len(org.organization_name) == 1
    assert org.organization_name[0].text == "Catalogix"
    assert org.organization_url[0].text == "http://www.catalogix.se/"
    assert len(ed.contact_person) == 1
    c = ed.contact_person[0]
    assert c.given_name.text == "Roland"
    assert c.sur_name.text == "Hedberg"
    assert c.email_address[0].text == "*****@*****.**"
    assert _eq(c.keyswv(), ["given_name", "sur_name", "email_address"])
Ejemplo n.º 3
0
def test_status():
    input = {
        "status_code": {"value": samlp.STATUS_RESPONDER, "status_code": {"value": samlp.STATUS_UNKNOWN_PRINCIPAL}},
        "status_message": "Error resolving principal",
    }
    status_text = "%s" % make_instance(samlp.Status, input)
    assert status_text == STATUS_RESULT
Ejemplo n.º 4
0
def test_construct_entity_descr_2():
    ed = make_instance(md.EntityDescriptor,
        {"organization": {
            "organization_name":"Catalogix", 
            "organization_url": "http://www.catalogix.se/"},
         "entity_id": "urn:mace:catalogix.se:sp1",
         "contact_person": {
            "given_name":"Roland",
            "sur_name": "Hedberg",
            "email_address": "*****@*****.**",
            }   
        })

    assert _eq(ed.keyswv(), ["entity_id", "contact_person", "organization"])
    assert ed.entity_id == "urn:mace:catalogix.se:sp1"
    org = ed.organization
    assert org
    assert _eq(org.keyswv(), ["organization_name", "organization_url"])
    assert len(org.organization_name) == 1
    assert org.organization_name[0].text == "Catalogix"
    assert org.organization_url[0].text == "http://www.catalogix.se/"
    assert len(ed.contact_person) == 1
    c = ed.contact_person[0]
    assert c.given_name.text == "Roland"
    assert c.sur_name.text == "Hedberg"
    assert c.email_address[0].text == "*****@*****.**"    
    assert _eq(c.keyswv(), ["given_name","sur_name","email_address"])
Ejemplo n.º 5
0
def test_construct_contact():
    c = make_instance(
        md.ContactPerson, {"given_name": "Roland", "sur_name": "Hedberg", "email_address": "*****@*****.**"}
    )
    print c
    assert c.given_name.text == "Roland"
    assert c.sur_name.text == "Hedberg"
    assert c.email_address[0].text == "*****@*****.**"
    assert _eq(c.keyswv(), ["given_name", "sur_name", "email_address"])
Ejemplo n.º 6
0
def test_status():
    input = {
        "status_code": {
            "value": samlp.STATUS_RESPONDER,
            "status_code": {
                "value": samlp.STATUS_UNKNOWN_PRINCIPAL,
            },
        },
        "status_message": "Error resolving principal",
    }
    status_text = "%s" % make_instance(samlp.Status, input)
    assert status_text == STATUS_RESULT
Ejemplo n.º 7
0
def test_construct_contact():
    c = make_instance(
        md.ContactPerson, {
            "given_name": "Roland",
            "sur_name": "Hedberg",
            "email_address": "*****@*****.**",
        })
    print c
    assert c.given_name.text == "Roland"
    assert c.sur_name.text == "Hedberg"
    assert c.email_address[0].text == "*****@*****.**"
    assert _eq(c.keyswv(), ["given_name", "sur_name", "email_address"])
Ejemplo n.º 8
0
def test_construct_organisation():
    c = make_instance( md.Organization, {
            "organization_name": ["Example Co.",
                    {"text":"Exempel AB", "lang":"se"}],
            "organization_url": "http://www.example.com/"
        })
        
    assert _eq(c.keyswv(), ["organization_name","organization_url"])
    assert len(c.organization_name) == 2
    org_names = [on.text for on in c.organization_name]
    assert _eq(org_names,["Exempel AB","Example Co."])
    assert len(c.organization_url) == 1
Ejemplo n.º 9
0
def test_construct_key_descriptor():
    cert = "".join(_read_lines("test.pem")[1:-1]).strip()
    spec = {"use": "signing", "key_info": {"x509_data": {"x509_certificate": cert}}}
    kd = make_instance(md.KeyDescriptor, spec)
    assert _eq(kd.keyswv(), ["use", "key_info"])
    assert kd.use == "signing"
    ki = kd.key_info
    assert _eq(ki.keyswv(), ["x509_data"])
    assert len(ki.x509_data) == 1
    data = ki.x509_data[0]
    assert _eq(data.keyswv(), ["x509_certificate"])
    assert data.x509_certificate
    assert len(data.x509_certificate.text.strip()) == len(cert)
Ejemplo n.º 10
0
def test_construct_entity_descr_1():
    ed = make_instance(md.EntityDescriptor,
        {"organization": {
            "organization_name":"Catalogix", 
            "organization_url": "http://www.catalogix.se/"},
         "entity_id": "urn:mace:catalogix.se:sp1",   
        })

    assert ed.entity_id == "urn:mace:catalogix.se:sp1"
    org = ed.organization
    assert org
    assert _eq(org.keyswv(), ["organization_name","organization_url"])
    assert len(org.organization_name) == 1
    assert org.organization_name[0].text == "Catalogix"
    assert org.organization_url[0].text == "http://www.catalogix.se/"
Ejemplo n.º 11
0
def test_construct_entity_descr_1():
    ed = make_instance(
        md.EntityDescriptor, {
            "organization": {
                "organization_name": "Catalogix",
                "organization_url": "http://www.catalogix.se/"
            },
            "entity_id": "urn:mace:catalogix.se:sp1",
        })

    assert ed.entity_id == "urn:mace:catalogix.se:sp1"
    org = ed.organization
    assert org
    assert _eq(org.keyswv(), ["organization_name", "organization_url"])
    assert len(org.organization_name) == 1
    assert org.organization_name[0].text == "Catalogix"
    assert org.organization_url[0].text == "http://www.catalogix.se/"
Ejemplo n.º 12
0
def test_construct_organisation():
    c = make_instance(
        md.Organization, {
            "organization_name":
            ["Example Co.", {
                "text": "Exempel AB",
                "lang": "se"
            }],
            "organization_url":
            "http://www.example.com/"
        })

    assert _eq(c.keyswv(), ["organization_name", "organization_url"])
    assert len(c.organization_name) == 2
    org_names = [on.text for on in c.organization_name]
    assert _eq(org_names, ["Exempel AB", "Example Co."])
    assert len(c.organization_url) == 1
Ejemplo n.º 13
0
def test_construct_AttributeAuthorityDescriptor():
    aad = make_instance(
        md.AttributeAuthorityDescriptor,
        {
            "valid_until": time_util.in_a_while(30),  # 30 days from now
            "id": "aad.example.com",
            "protocol_support_enumeration": SAML2_NAMESPACE,
            "attribute_service": {
                "binding": BINDING_SOAP,
                "location": "http://example.com:6543/saml2/aad",
            },
            "name_id_format": [
                NAMEID_FORMAT_TRANSIENT,
            ],
            "key_descriptor": {
                "use": "signing",
                "key_info": {
                    "key_name": "example.com",
                }
            }
        })

    print aad
    assert _eq(aad.keyswv(), [
        "valid_until", "id", "attribute_service", "name_id_format",
        "key_descriptor", "protocol_support_enumeration"
    ])
    assert time_util.str_to_time(aad.valid_until)
    assert aad.id == "aad.example.com"
    assert aad.protocol_support_enumeration == SAML2_NAMESPACE
    assert len(aad.attribute_service) == 1
    atsr = aad.attribute_service[0]
    assert _eq(atsr.keyswv(), ["binding", "location"])
    assert atsr.binding == BINDING_SOAP
    assert atsr.location == "http://example.com:6543/saml2/aad"
    assert len(aad.name_id_format) == 1
    nif = aad.name_id_format[0]
    assert nif.text.strip() == NAMEID_FORMAT_TRANSIENT
    assert len(aad.key_descriptor) == 1
    kdesc = aad.key_descriptor[0]
    assert kdesc.use == "signing"
    assert kdesc.key_info.key_name[0].text.strip() == "example.com"
Ejemplo n.º 14
0
def test_construct_key_descriptor():
    cert = "".join(_read_lines("test.pem")[1:-1]).strip()
    spec = {
        "use": "signing",
        "key_info": {
            "x509_data": {
                "x509_certificate": cert
            }
        }
    }
    kd = make_instance(md.KeyDescriptor, spec)
    assert _eq(kd.keyswv(), ["use", "key_info"])
    assert kd.use == "signing"
    ki = kd.key_info
    assert _eq(ki.keyswv(), ["x509_data"])
    assert len(ki.x509_data) == 1
    data = ki.x509_data[0]
    assert _eq(data.keyswv(), ["x509_certificate"])
    assert data.x509_certificate
    assert len(data.x509_certificate.text.strip()) == len(cert)