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 46 47 48 49
|
from saml2 import BINDING_HTTP_POST
from saml2 import config
from saml2 import saml
from saml2 import samlp
from saml2.client import Saml2Client
from saml2.saml import NAMEID_FORMAT_TRANSIENT
__author__ = "roland"
def test_nsprefix():
status_message = samlp.StatusMessage()
status_message.text = "OK"
txt = f"{status_message}"
assert "ns0:StatusMessage" in txt
status_message.register_prefix({"saml2": saml.NAMESPACE, "saml2p": samlp.NAMESPACE})
txt = f"{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 = f"{req}"
assert "saml2p:AuthnRequest" in txt
assert "saml2:Issuer" in txt
if __name__ == "__main__":
test_nsprefix2()
|