summaryrefslogtreecommitdiff
path: root/tests/test_88_nsprefix.py
blob: 4f652a54f18f1da2b0f724d356f2fe5c08ab8b2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from saml2.saml import NAMEID_FORMAT_TRANSIENT
from saml2.client import Saml2Client
from saml2 import config, BINDING_HTTP_POST
from saml2 import saml
from saml2 import samlp

__author__ = 'roland'


def test_nsprefix():
    status_message = samlp.StatusMessage()
    status_message.text = "OK"

    txt = "%s" % status_message

    assert "ns0:StatusMessage" in txt

    status_message.register_prefix({"saml2": saml.NAMESPACE,
                                    "saml2p": samlp.NAMESPACE})

    txt = "%s" % status_message

    assert "saml2p:StatusMessage" in txt


def test_nsprefix2():
    conf = config.SPConfig()
    conf.load_file("servera_conf")
    client = Saml2Client(conf)

    selected_idp = "urn:mace:example.com:saml:roland:idp"

    destination = client._sso_location(selected_idp, BINDING_HTTP_POST)

    reqid, req = client.create_authn_request(
        destination, nameid_format=NAMEID_FORMAT_TRANSIENT,
        nsprefix={"saml2": saml.NAMESPACE, "saml2p": samlp.NAMESPACE})

    txt = "%s" % req

    assert "saml2p:AuthnRequest" in txt
    assert "saml2:Issuer" in txt

if __name__ == "__main__":
    test_nsprefix2()