Added a couple of tests
This commit is contained in:
31
tests/test_65_authn_query.py
Normal file
31
tests/test_65_authn_query.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
__author__ = 'rolandh'
|
||||||
|
|
||||||
|
from saml2.samlp import RequestedAuthnContext
|
||||||
|
from saml2.samlp import AuthnQuery
|
||||||
|
from saml2.client import Saml2Client
|
||||||
|
from saml2.saml import AUTHN_PASSWORD
|
||||||
|
from saml2.saml import AuthnContextClassRef
|
||||||
|
from saml2.saml import Subject
|
||||||
|
from saml2.saml import NameID
|
||||||
|
from saml2.saml import NAMEID_FORMAT_TRANSIENT
|
||||||
|
from saml2.server import Server
|
||||||
|
|
||||||
|
def test_basic():
|
||||||
|
sp = Saml2Client(config_file="servera_conf")
|
||||||
|
idp = Server(config_file="idp_all_conf")
|
||||||
|
|
||||||
|
srvs = sp.metadata.authn_query_service(idp.config.entityid)
|
||||||
|
|
||||||
|
destination = srvs[0]["location"]
|
||||||
|
authn_context = [RequestedAuthnContext(
|
||||||
|
authn_context_class_ref=AuthnContextClassRef(
|
||||||
|
text=AUTHN_PASSWORD))]
|
||||||
|
|
||||||
|
subject = Subject(text="abc", name_id=NameID(format=NAMEID_FORMAT_TRANSIENT))
|
||||||
|
|
||||||
|
aq = sp.create_authn_query(subject, destination, authn_context)
|
||||||
|
|
||||||
|
print aq
|
||||||
|
|
||||||
|
assert isinstance(aq, AuthnQuery)
|
71
tests/test_66_name_id_mapping.py
Normal file
71
tests/test_66_name_id_mapping.py
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
__author__ = 'rolandh'
|
||||||
|
|
||||||
|
from saml2.client import Saml2Client
|
||||||
|
from saml2.saml import NameID, NAMEID_FORMAT_PERSISTENT
|
||||||
|
from saml2.saml import NAMEID_FORMAT_TRANSIENT
|
||||||
|
from saml2.server import Server
|
||||||
|
from saml2.samlp import NameIDPolicy
|
||||||
|
from saml2.samlp import NameIDMappingRequest
|
||||||
|
|
||||||
|
def test_base_request():
|
||||||
|
sp = Saml2Client(config_file="servera_conf")
|
||||||
|
idp = Server(config_file="idp_all_conf")
|
||||||
|
|
||||||
|
binding, destination = sp.pick_binding("name_id_mapping_service",
|
||||||
|
entity_id=idp.config.entityid)
|
||||||
|
|
||||||
|
policy = NameIDPolicy(format=NAMEID_FORMAT_TRANSIENT,
|
||||||
|
sp_name_qualifier="urn:mace:swamid:junk",
|
||||||
|
allow_create="true")
|
||||||
|
|
||||||
|
nameid = NameID(format=NAMEID_FORMAT_TRANSIENT, text="foobar")
|
||||||
|
|
||||||
|
nmr = sp.create_name_id_mapping_request(policy, nameid, destination)
|
||||||
|
|
||||||
|
print nmr
|
||||||
|
|
||||||
|
assert isinstance(nmr, NameIDMappingRequest)
|
||||||
|
|
||||||
|
def test_request_response():
|
||||||
|
sp = Saml2Client(config_file="servera_conf")
|
||||||
|
idp = Server(config_file="idp_all_conf")
|
||||||
|
|
||||||
|
binding, destination = sp.pick_binding("name_id_mapping_service",
|
||||||
|
entity_id=idp.config.entityid)
|
||||||
|
|
||||||
|
policy = NameIDPolicy(format=NAMEID_FORMAT_TRANSIENT,
|
||||||
|
sp_name_qualifier="urn:mace:swamid:junk",
|
||||||
|
allow_create="true")
|
||||||
|
|
||||||
|
nameid = NameID(format=NAMEID_FORMAT_TRANSIENT, text="foobar")
|
||||||
|
|
||||||
|
nmr = sp.create_name_id_mapping_request(policy, nameid, destination)
|
||||||
|
|
||||||
|
print nmr
|
||||||
|
|
||||||
|
args = sp.use_soap(nmr, destination)
|
||||||
|
|
||||||
|
# ------- IDP ------------
|
||||||
|
|
||||||
|
req = idp.parse_name_id_mapping_request(args["data"], binding)
|
||||||
|
|
||||||
|
in_response_to = req.message.id
|
||||||
|
name_id = NameID(format=NAMEID_FORMAT_PERSISTENT, text="foobar")
|
||||||
|
|
||||||
|
idp_response = idp.create_name_id_mapping_response(name_id,
|
||||||
|
in_response_to=in_response_to)
|
||||||
|
|
||||||
|
print idp_response
|
||||||
|
|
||||||
|
ht_args = sp.use_soap(idp_response)
|
||||||
|
|
||||||
|
# ------- SP ------------
|
||||||
|
|
||||||
|
_resp = sp.parse_name_id_mapping_request_response(ht_args["data"], binding)
|
||||||
|
|
||||||
|
print _resp.response
|
||||||
|
|
||||||
|
r_name_id = _resp.response.name_id
|
||||||
|
|
||||||
|
assert r_name_id.format == NAMEID_FORMAT_PERSISTENT
|
||||||
|
assert r_name_id.text == "foobar"
|
31
tests/test_67_manage_name_id.py
Normal file
31
tests/test_67_manage_name_id.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
from saml2.samlp import NewID
|
||||||
|
from saml2.saml import NameID, NAMEID_FORMAT_TRANSIENT
|
||||||
|
from saml2.client import Saml2Client
|
||||||
|
from saml2.server import Server
|
||||||
|
|
||||||
|
__author__ = 'rolandh'
|
||||||
|
|
||||||
|
def test_basic():
|
||||||
|
sp = Saml2Client(config_file="servera_conf")
|
||||||
|
idp = Server(config_file="idp_all_conf")
|
||||||
|
|
||||||
|
# -------- @SP ------------
|
||||||
|
binding, destination = sp.pick_binding("manage_name_id_service",
|
||||||
|
entity_id=idp.config.entityid)
|
||||||
|
|
||||||
|
nameid = NameID(format=NAMEID_FORMAT_TRANSIENT, text="foobar")
|
||||||
|
newid = NewID(text="Barfoo")
|
||||||
|
|
||||||
|
mid = sp.create_manage_name_id_request(destination, name_id=nameid,
|
||||||
|
new_id=newid)
|
||||||
|
|
||||||
|
print mid
|
||||||
|
rargs = sp.apply_binding(binding, "%s" % mid, destination, "")
|
||||||
|
|
||||||
|
# --------- @IDP --------------
|
||||||
|
|
||||||
|
_req = idp.parse_manage_name_id_request(rargs["data"], binding)
|
||||||
|
|
||||||
|
print _req.message
|
||||||
|
|
||||||
|
assert mid.id == _req.message.id
|
Reference in New Issue
Block a user