Fixed tests, supposted to be run from the tests directory
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<?xml version='1.0' encoding='UTF-8'?>
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
<ns0:EntitiesDescriptor name="urn:mace:example.com:saml:test" validUntil="2009-12-04T17:31:07Z" xmlns:ns0="urn:oasis:names:tc:SAML:2.0:metadata"><ns0:EntityDescriptor entityID="urn:mace:example.com:saml:roland:sp"><ns0:SPSSODescriptor AuthnRequestsSigned="False" WantAssertionsSigned="True" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol"><ns0:KeyDescriptor><ns1:KeyInfo xmlns:ns1="http://www.w3.org/2000/09/xmldsig#"><ns1:X509Data><ns1:X509Certificate>MIIC8jCCAlugAwIBAgIJAJHg2V5J31I8MA0GCSqGSIb3DQEBBQUAMFoxCzAJBgNV
|
<ns0:EntitiesDescriptor name="urn:mace:example.com:saml:test" validUntil="2010-12-04T17:31:07Z" xmlns:ns0="urn:oasis:names:tc:SAML:2.0:metadata"><ns0:EntityDescriptor entityID="urn:mace:example.com:saml:roland:sp"><ns0:SPSSODescriptor AuthnRequestsSigned="False" WantAssertionsSigned="True" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol"><ns0:KeyDescriptor><ns1:KeyInfo xmlns:ns1="http://www.w3.org/2000/09/xmldsig#"><ns1:X509Data><ns1:X509Certificate>MIIC8jCCAlugAwIBAgIJAJHg2V5J31I8MA0GCSqGSIb3DQEBBQUAMFoxCzAJBgNV
|
||||||
BAYTAlNFMQ0wCwYDVQQHEwRVbWVhMRgwFgYDVQQKEw9VbWVhIFVuaXZlcnNpdHkx
|
BAYTAlNFMQ0wCwYDVQQHEwRVbWVhMRgwFgYDVQQKEw9VbWVhIFVuaXZlcnNpdHkx
|
||||||
EDAOBgNVBAsTB0lUIFVuaXQxEDAOBgNVBAMTB1Rlc3QgU1AwHhcNMDkxMDI2MTMz
|
EDAOBgNVBAsTB0lUIFVuaXQxEDAOBgNVBAMTB1Rlc3QgU1AwHhcNMDkxMDI2MTMz
|
||||||
MTE1WhcNMTAxMDI2MTMzMTE1WjBaMQswCQYDVQQGEwJTRTENMAsGA1UEBxMEVW1l
|
MTE1WhcNMTAxMDI2MTMzMTE1WjBaMQswCQYDVQQGEwJTRTENMAsGA1UEBxMEVW1l
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version='1.0' encoding='UTF-8'?>
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
<ns0:EntitiesDescriptor name="urn:mace:umu.se:saml:test" validUntil="2009-12-01T09:22:16Z" xmlns:ns0="urn:oasis:names:tc:SAML:2.0:metadata"><ns0:EntityDescriptor entityID="urn:mace:umu.se:saml:roland:sp" validUntil="2009-12-01T09:22:16Z"><ns0:SPSSODescriptor AuthnRequestsSigned="False" WantAssertionsSigned="True" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol"><ns0:KeyDescriptor><ns1:KeyInfo xmlns:ns1="http://www.w3.org/2000/09/xmldsig#"><ns1:X509Data><ns1:X509Certificate>MIIC8jCCAlugAwIBAgIJAJHg2V5J31I8MA0GCSqGSIb3DQEBBQUAMFoxCzAJBgNV
|
<ns0:EntitiesDescriptor name="urn:mace:umu.se:saml:test" validUntil="2010-12-01T09:22:16Z" xmlns:ns0="urn:oasis:names:tc:SAML:2.0:metadata"><ns0:EntityDescriptor entityID="urn:mace:umu.se:saml:roland:sp" validUntil="2010-12-01T09:22:16Z"><ns0:SPSSODescriptor AuthnRequestsSigned="False" WantAssertionsSigned="True" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol"><ns0:KeyDescriptor><ns1:KeyInfo xmlns:ns1="http://www.w3.org/2000/09/xmldsig#"><ns1:X509Data><ns1:X509Certificate>MIIC8jCCAlugAwIBAgIJAJHg2V5J31I8MA0GCSqGSIb3DQEBBQUAMFoxCzAJBgNV
|
||||||
BAYTAlNFMQ0wCwYDVQQHEwRVbWVhMRgwFgYDVQQKEw9VbWVhIFVuaXZlcnNpdHkx
|
BAYTAlNFMQ0wCwYDVQQHEwRVbWVhMRgwFgYDVQQKEw9VbWVhIFVuaXZlcnNpdHkx
|
||||||
EDAOBgNVBAsTB0lUIFVuaXQxEDAOBgNVBAMTB1Rlc3QgU1AwHhcNMDkxMDI2MTMz
|
EDAOBgNVBAsTB0lUIFVuaXQxEDAOBgNVBAMTB1Rlc3QgU1AwHhcNMDkxMDI2MTMz
|
||||||
MTE1WhcNMTAxMDI2MTMzMTE1WjBaMQswCQYDVQQGEwJTRTENMAsGA1UEBxMEVW1l
|
MTE1WhcNMTAxMDI2MTMzMTE1WjBaMQswCQYDVQQGEwJTRTENMAsGA1UEBxMEVW1l
|
||||||
|
|||||||
@@ -1,77 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
from saml2.cache import Cache
|
|
||||||
from saml2.time_util import in_a_while, str_to_time
|
|
||||||
from saml2.client import SESSION_INFO
|
|
||||||
|
|
||||||
def _eq(l1,l2):
|
|
||||||
return set(l1) == set(l2)
|
|
||||||
|
|
||||||
|
|
||||||
class TestClass:
|
|
||||||
def setup_class(self):
|
|
||||||
self.cache = Cache()
|
|
||||||
|
|
||||||
|
|
||||||
def test_0(self):
|
|
||||||
not_on_or_after = str_to_time(in_a_while(days=1))
|
|
||||||
session_info = SESSION_INFO.copy()
|
|
||||||
session_info["ava"] = {"givenName":["Derek"]}
|
|
||||||
self.cache.set("1234", "abcd", session_info,
|
|
||||||
not_on_or_after)
|
|
||||||
|
|
||||||
(ava, inactive) = self.cache.get_identity("1234")
|
|
||||||
assert inactive == []
|
|
||||||
assert ava.keys() == ["givenName"]
|
|
||||||
assert ava["givenName"] == ["Derek"]
|
|
||||||
|
|
||||||
def test_1(self):
|
|
||||||
not_on_or_after = str_to_time(in_a_while(days=1))
|
|
||||||
session_info = SESSION_INFO.copy()
|
|
||||||
session_info["ava"] = {"surName":["Jeter"]}
|
|
||||||
self.cache.set("1234", "bcde", session_info,
|
|
||||||
not_on_or_after)
|
|
||||||
|
|
||||||
(ava, inactive) = self.cache.get_identity("1234")
|
|
||||||
assert inactive == []
|
|
||||||
assert _eq(ava.keys(), ["givenName","surName"])
|
|
||||||
assert ava["givenName"] == ["Derek"]
|
|
||||||
assert ava["surName"] == ["Jeter"]
|
|
||||||
|
|
||||||
def test_2(self):
|
|
||||||
session_info = self.cache.get("1234","bcde")
|
|
||||||
ava = session_info["ava"]
|
|
||||||
assert _eq(ava.keys(), ["surName"])
|
|
||||||
assert ava["surName"] == ["Jeter"]
|
|
||||||
|
|
||||||
def test_entities(self):
|
|
||||||
assert _eq(self.cache.entities("1234"), ["abcd", "bcde"])
|
|
||||||
|
|
||||||
def test_4(self):
|
|
||||||
self.cache.reset("1234", "bcde")
|
|
||||||
assert self.cache.active("1234","bcde") == False
|
|
||||||
assert self.cache.active("1234","abcd")
|
|
||||||
|
|
||||||
(ava, inactive) = self.cache.get_identity("1234")
|
|
||||||
assert inactive == ['bcde']
|
|
||||||
assert _eq(ava.keys(), ["givenName"])
|
|
||||||
assert ava["givenName"] == ["Derek"]
|
|
||||||
|
|
||||||
def test_subjects(self):
|
|
||||||
assert self.cache.subjects() == ["1234"]
|
|
||||||
|
|
||||||
def test_second_subject(self):
|
|
||||||
not_on_or_after = str_to_time(in_a_while(days=1))
|
|
||||||
session_info = SESSION_INFO.copy()
|
|
||||||
session_info["ava"] = {"givenName":["Ichiro"],
|
|
||||||
"surName":["Suzuki"]}
|
|
||||||
self.cache.set("9876", "abcd", session_info,
|
|
||||||
not_on_or_after)
|
|
||||||
|
|
||||||
(ava, inactive) = self.cache.get_identity("9876")
|
|
||||||
assert inactive == []
|
|
||||||
assert _eq(ava.keys(), ["givenName","surName"])
|
|
||||||
assert ava["givenName"] == ["Ichiro"]
|
|
||||||
assert ava["surName"] == ["Suzuki"]
|
|
||||||
assert _eq(self.cache.subjects(), ["1234","9876"])
|
|
||||||
|
|
||||||
@@ -5,10 +5,11 @@ from saml2.client import Saml2Client
|
|||||||
from saml2 import samlp, client, BINDING_HTTP_POST
|
from saml2 import samlp, client, BINDING_HTTP_POST
|
||||||
from saml2 import saml, utils, config, class_name
|
from saml2 import saml, utils, config, class_name
|
||||||
from saml2.sigver import correctly_signed_authn_request, verify_signature
|
from saml2.sigver import correctly_signed_authn_request, verify_signature
|
||||||
|
from saml2.sigver import correctly_signed_response
|
||||||
from saml2.server import Server
|
from saml2.server import Server
|
||||||
|
|
||||||
XML_RESPONSE_FILE = "tests/saml_signed.xml"
|
XML_RESPONSE_FILE = "saml_signed.xml"
|
||||||
XML_RESPONSE_FILE2 = "tests/saml2_response.xml"
|
XML_RESPONSE_FILE2 = "saml2_response.xml"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@@ -92,8 +93,8 @@ class TestClient:
|
|||||||
|
|
||||||
def test_parse_1(self):
|
def test_parse_1(self):
|
||||||
xml_response = ("%s" % (self._resp_,)).split("\n")[1]
|
xml_response = ("%s" % (self._resp_,)).split("\n")[1]
|
||||||
response = correctly_signed_response(decoded_xml,
|
response = correctly_signed_response(xml_response,
|
||||||
self.config["xmlsec_binary"], log=log)
|
self.client.config["xmlsec_binary"])
|
||||||
outstanding = {"12": "http://localhost:8088/sso"}
|
outstanding = {"12": "http://localhost:8088/sso"}
|
||||||
session_info = self.client.do_response(response,
|
session_info = self.client.do_response(response,
|
||||||
"urn:mace:example.com:saml:roland:sp",
|
"urn:mace:example.com:saml:roland:sp",
|
||||||
@@ -103,7 +104,12 @@ class TestClient:
|
|||||||
def test_parse_2(self):
|
def test_parse_2(self):
|
||||||
xml_response = open(XML_RESPONSE_FILE2).read()
|
xml_response = open(XML_RESPONSE_FILE2).read()
|
||||||
response = samlp.response_from_string(xml_response)
|
response = samlp.response_from_string(xml_response)
|
||||||
session_info = self.client.do_response(response, "xenosmilus.umdc.umu.se")
|
outstanding = {"_ae0216740b5baa4b13c79ffdb2baa82572788fd9a3":
|
||||||
|
"http://localhost:8088/sso"}
|
||||||
|
session_info = self.client.do_response(response,
|
||||||
|
"xenosmilus.umdc.umu.se",
|
||||||
|
outstanding=outstanding,
|
||||||
|
lax=True)
|
||||||
|
|
||||||
assert session_info["ava"] == {'uid': ['andreas'],
|
assert session_info["ava"] == {'uid': ['andreas'],
|
||||||
'mobile': ['+4741107700'],
|
'mobile': ['+4741107700'],
|
||||||
|
|||||||
@@ -15,12 +15,12 @@ sp1 = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"key_file" : "tests/mykey.pem",
|
"key_file" : "mykey.pem",
|
||||||
"cert_file" : "tests/mycert.pem",
|
"cert_file" : "mycert.pem",
|
||||||
"xmlsec_binary" : "/opt/local/bin/xmlsec1",
|
"xmlsec_binary" : "/opt/local/bin/xmlsec1",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"local": ["tests/metadata.xml",
|
"local": ["metadata.xml",
|
||||||
"tests/urn-mace-swami.se-swamid-test-1.0-metadata.xml"],
|
"urn-mace-swami.se-swamid-test-1.0-metadata.xml"],
|
||||||
},
|
},
|
||||||
"virtual_organization" : {
|
"virtual_organization" : {
|
||||||
"http://vo.example.org/biomed":{
|
"http://vo.example.org/biomed":{
|
||||||
|
|||||||
1157
tests/test_md.py
1157
tests/test_md.py
File diff suppressed because it is too large
Load Diff
@@ -1,344 +0,0 @@
|
|||||||
|
|
||||||
from saml2 import metadata, utils
|
|
||||||
from saml2 import NAMESPACE as SAML2_NAMESPACE
|
|
||||||
from saml2 import BINDING_SOAP
|
|
||||||
from saml2 import md, saml, samlp
|
|
||||||
from saml2 import time_util
|
|
||||||
from saml2.saml import NAMEID_FORMAT_TRANSIENT
|
|
||||||
|
|
||||||
SWAMI_METADATA = "tests/urn-mace-swami.se-swamid-test-1.0-metadata.xml"
|
|
||||||
INCOMMON_METADATA = "tests/InCommon-metadata.xml"
|
|
||||||
EXAMPLE_METADATA = "tests/metadata_example.xml"
|
|
||||||
SWITCH_METADATA = "tests/metadata.aaitest.xml"
|
|
||||||
SP_METADATA = "tests/metasp.xml"
|
|
||||||
|
|
||||||
def _eq(l1,l2):
|
|
||||||
return set(l1) == set(l2)
|
|
||||||
|
|
||||||
def test_swami_1():
|
|
||||||
md = metadata.MetaData()
|
|
||||||
md.import_metadata(open(SWAMI_METADATA).read())
|
|
||||||
print len(md.entity)
|
|
||||||
assert len(md.entity) == 58
|
|
||||||
idps = dict([(id,ent["idp_sso"]) for id,ent in md.entity.items() \
|
|
||||||
if "idp_sso" in ent])
|
|
||||||
print idps
|
|
||||||
assert idps.keys() == ['https://idp.umu.se/saml2/idp/metadata.php']
|
|
||||||
idp_sso = md.single_sign_on_services(
|
|
||||||
'https://idp.umu.se/saml2/idp/metadata.php')
|
|
||||||
assert md.name('https://idp.umu.se/saml2/idp/metadata.php') == (
|
|
||||||
u'Ume\xe5 university (New SAML2)')
|
|
||||||
assert len(idp_sso) == 1
|
|
||||||
assert idp_sso == ['https://idp.umu.se/saml2/idp/SSOService.php']
|
|
||||||
ssocerts = md.certs('https://idp.umu.se/saml2/idp/SSOService.php')
|
|
||||||
print ssocerts
|
|
||||||
assert len(ssocerts) == 1
|
|
||||||
|
|
||||||
def test_incommon_1():
|
|
||||||
md = metadata.MetaData()
|
|
||||||
md.import_metadata(open(INCOMMON_METADATA).read())
|
|
||||||
print len(md.entity)
|
|
||||||
assert len(md.entity) == 366
|
|
||||||
idps = dict([
|
|
||||||
(id,ent["idp_sso"]) for id,ent in md.entity.items() if "idp_sso" in ent])
|
|
||||||
print idps.keys()
|
|
||||||
assert len(idps) == 35 # !!!!???? < 10%
|
|
||||||
idp_sso = md.single_sign_on_services('urn:mace:incommon:uiuc.edu')
|
|
||||||
assert idp_sso == []
|
|
||||||
idp_sso = md.single_sign_on_services('urn:mace:incommon:alaska.edu')
|
|
||||||
assert len(idp_sso) == 1
|
|
||||||
print idp_sso
|
|
||||||
assert idp_sso == ['https://idp.alaska.edu/idp/profile/SAML2/Redirect/SSO']
|
|
||||||
|
|
||||||
def test_example():
|
|
||||||
md = metadata.MetaData()
|
|
||||||
md.import_metadata(open(EXAMPLE_METADATA).read())
|
|
||||||
print len(md.entity)
|
|
||||||
assert len(md.entity) == 1
|
|
||||||
idps = dict([(id,ent["idp_sso"]) for id,ent in md.entity.items() \
|
|
||||||
if "idp_sso" in ent])
|
|
||||||
assert idps.keys() == [
|
|
||||||
'http://xenosmilus.umdc.umu.se/simplesaml/saml2/idp/metadata.php']
|
|
||||||
certs = md.certs(
|
|
||||||
'http://xenosmilus.umdc.umu.se/simplesaml/saml2/idp/metadata.php')
|
|
||||||
assert len(certs) == 1
|
|
||||||
assert isinstance(certs[0], tuple)
|
|
||||||
assert len(certs[0]) == 2
|
|
||||||
|
|
||||||
def test_switch_1():
|
|
||||||
md = metadata.MetaData()
|
|
||||||
md.import_metadata(open(SWITCH_METADATA).read())
|
|
||||||
print len(md.entity)
|
|
||||||
assert len(md.entity) == 90
|
|
||||||
idps = dict([(id,ent["idp_sso"]) for id,ent in md.entity.items() \
|
|
||||||
if "idp_sso" in ent])
|
|
||||||
print idps.keys()
|
|
||||||
idp_sso = md.single_sign_on_services(
|
|
||||||
'https://aai-demo-idp.switch.ch/idp/shibboleth')
|
|
||||||
assert len(idp_sso) == 1
|
|
||||||
print idp_sso
|
|
||||||
assert idp_sso == [
|
|
||||||
'https://aai-demo-idp.switch.ch/idp/profile/SAML2/Redirect/SSO']
|
|
||||||
assert len(idps) == 16
|
|
||||||
aas = dict([(id,ent["attribute_authority"]) for id,ent in md.entity.items() \
|
|
||||||
if "attribute_authority" in ent])
|
|
||||||
print aas.keys()
|
|
||||||
aads = aas['https://aai-demo-idp.switch.ch/idp/shibboleth']
|
|
||||||
assert len(aads) == 1
|
|
||||||
aad = aads[0]
|
|
||||||
assert len(aad.attribute_service) == 1
|
|
||||||
assert len(aad.name_id_format) == 2
|
|
||||||
dual = dict([(id,ent) for id,ent in md.entity.items() \
|
|
||||||
if "idp_sso" in ent and "sp_sso" in ent])
|
|
||||||
print len(dual)
|
|
||||||
assert len(dual) == 0
|
|
||||||
|
|
||||||
def test_sp_metadata():
|
|
||||||
md = metadata.MetaData()
|
|
||||||
md.import_metadata(open(SP_METADATA).read())
|
|
||||||
|
|
||||||
print md.entity
|
|
||||||
assert len(md.entity) == 1
|
|
||||||
assert md.entity.keys() == ['urn:mace:umu.se:saml:roland:sp']
|
|
||||||
assert md.entity['urn:mace:umu.se:saml:roland:sp'].keys() == [
|
|
||||||
"organization","sp_sso"]
|
|
||||||
print md.entity['urn:mace:umu.se:saml:roland:sp']["sp_sso"][0].keyswv()
|
|
||||||
(req,opt) = md.attribute_consumer('urn:mace:umu.se:saml:roland:sp')
|
|
||||||
print req
|
|
||||||
assert len(req) == 3
|
|
||||||
assert len(opt) == 1
|
|
||||||
assert opt[0].name == 'urn:oid:2.5.4.12'
|
|
||||||
assert opt[0].friendly_name == 'title'
|
|
||||||
assert _eq([n.name for n in req],['urn:oid:2.5.4.4', 'urn:oid:2.5.4.42',
|
|
||||||
'urn:oid:0.9.2342.19200300.100.1.3'])
|
|
||||||
assert _eq([n.friendly_name for n in req],['surName', 'givenName', 'mail'])
|
|
||||||
|
|
||||||
# ------------ Constructing metaval ----------------------------------------
|
|
||||||
|
|
||||||
def test_construct_organisation_name():
|
|
||||||
o = md.Organization()
|
|
||||||
utils.make_vals({"text":"Exempel AB", "lang":"se"},
|
|
||||||
md.OrganizationName, o, "organization_name")
|
|
||||||
print o
|
|
||||||
assert str(o) == """<?xml version='1.0' encoding='UTF-8'?>
|
|
||||||
<ns0:Organization xmlns:ns0="urn:oasis:names:tc:SAML:2.0:metadata"><ns0:OrganizationName ns1:lang="se" xmlns:ns1="http:#www.w3.org/XML/1998/namespace">Exempel AB</ns0:OrganizationName></ns0:Organization>"""
|
|
||||||
|
|
||||||
def test_make_int_value():
|
|
||||||
val = utils.make_vals( 1, saml.AttributeValue, part=True)
|
|
||||||
assert isinstance(val, saml.AttributeValue)
|
|
||||||
assert val.text == "1"
|
|
||||||
|
|
||||||
def test_make_true_value():
|
|
||||||
val = utils.make_vals( True, saml.AttributeValue, part=True )
|
|
||||||
assert isinstance(val, saml.AttributeValue)
|
|
||||||
assert val.text == "True"
|
|
||||||
|
|
||||||
def test_make_false_value():
|
|
||||||
val = utils.make_vals( False, saml.AttributeValue, part=True )
|
|
||||||
assert isinstance(val, saml.AttributeValue)
|
|
||||||
assert val.text == "False"
|
|
||||||
|
|
||||||
NO_VALUE = """<?xml version='1.0' encoding='UTF-8'?>
|
|
||||||
<ns0:AttributeValue xmlns:ns0="urn:oasis:names:tc:SAML:2.0:assertion" />"""
|
|
||||||
|
|
||||||
def test_make_no_value():
|
|
||||||
val = utils.make_vals( None, saml.AttributeValue, part=True )
|
|
||||||
assert isinstance(val, saml.AttributeValue)
|
|
||||||
assert val.text == None
|
|
||||||
print val
|
|
||||||
assert "%s" % val == NO_VALUE
|
|
||||||
|
|
||||||
def test_make_string():
|
|
||||||
val = utils.make_vals( "example", saml.AttributeValue, part=True )
|
|
||||||
assert isinstance(val, saml.AttributeValue)
|
|
||||||
assert val.text == "example"
|
|
||||||
|
|
||||||
def test_make_list_of_strings():
|
|
||||||
attr = saml.Attribute()
|
|
||||||
vals = ["foo", "bar"]
|
|
||||||
val = utils.make_vals(vals, saml.AttributeValue, attr,
|
|
||||||
"attribute_value")
|
|
||||||
assert attr.keyswv() == ["attribute_value"]
|
|
||||||
print attr.attribute_value
|
|
||||||
assert _eq([val.text for val in attr.attribute_value], vals)
|
|
||||||
|
|
||||||
def test_make_dict():
|
|
||||||
vals = ["foo", "bar"]
|
|
||||||
attrval = { "attribute_value": vals}
|
|
||||||
attr = utils.make_vals(attrval, saml.Attribute, part=True)
|
|
||||||
assert attr.keyswv() == ["attribute_value"]
|
|
||||||
assert _eq([val.text for val in attr.attribute_value], vals)
|
|
||||||
|
|
||||||
# ------------ Constructing metadata ----------------------------------------
|
|
||||||
|
|
||||||
def test_construct_contact():
|
|
||||||
c = utils.make_instance(md.ContactPerson, {
|
|
||||||
"given_name":"Roland",
|
|
||||||
"sur_name": "Hedberg",
|
|
||||||
"email_address": "roland@catalogix.se",
|
|
||||||
})
|
|
||||||
print c
|
|
||||||
assert c.given_name.text == "Roland"
|
|
||||||
assert c.sur_name.text == "Hedberg"
|
|
||||||
assert c.email_address[0].text == "roland@catalogix.se"
|
|
||||||
assert _eq(c.keyswv(), ["given_name","sur_name","email_address"])
|
|
||||||
|
|
||||||
|
|
||||||
def test_construct_organisation():
|
|
||||||
c = utils.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
|
|
||||||
|
|
||||||
def test_construct_entity_descr_1():
|
|
||||||
ed = utils.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 _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/"
|
|
||||||
|
|
||||||
def test_construct_entity_descr_2():
|
|
||||||
ed = utils.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": "roland@catalogix.se",
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
assert _eq(ed.keyswv(), ["entity_id", "contact_person", "organization"])
|
|
||||||
assert ed.entity_id == "urn:mace:catalogix.se:sp1"
|
|
||||||
org = ed.organization
|
|
||||||
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 == "roland@catalogix.se"
|
|
||||||
assert _eq(c.keyswv(), ["given_name","sur_name","email_address"])
|
|
||||||
|
|
||||||
def test_construct_key_descriptor():
|
|
||||||
cert = "".join(open("tests/test.pem").readlines()[1:-1]).strip()
|
|
||||||
spec = {
|
|
||||||
"use": "signing",
|
|
||||||
"key_info" : {
|
|
||||||
"x509_data": {
|
|
||||||
"x509_certificate": cert
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
kd = utils.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 len(data.x509_certificate) == 1
|
|
||||||
assert len(data.x509_certificate[0].text.strip()) == len(cert)
|
|
||||||
|
|
||||||
def test_construct_key_descriptor_with_key_name():
|
|
||||||
cert = "".join(open("tests/test.pem").readlines()[1:-1]).strip()
|
|
||||||
spec = {
|
|
||||||
"use": "signing",
|
|
||||||
"key_info" : {
|
|
||||||
"key_name": "example.com",
|
|
||||||
"x509_data": {
|
|
||||||
"x509_certificate": cert
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
kd = utils.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", "key_name"])
|
|
||||||
assert len(ki.key_name) == 1
|
|
||||||
assert ki.key_name[0].text.strip() == "example.com"
|
|
||||||
assert len(ki.x509_data) == 1
|
|
||||||
data = ki.x509_data[0]
|
|
||||||
assert _eq(data.keyswv(), ["x509_certificate"])
|
|
||||||
assert len(data.x509_certificate) == 1
|
|
||||||
assert len(data.x509_certificate[0].text.strip()) == len(cert)
|
|
||||||
|
|
||||||
def test_construct_AttributeAuthorityDescriptor():
|
|
||||||
aad = utils.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"
|
|
||||||
|
|
||||||
STATUS_RESULT = """<?xml version='1.0' encoding='UTF-8'?>
|
|
||||||
<ns0:Status xmlns:ns0="urn:oasis:names:tc:SAML:2.0:protocol"><ns0:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Responder"><ns0:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:UnknownPrincipal" /></ns0:StatusCode><ns0:StatusMessage>Error resolving principal</ns0:StatusMessage></ns0:Status>"""
|
|
||||||
|
|
||||||
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" % utils.make_instance( samlp.Status, input)
|
|
||||||
assert status_text == STATUS_RESULT
|
|
||||||
|
|
||||||
@@ -1,893 +0,0 @@
|
|||||||
#!/usr/bin/python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
#
|
|
||||||
# Copyright (C) 2009 Umeå University.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
"""Tests for saml2.saml"""
|
|
||||||
|
|
||||||
__author__ = 'roland.hedberg@adm.umu.se (Roland Hedberg)'
|
|
||||||
|
|
||||||
try:
|
|
||||||
from xml.etree import ElementTree
|
|
||||||
except ImportError:
|
|
||||||
from elementtree import ElementTree
|
|
||||||
import saml2
|
|
||||||
from saml2 import saml
|
|
||||||
import saml2_data, ds_data
|
|
||||||
import xmldsig as ds
|
|
||||||
|
|
||||||
class TestNameID:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.name_id = saml.NameID()
|
|
||||||
|
|
||||||
def testEmptyExtensionsList(self):
|
|
||||||
"""Test if NameID has empty extensions list"""
|
|
||||||
assert isinstance(self.name_id.extension_elements, list)
|
|
||||||
assert len(self.name_id.extension_elements) == 0
|
|
||||||
|
|
||||||
def testFormatAttribute(self):
|
|
||||||
"""Test for Format attribute accessors"""
|
|
||||||
self.name_id.format = saml.NAMEID_FORMAT_EMAILADDRESS
|
|
||||||
assert self.name_id.format == saml.NAMEID_FORMAT_EMAILADDRESS
|
|
||||||
assert len(self.name_id.extension_elements) == 0
|
|
||||||
new_name_id = saml.name_id_from_string(self.name_id.to_string())
|
|
||||||
assert len(new_name_id.extension_elements) == 0
|
|
||||||
|
|
||||||
self.name_id.extension_elements.append(saml2.ExtensionElement(
|
|
||||||
'foo', text='bar'))
|
|
||||||
assert len(self.name_id.extension_elements) == 1
|
|
||||||
assert self.name_id.format == saml.NAMEID_FORMAT_EMAILADDRESS
|
|
||||||
|
|
||||||
def testNameIDText(self):
|
|
||||||
"""Test text value of NameID element"""
|
|
||||||
self.name_id.text = "tmatsuo@example.com"
|
|
||||||
assert self.name_id.text == "tmatsuo@example.com"
|
|
||||||
|
|
||||||
def testSPProvidedID(self):
|
|
||||||
"""Test for SPProvidedID attribute accessors"""
|
|
||||||
self.name_id.sp_provided_id = "provided id"
|
|
||||||
assert self.name_id.sp_provided_id == "provided id"
|
|
||||||
|
|
||||||
def testEmptyNameIDToAndFromStringMatch(self):
|
|
||||||
"""Test name_id_from_string() with empty NameID"""
|
|
||||||
string_from_name_id = self.name_id.to_string()
|
|
||||||
new_name_id = saml.name_id_from_string(string_from_name_id)
|
|
||||||
string_from_new_name_id = new_name_id.to_string()
|
|
||||||
assert string_from_name_id == string_from_new_name_id
|
|
||||||
|
|
||||||
def testNameIDToAndFromStringMatch(self):
|
|
||||||
"""Test name_id_from_string() with data"""
|
|
||||||
self.name_id.format = saml.NAMEID_FORMAT_EMAILADDRESS
|
|
||||||
self.name_id.text = "tmatsuo@example.com"
|
|
||||||
self.name_id.name_qualifier = "name_qualifier"
|
|
||||||
self.name_id.sp_name_qualifier = "sp_name_qualifier"
|
|
||||||
string_from_name_id = self.name_id.to_string()
|
|
||||||
new_name_id = saml.name_id_from_string(string_from_name_id)
|
|
||||||
assert new_name_id.name_qualifier == "name_qualifier"
|
|
||||||
assert new_name_id.sp_name_qualifier == "sp_name_qualifier"
|
|
||||||
string_from_new_name_id = new_name_id.to_string()
|
|
||||||
assert string_from_name_id == string_from_new_name_id
|
|
||||||
|
|
||||||
def testExtensionAttributes(self):
|
|
||||||
"""Test extension attributes"""
|
|
||||||
self.name_id.extension_attributes['hoge'] = 'fuga'
|
|
||||||
self.name_id.extension_attributes['moge'] = 'muga'
|
|
||||||
assert self.name_id.extension_attributes['hoge'] == 'fuga'
|
|
||||||
assert self.name_id.extension_attributes['moge'] == 'muga'
|
|
||||||
new_name_id = saml.name_id_from_string(self.name_id.to_string())
|
|
||||||
assert new_name_id.extension_attributes['hoge'] == 'fuga'
|
|
||||||
assert new_name_id.extension_attributes['moge'] == 'muga'
|
|
||||||
|
|
||||||
def testname_id_from_string(self):
|
|
||||||
"""Test name_id_from_string() using test data"""
|
|
||||||
name_id = saml.name_id_from_string(saml2_data.TEST_NAME_ID)
|
|
||||||
assert name_id.format == saml.NAMEID_FORMAT_EMAILADDRESS
|
|
||||||
assert name_id.text.strip() == "tmatsuo@example.com"
|
|
||||||
assert name_id.sp_provided_id == "sp provided id"
|
|
||||||
|
|
||||||
|
|
||||||
class TestIssuer:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.issuer = saml.Issuer()
|
|
||||||
|
|
||||||
def testIssuerToAndFromString(self):
|
|
||||||
"""Test issuer_from_string()"""
|
|
||||||
self.issuer.text = "http://www.example.com/test"
|
|
||||||
self.issuer.name_qualifier = "name_qualifier"
|
|
||||||
self.issuer.sp_name_qualifier = "sp_name_qualifier"
|
|
||||||
new_issuer = saml.issuer_from_string(self.issuer.to_string())
|
|
||||||
assert self.issuer.text == new_issuer.text
|
|
||||||
assert self.issuer.name_qualifier == new_issuer.name_qualifier
|
|
||||||
assert self.issuer.sp_name_qualifier == new_issuer.sp_name_qualifier
|
|
||||||
assert self.issuer.extension_elements == new_issuer.extension_elements
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test issuer_from_string() using test data"""
|
|
||||||
issuer = saml.issuer_from_string(saml2_data.TEST_ISSUER)
|
|
||||||
assert issuer.text.strip() == "http://www.example.com/test"
|
|
||||||
new_issuer = saml.issuer_from_string(issuer.to_string())
|
|
||||||
assert issuer.text == new_issuer.text
|
|
||||||
assert issuer.extension_elements == new_issuer.extension_elements
|
|
||||||
|
|
||||||
|
|
||||||
class TestSubjectLocality:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.subject_locality = saml.SubjectLocality()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for SubjectLocality accessors"""
|
|
||||||
self.subject_locality.address = "127.0.0.1"
|
|
||||||
self.subject_locality.dns_name = "localhost"
|
|
||||||
assert self.subject_locality.address == "127.0.0.1"
|
|
||||||
assert self.subject_locality.dns_name == "localhost"
|
|
||||||
new_subject_locality = saml.subject_locality_from_string(
|
|
||||||
self.subject_locality.to_string())
|
|
||||||
assert new_subject_locality.address == "127.0.0.1"
|
|
||||||
assert new_subject_locality.dns_name == "localhost"
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test SubjectLocalityFromString() using test data"""
|
|
||||||
|
|
||||||
subject_locality = saml.subject_locality_from_string(
|
|
||||||
saml2_data.TEST_SUBJECT_LOCALITY)
|
|
||||||
assert subject_locality.address == "127.0.0.1"
|
|
||||||
assert subject_locality.dns_name == "localhost"
|
|
||||||
|
|
||||||
new_subject_locality = saml.subject_locality_from_string(
|
|
||||||
subject_locality.to_string())
|
|
||||||
assert new_subject_locality.address == "127.0.0.1"
|
|
||||||
assert new_subject_locality.dns_name == "localhost"
|
|
||||||
assert subject_locality.to_string() == new_subject_locality.to_string()
|
|
||||||
|
|
||||||
|
|
||||||
class TestAuthnContextClassRef:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.authn_context_class_ref = saml.AuthnContextClassRef()
|
|
||||||
self.text = "http://www.example.com/authnContextClassRef"
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for AuthnContextClassRef accessors"""
|
|
||||||
self.authn_context_class_ref.text = self.text
|
|
||||||
assert self.authn_context_class_ref.text == self.text
|
|
||||||
new_authn_context_class_ref = saml.authn_context_class_ref_from_string(
|
|
||||||
self.authn_context_class_ref.to_string())
|
|
||||||
assert new_authn_context_class_ref.text == self.text
|
|
||||||
assert self.authn_context_class_ref.to_string() == \
|
|
||||||
new_authn_context_class_ref.to_string()
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test authn_context_class_ref_from_string() using test data"""
|
|
||||||
authn_context_class_ref = saml.authn_context_class_ref_from_string(
|
|
||||||
saml2_data.TEST_AUTHN_CONTEXT_CLASS_REF)
|
|
||||||
assert authn_context_class_ref.text.strip() == self.text
|
|
||||||
|
|
||||||
|
|
||||||
class TestAuthnContextDeclRef:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.authn_context_decl_ref = saml.AuthnContextDeclRef()
|
|
||||||
self.ref = "http://www.example.com/authnContextDeclRef"
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for AuthnContextDeclRef accessors"""
|
|
||||||
self.authn_context_decl_ref.text = self.ref
|
|
||||||
assert self.authn_context_decl_ref.text == self.ref
|
|
||||||
new_authn_context_decl_ref = saml.authn_context_decl_ref_from_string(
|
|
||||||
self.authn_context_decl_ref.to_string())
|
|
||||||
assert new_authn_context_decl_ref.text == self.ref
|
|
||||||
assert self.authn_context_decl_ref.to_string() == \
|
|
||||||
new_authn_context_decl_ref.to_string()
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test authn_context_decl_ref_from_string() using test data"""
|
|
||||||
authn_context_decl_ref = saml.authn_context_decl_ref_from_string(
|
|
||||||
saml2_data.TEST_AUTHN_CONTEXT_DECL_REF)
|
|
||||||
assert authn_context_decl_ref.text.strip() == self.ref
|
|
||||||
|
|
||||||
|
|
||||||
class TestAuthnContextDecl:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.authn_context_decl = saml.AuthnContextDecl()
|
|
||||||
self.text = "http://www.example.com/authnContextDecl"
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for AuthnContextDecl accessors"""
|
|
||||||
self.authn_context_decl.text = self.text
|
|
||||||
assert self.authn_context_decl.text == self.text
|
|
||||||
new_authn_context_decl = saml.authn_context_decl_from_string(
|
|
||||||
self.authn_context_decl.to_string())
|
|
||||||
assert new_authn_context_decl.text == self.text
|
|
||||||
assert self.authn_context_decl.to_string() == \
|
|
||||||
new_authn_context_decl.to_string()
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test authn_context_decl_from_string() using test data"""
|
|
||||||
authn_context_decl = saml.authn_context_decl_from_string(
|
|
||||||
saml2_data.TEST_AUTHN_CONTEXT_DECL)
|
|
||||||
assert authn_context_decl.text.strip() == self.text
|
|
||||||
|
|
||||||
|
|
||||||
class TestAuthenticatingAuthority:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.authenticating_authority = saml.AuthenticatingAuthority()
|
|
||||||
self.text = "http://www.example.com/authenticatingAuthority"
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for AuthenticatingAuthority accessors"""
|
|
||||||
self.authenticating_authority.text = self.text
|
|
||||||
assert self.authenticating_authority.text == self.text
|
|
||||||
new_authenticating_authority = saml.authenticating_authority_from_string(
|
|
||||||
self.authenticating_authority.to_string())
|
|
||||||
assert new_authenticating_authority.text == self.text
|
|
||||||
assert self.authenticating_authority.to_string() == \
|
|
||||||
new_authenticating_authority.to_string()
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test authenticating_authority_from_string() using test data"""
|
|
||||||
authenticating_authority = saml.authenticating_authority_from_string(
|
|
||||||
saml2_data.TEST_AUTHENTICATING_AUTHORITY)
|
|
||||||
assert authenticating_authority.text.strip() == self.text
|
|
||||||
|
|
||||||
class TestAuthnContext:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.authn_context = saml.AuthnContext()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for AuthnContext accessors"""
|
|
||||||
self.authn_context.authn_context_class_ref = \
|
|
||||||
saml.authn_context_class_ref_from_string(
|
|
||||||
saml2_data.TEST_AUTHN_CONTEXT_CLASS_REF)
|
|
||||||
self.authn_context.authn_context_decl_ref = \
|
|
||||||
saml.authn_context_decl_ref_from_string(
|
|
||||||
saml2_data.TEST_AUTHN_CONTEXT_DECL_REF)
|
|
||||||
self.authn_context.authn_context_decl = \
|
|
||||||
saml.authn_context_decl_from_string(
|
|
||||||
saml2_data.TEST_AUTHN_CONTEXT_DECL)
|
|
||||||
self.authn_context.authenticating_authority.append(
|
|
||||||
saml.authenticating_authority_from_string(
|
|
||||||
saml2_data.TEST_AUTHENTICATING_AUTHORITY))
|
|
||||||
assert self.authn_context.authn_context_class_ref.text.strip() == \
|
|
||||||
"http://www.example.com/authnContextClassRef"
|
|
||||||
assert self.authn_context.authn_context_decl_ref.text.strip() == \
|
|
||||||
"http://www.example.com/authnContextDeclRef"
|
|
||||||
assert self.authn_context.authn_context_decl.text.strip() == \
|
|
||||||
"http://www.example.com/authnContextDecl"
|
|
||||||
assert self.authn_context.authenticating_authority[0].text.strip() == \
|
|
||||||
"http://www.example.com/authenticatingAuthority"
|
|
||||||
new_authn_context = saml.authn_context_from_string(
|
|
||||||
self.authn_context.to_string())
|
|
||||||
assert self.authn_context.to_string() == new_authn_context.to_string()
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test authn_context_from_string() using test data"""
|
|
||||||
authn_context = saml.authn_context_from_string(saml2_data.TEST_AUTHN_CONTEXT)
|
|
||||||
assert authn_context.authn_context_class_ref.text.strip() == \
|
|
||||||
saml.URN_PASSWORD
|
|
||||||
|
|
||||||
|
|
||||||
class TestAuthnStatement:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.authn_statem = saml.AuthnStatement()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for AuthnStatement accessors"""
|
|
||||||
self.authn_statem.authn_instant = "2007-08-31T01:05:02Z"
|
|
||||||
self.authn_statem.session_not_on_or_after = "2007-09-14T01:05:02Z"
|
|
||||||
self.authn_statem.session_index = "sessionindex"
|
|
||||||
self.authn_statem.authn_context = saml.AuthnContext()
|
|
||||||
self.authn_statem.authn_context.authn_context_class_ref = \
|
|
||||||
saml.authn_context_class_ref_from_string(
|
|
||||||
saml2_data.TEST_AUTHN_CONTEXT_CLASS_REF)
|
|
||||||
self.authn_statem.authn_context.authn_context_decl_ref = \
|
|
||||||
saml.authn_context_decl_ref_from_string(
|
|
||||||
saml2_data.TEST_AUTHN_CONTEXT_DECL_REF)
|
|
||||||
self.authn_statem.authn_context.authn_context_decl = \
|
|
||||||
saml.authn_context_decl_from_string(
|
|
||||||
saml2_data.TEST_AUTHN_CONTEXT_DECL)
|
|
||||||
self.authn_statem.authn_context.authenticating_authority.append(
|
|
||||||
saml.authenticating_authority_from_string(
|
|
||||||
saml2_data.TEST_AUTHENTICATING_AUTHORITY))
|
|
||||||
|
|
||||||
new_as = saml.authn_statement_from_string(self.authn_statem.to_string())
|
|
||||||
assert new_as.authn_instant == "2007-08-31T01:05:02Z"
|
|
||||||
assert new_as.session_index == "sessionindex"
|
|
||||||
assert new_as.session_not_on_or_after == "2007-09-14T01:05:02Z"
|
|
||||||
assert new_as.authn_context.authn_context_class_ref.text.strip() == \
|
|
||||||
"http://www.example.com/authnContextClassRef"
|
|
||||||
assert new_as.authn_context.authn_context_decl_ref.text.strip() == \
|
|
||||||
"http://www.example.com/authnContextDeclRef"
|
|
||||||
assert new_as.authn_context.authn_context_decl.text.strip() == \
|
|
||||||
"http://www.example.com/authnContextDecl"
|
|
||||||
assert new_as.authn_context.authenticating_authority[0].text.strip() \
|
|
||||||
== "http://www.example.com/authenticatingAuthority"
|
|
||||||
assert self.authn_statem.to_string() == new_as.to_string()
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test authn_statement_from_string() using test data"""
|
|
||||||
authn_statem = saml.authn_statement_from_string(saml2_data.TEST_AUTHN_STATEMENT)
|
|
||||||
assert authn_statem.authn_instant == "2007-08-31T01:05:02Z"
|
|
||||||
assert authn_statem.session_not_on_or_after == "2007-09-14T01:05:02Z"
|
|
||||||
assert authn_statem.authn_context.authn_context_class_ref.text.strip() == \
|
|
||||||
saml.URN_PASSWORD
|
|
||||||
|
|
||||||
|
|
||||||
class TestAttributeValue:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.attribute_value = saml.AttributeValue()
|
|
||||||
self.text = "value for test attribute"
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for AttributeValue accessors"""
|
|
||||||
|
|
||||||
self.attribute_value.text = self.text
|
|
||||||
new_attribute_value = saml.attribute_value_from_string(
|
|
||||||
self.attribute_value.to_string())
|
|
||||||
assert new_attribute_value.text.strip() == self.text
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test attribute_value_from_string() using test data"""
|
|
||||||
|
|
||||||
attribute_value = saml.attribute_value_from_string(
|
|
||||||
saml2_data.TEST_ATTRIBUTE_VALUE)
|
|
||||||
assert attribute_value.text.strip() == self.text
|
|
||||||
|
|
||||||
|
|
||||||
class TestAttribute:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.attribute = saml.Attribute()
|
|
||||||
self.text = ["value of test attribute",
|
|
||||||
"value1 of test attribute",
|
|
||||||
"value2 of test attribute"]
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for Attribute accessors"""
|
|
||||||
self.attribute.name = "testAttribute"
|
|
||||||
self.attribute.name_format = saml.NAME_FORMAT_URI
|
|
||||||
self.attribute.friendly_name = "test attribute"
|
|
||||||
self.attribute.attribute_value.append(saml.AttributeValue())
|
|
||||||
self.attribute.attribute_value[0].text = self.text[0]
|
|
||||||
|
|
||||||
new_attribute = saml.attribute_from_string(self.attribute.to_string())
|
|
||||||
assert new_attribute.name == "testAttribute"
|
|
||||||
assert new_attribute.name_format == saml.NAME_FORMAT_URI
|
|
||||||
assert new_attribute.friendly_name == "test attribute"
|
|
||||||
assert new_attribute.attribute_value[0].text.strip() == self.text[0]
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test attribute_from_string() using test data"""
|
|
||||||
attribute = saml.attribute_from_string(saml2_data.TEST_ATTRIBUTE)
|
|
||||||
assert attribute.name == "testAttribute"
|
|
||||||
assert attribute.name_format == saml.NAME_FORMAT_UNSPECIFIED
|
|
||||||
assert attribute.friendly_name == "test attribute"
|
|
||||||
assert attribute.attribute_value[0].text.strip() == self.text[1]
|
|
||||||
assert attribute.attribute_value[1].text.strip() == self.text[2]
|
|
||||||
# test again
|
|
||||||
attribute = saml.attribute_from_string(attribute.to_string())
|
|
||||||
assert attribute.name == "testAttribute"
|
|
||||||
assert attribute.name_format == saml.NAME_FORMAT_UNSPECIFIED
|
|
||||||
assert attribute.friendly_name == "test attribute"
|
|
||||||
assert attribute.attribute_value[0].text.strip() == self.text[1]
|
|
||||||
assert attribute.attribute_value[1].text.strip() == self.text[2]
|
|
||||||
|
|
||||||
|
|
||||||
class TestAttributeStatement:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.attr_statem = saml.AttributeStatement()
|
|
||||||
self.text = ["value of test attribute",
|
|
||||||
"value1 of test attribute",
|
|
||||||
"value2 of test attribute",
|
|
||||||
"value1 of test attribute2",
|
|
||||||
"value2 of test attribute2",]
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for Attribute accessors"""
|
|
||||||
self.attr_statem.attribute.append(saml.Attribute())
|
|
||||||
self.attr_statem.attribute.append(saml.Attribute())
|
|
||||||
self.attr_statem.attribute[0].name = "testAttribute"
|
|
||||||
self.attr_statem.attribute[0].name_format = saml.NAME_FORMAT_URI
|
|
||||||
self.attr_statem.attribute[0].friendly_name = "test attribute"
|
|
||||||
self.attr_statem.attribute[0].attribute_value.append(saml.AttributeValue())
|
|
||||||
self.attr_statem.attribute[0].attribute_value[0].text = self.text[0]
|
|
||||||
|
|
||||||
self.attr_statem.attribute[1].name = "testAttribute2"
|
|
||||||
self.attr_statem.attribute[1].name_format = saml.NAME_FORMAT_UNSPECIFIED
|
|
||||||
self.attr_statem.attribute[1].friendly_name = self.text[2]
|
|
||||||
self.attr_statem.attribute[1].attribute_value.append(saml.AttributeValue())
|
|
||||||
self.attr_statem.attribute[1].attribute_value[0].text = self.text[2]
|
|
||||||
|
|
||||||
new_as = saml.attribute_statement_from_string(self.attr_statem.to_string())
|
|
||||||
assert new_as.attribute[0].name == "testAttribute"
|
|
||||||
assert new_as.attribute[0].name_format == saml.NAME_FORMAT_URI
|
|
||||||
assert new_as.attribute[0].friendly_name == "test attribute"
|
|
||||||
assert new_as.attribute[0].attribute_value[0].text.strip() == self.text[0]
|
|
||||||
assert new_as.attribute[1].name == "testAttribute2"
|
|
||||||
assert new_as.attribute[1].name_format == saml.NAME_FORMAT_UNSPECIFIED
|
|
||||||
assert new_as.attribute[1].friendly_name == "value2 of test attribute"
|
|
||||||
assert new_as.attribute[1].attribute_value[0].text.strip() == self.text[2]
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test attribute_statement_from_string() using test data"""
|
|
||||||
attr_statem = saml.attribute_statement_from_string(saml2_data.TEST_ATTRIBUTE_STATEMENT)
|
|
||||||
assert attr_statem.attribute[0].name == "testAttribute"
|
|
||||||
assert attr_statem.attribute[0].name_format == saml.NAME_FORMAT_UNSPECIFIED
|
|
||||||
assert attr_statem.attribute[0].friendly_name == "test attribute"
|
|
||||||
assert attr_statem.attribute[0].attribute_value[0].text.strip() == self.text[1]
|
|
||||||
assert attr_statem.attribute[0].attribute_value[1].text.strip() == self.text[2]
|
|
||||||
assert attr_statem.attribute[1].name == "http://www.example.com/testAttribute2"
|
|
||||||
assert attr_statem.attribute[1].name_format == saml.NAME_FORMAT_URI
|
|
||||||
assert attr_statem.attribute[1].friendly_name == "test attribute2"
|
|
||||||
assert attr_statem.attribute[1].attribute_value[0].text.strip() == self.text[3]
|
|
||||||
assert attr_statem.attribute[1].attribute_value[1].text.strip() == self.text[4]
|
|
||||||
|
|
||||||
# test again
|
|
||||||
attr_statem2 = saml.attribute_statement_from_string(attr_statem.to_string())
|
|
||||||
assert attr_statem2.attribute[0].name == "testAttribute"
|
|
||||||
assert attr_statem2.attribute[0].name_format == saml.NAME_FORMAT_UNSPECIFIED
|
|
||||||
assert attr_statem2.attribute[0].friendly_name == "test attribute"
|
|
||||||
assert attr_statem2.attribute[0].attribute_value[0].text.strip() == self.text[1]
|
|
||||||
assert attr_statem2.attribute[0].attribute_value[1].text.strip() == self.text[2]
|
|
||||||
assert attr_statem2.attribute[1].name == "http://www.example.com/testAttribute2"
|
|
||||||
assert attr_statem2.attribute[1].name_format == saml.NAME_FORMAT_URI
|
|
||||||
assert attr_statem2.attribute[1].friendly_name == "test attribute2"
|
|
||||||
assert attr_statem2.attribute[1].attribute_value[0].text.strip() == self.text[3]
|
|
||||||
assert attr_statem2.attribute[1].attribute_value[1].text.strip() == self.text[4]
|
|
||||||
|
|
||||||
|
|
||||||
class TestSubjectConfirmationData:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.scd = saml.SubjectConfirmationData()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for SubjectConfirmationData accessors"""
|
|
||||||
|
|
||||||
self.scd.not_before = "2007-08-31T01:05:02Z"
|
|
||||||
self.scd.not_on_or_after = "2007-09-14T01:05:02Z"
|
|
||||||
self.scd.recipient = "recipient"
|
|
||||||
self.scd.in_response_to = "responseID"
|
|
||||||
self.scd.address = "127.0.0.1"
|
|
||||||
new_scd = saml.subject_confirmation_data_from_string(self.scd.to_string())
|
|
||||||
assert new_scd.not_before == "2007-08-31T01:05:02Z"
|
|
||||||
assert new_scd.not_on_or_after == "2007-09-14T01:05:02Z"
|
|
||||||
assert new_scd.recipient == "recipient"
|
|
||||||
assert new_scd.in_response_to == "responseID"
|
|
||||||
assert new_scd.address == "127.0.0.1"
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test subject_confirmation_data_from_string() using test data"""
|
|
||||||
|
|
||||||
scd = saml.subject_confirmation_data_from_string(
|
|
||||||
saml2_data.TEST_SUBJECT_CONFIRMATION_DATA)
|
|
||||||
assert scd.not_before == "2007-08-31T01:05:02Z"
|
|
||||||
assert scd.not_on_or_after == "2007-09-14T01:05:02Z"
|
|
||||||
assert scd.recipient == "recipient"
|
|
||||||
assert scd.in_response_to == "responseID"
|
|
||||||
assert scd.address == "127.0.0.1"
|
|
||||||
|
|
||||||
|
|
||||||
class TestSubjectConfirmation:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.sc = saml.SubjectConfirmation()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for SubjectConfirmation accessors"""
|
|
||||||
self.sc.name_id = saml.name_id_from_string(saml2_data.TEST_NAME_ID)
|
|
||||||
self.sc.method = saml.SUBJECT_CONFIRMATION_METHOD_BEARER
|
|
||||||
self.sc.subject_confirmation_data = saml.subject_confirmation_data_from_string(
|
|
||||||
saml2_data.TEST_SUBJECT_CONFIRMATION_DATA)
|
|
||||||
new_sc = saml.subject_confirmation_from_string(self.sc.to_string())
|
|
||||||
assert new_sc.name_id.sp_provided_id == "sp provided id"
|
|
||||||
assert new_sc.method == saml.SUBJECT_CONFIRMATION_METHOD_BEARER
|
|
||||||
assert new_sc.subject_confirmation_data.not_before == \
|
|
||||||
"2007-08-31T01:05:02Z"
|
|
||||||
assert new_sc.subject_confirmation_data.not_on_or_after == \
|
|
||||||
"2007-09-14T01:05:02Z"
|
|
||||||
assert new_sc.subject_confirmation_data.recipient == "recipient"
|
|
||||||
assert new_sc.subject_confirmation_data.in_response_to == "responseID"
|
|
||||||
assert new_sc.subject_confirmation_data.address == "127.0.0.1"
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test subject_confirmation_from_string() using test data"""
|
|
||||||
|
|
||||||
sc = saml.subject_confirmation_from_string(
|
|
||||||
saml2_data.TEST_SUBJECT_CONFIRMATION)
|
|
||||||
assert sc.name_id.sp_provided_id == "sp provided id"
|
|
||||||
assert sc.method == saml.SUBJECT_CONFIRMATION_METHOD_BEARER
|
|
||||||
assert sc.subject_confirmation_data.not_before == "2007-08-31T01:05:02Z"
|
|
||||||
assert sc.subject_confirmation_data.not_on_or_after == "2007-09-14T01:05:02Z"
|
|
||||||
assert sc.subject_confirmation_data.recipient == "recipient"
|
|
||||||
assert sc.subject_confirmation_data.in_response_to == "responseID"
|
|
||||||
assert sc.subject_confirmation_data.address == "127.0.0.1"
|
|
||||||
|
|
||||||
|
|
||||||
class TestSubject:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.subject = saml.Subject()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for Subject accessors"""
|
|
||||||
self.subject.name_id = saml.name_id_from_string(saml2_data.TEST_NAME_ID)
|
|
||||||
self.subject.subject_confirmation.append(
|
|
||||||
saml.subject_confirmation_from_string(
|
|
||||||
saml2_data.TEST_SUBJECT_CONFIRMATION))
|
|
||||||
new_subject = saml.subject_from_string(self.subject.to_string())
|
|
||||||
assert new_subject.name_id.sp_provided_id == "sp provided id"
|
|
||||||
assert new_subject.name_id.text.strip() == "tmatsuo@example.com"
|
|
||||||
assert new_subject.name_id.format == saml.NAMEID_FORMAT_EMAILADDRESS
|
|
||||||
assert isinstance(new_subject.subject_confirmation[0],
|
|
||||||
saml.SubjectConfirmation)
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test for subject_from_string() using test data."""
|
|
||||||
|
|
||||||
subject = saml.subject_from_string(saml2_data.TEST_SUBJECT)
|
|
||||||
assert subject.name_id.sp_provided_id == "sp provided id"
|
|
||||||
assert subject.name_id.text.strip() == "tmatsuo@example.com"
|
|
||||||
assert subject.name_id.format == saml.NAMEID_FORMAT_EMAILADDRESS
|
|
||||||
assert isinstance(subject.subject_confirmation[0],
|
|
||||||
saml.SubjectConfirmation)
|
|
||||||
|
|
||||||
|
|
||||||
class TestCondition:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.condition = saml.Condition()
|
|
||||||
self.name = "{%s}type" % saml.XSI_NAMESPACE
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for Condition accessors."""
|
|
||||||
self.condition.extension_attributes[self.name] = "test"
|
|
||||||
self.condition.extension_attributes['ExtendedAttribute'] = "value"
|
|
||||||
new_condition = saml.condition_from_string(self.condition.to_string())
|
|
||||||
assert new_condition.extension_attributes[self.name] == "test"
|
|
||||||
assert new_condition.extension_attributes["ExtendedAttribute"] == "value"
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test for condition_from_string() using test data."""
|
|
||||||
condition = saml.condition_from_string(saml2_data.TEST_CONDITION)
|
|
||||||
assert condition.extension_attributes[self.name] == "test"
|
|
||||||
assert condition.extension_attributes["ExtendedAttribute"] == "value"
|
|
||||||
|
|
||||||
|
|
||||||
class TestAudience:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.audience = saml.Audience()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for Audience accessors"""
|
|
||||||
|
|
||||||
self.audience.text = "http://www.example.com/Audience"
|
|
||||||
new_audience = saml.audience_from_string(self.audience.to_string())
|
|
||||||
assert new_audience.text.strip() == "http://www.example.com/Audience"
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test audience_from_string using test data"""
|
|
||||||
|
|
||||||
audience = saml.audience_from_string(saml2_data.TEST_AUDIENCE)
|
|
||||||
assert audience.text.strip() == "http://www.example.com/Audience"
|
|
||||||
|
|
||||||
|
|
||||||
class TestAudienceRestriction:
|
|
||||||
def setup_class(self):
|
|
||||||
self.audience_restriction = saml.AudienceRestriction()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for AudienceRestriction accessors"""
|
|
||||||
|
|
||||||
self.audience_restriction.audience = \
|
|
||||||
saml.audience_from_string(saml2_data.TEST_AUDIENCE)
|
|
||||||
new_audience = saml.audience_restriction_from_string(
|
|
||||||
self.audience_restriction.to_string())
|
|
||||||
assert self.audience_restriction.audience.text.strip() == \
|
|
||||||
"http://www.example.com/Audience"
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test audience_restriction_from_string using test data"""
|
|
||||||
|
|
||||||
audience_restriction = saml.audience_restriction_from_string(
|
|
||||||
saml2_data.TEST_AUDIENCE_RESTRICTION)
|
|
||||||
assert audience_restriction.audience.text.strip() == \
|
|
||||||
"http://www.example.com/Audience"
|
|
||||||
|
|
||||||
|
|
||||||
class TestOneTimeUse:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.one_time_use = saml.OneTimeUse()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for OneTimeUse accessors"""
|
|
||||||
assert isinstance(self.one_time_use, saml.OneTimeUse)
|
|
||||||
assert isinstance(self.one_time_use, saml.Condition)
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test one_time_use_from_string() using test data"""
|
|
||||||
one_time_use = saml.one_time_use_from_string(saml2_data.TEST_ONE_TIME_USE)
|
|
||||||
assert isinstance(one_time_use, saml.OneTimeUse)
|
|
||||||
assert isinstance(one_time_use, saml.Condition)
|
|
||||||
|
|
||||||
|
|
||||||
class TestProxyRestriction:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.proxy_restriction = saml.ProxyRestriction()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for ProxyRestriction accessors"""
|
|
||||||
|
|
||||||
assert isinstance(self.proxy_restriction, saml.Condition)
|
|
||||||
self.proxy_restriction.count = "2"
|
|
||||||
self.proxy_restriction.audience.append(saml.audience_from_string(
|
|
||||||
saml2_data.TEST_AUDIENCE))
|
|
||||||
new_proxy_restriction = saml.proxy_restriction_from_string(
|
|
||||||
self.proxy_restriction.to_string())
|
|
||||||
assert new_proxy_restriction.count == "2"
|
|
||||||
assert new_proxy_restriction.audience[0].text.strip() == \
|
|
||||||
"http://www.example.com/Audience"
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test proxy_restriction_from_string() using test data"""
|
|
||||||
|
|
||||||
proxy_restriction = saml.proxy_restriction_from_string(
|
|
||||||
saml2_data.TEST_PROXY_RESTRICTION)
|
|
||||||
assert proxy_restriction.count == "2"
|
|
||||||
assert proxy_restriction.audience[0].text.strip() == \
|
|
||||||
"http://www.example.com/Audience"
|
|
||||||
|
|
||||||
class TestConditions:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.conditions = saml.Conditions()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for Conditions accessors"""
|
|
||||||
self.conditions.not_before = "2007-08-31T01:05:02Z"
|
|
||||||
self.conditions.not_on_or_after = "2007-09-14T01:05:02Z"
|
|
||||||
self.conditions.condition.append(saml.Condition())
|
|
||||||
self.conditions.audience_restriction.append(saml.AudienceRestriction())
|
|
||||||
self.conditions.one_time_use.append(saml.OneTimeUse())
|
|
||||||
self.conditions.proxy_restriction.append(saml.ProxyRestriction())
|
|
||||||
new_conditions = saml.conditions_from_string(self.conditions.to_string())
|
|
||||||
assert new_conditions.not_before == "2007-08-31T01:05:02Z"
|
|
||||||
assert new_conditions.not_on_or_after == "2007-09-14T01:05:02Z"
|
|
||||||
assert isinstance(new_conditions.condition[0], saml.Condition)
|
|
||||||
assert isinstance(new_conditions.audience_restriction[0],
|
|
||||||
saml.AudienceRestriction)
|
|
||||||
assert isinstance(new_conditions.one_time_use[0],
|
|
||||||
saml.OneTimeUse)
|
|
||||||
assert isinstance(new_conditions.proxy_restriction[0],
|
|
||||||
saml.ProxyRestriction)
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test conditions_from_string() using test data"""
|
|
||||||
new_conditions = saml.conditions_from_string(saml2_data.TEST_CONDITIONS)
|
|
||||||
assert new_conditions.not_before == "2007-08-31T01:05:02Z"
|
|
||||||
assert new_conditions.not_on_or_after == "2007-09-14T01:05:02Z"
|
|
||||||
assert isinstance(new_conditions.condition[0], saml.Condition)
|
|
||||||
assert isinstance(new_conditions.audience_restriction[0],
|
|
||||||
saml.AudienceRestriction)
|
|
||||||
assert isinstance(new_conditions.one_time_use[0],
|
|
||||||
saml.OneTimeUse)
|
|
||||||
assert isinstance(new_conditions.proxy_restriction[0],
|
|
||||||
saml.ProxyRestriction)
|
|
||||||
|
|
||||||
class TestAssertionIDRef:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.assertion_id_ref = saml.AssertionIDRef()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for AssertionIDRef accessors"""
|
|
||||||
self.assertion_id_ref.text = "zzlieajngjbkjggjldmgindkckkolcblndbghlhm"
|
|
||||||
new_assertion_id_ref = saml.assertion_id_ref_from_string(
|
|
||||||
self.assertion_id_ref.to_string())
|
|
||||||
assert new_assertion_id_ref.text == \
|
|
||||||
"zzlieajngjbkjggjldmgindkckkolcblndbghlhm"
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test assertion_id_ref_from_string() using test data"""
|
|
||||||
new_assertion_id_ref = saml.assertion_id_ref_from_string(
|
|
||||||
saml2_data.TEST_ASSERTION_ID_REF)
|
|
||||||
assert new_assertion_id_ref.text.strip() == \
|
|
||||||
"zzlieajngjbkjggjldmgindkckkolcblndbghlhm"
|
|
||||||
|
|
||||||
|
|
||||||
class TestAssertionURIRef:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.assertion_uri_ref = saml.AssertionURIRef()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for AssertionURIRef accessors"""
|
|
||||||
self.assertion_uri_ref.text = "http://www.example.com/AssertionURIRef"
|
|
||||||
new_assertion_uri_ref = saml.assertion_uri_ref_from_string(
|
|
||||||
self.assertion_uri_ref.to_string())
|
|
||||||
assert new_assertion_uri_ref.text == \
|
|
||||||
"http://www.example.com/AssertionURIRef"
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test assertion_uri_ref_from_string() using test data"""
|
|
||||||
new_assertion_uri_ref = saml.assertion_uri_ref_from_string(
|
|
||||||
saml2_data.TEST_ASSERTION_URI_REF)
|
|
||||||
assert new_assertion_uri_ref.text.strip() == \
|
|
||||||
"http://www.example.com/AssertionURIRef"
|
|
||||||
|
|
||||||
|
|
||||||
class TestAction:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.action = saml.Action()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for Action accessors"""
|
|
||||||
self.action.namespace = "http://www.example.com/Namespace"
|
|
||||||
new_action = saml.action_from_string(self.action.to_string())
|
|
||||||
assert new_action.namespace == "http://www.example.com/Namespace"
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test action_from_string() using test data"""
|
|
||||||
new_action = saml.action_from_string(saml2_data.TEST_ACTION)
|
|
||||||
assert new_action.namespace == "http://www.example.com/Namespace"
|
|
||||||
|
|
||||||
|
|
||||||
class TestEvidence:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.evidence = saml.Evidence()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for Evidence accessors"""
|
|
||||||
self.evidence.assertion_id_ref.append(saml.AssertionIDRef())
|
|
||||||
self.evidence.assertion_uri_ref.append(saml.AssertionURIRef())
|
|
||||||
self.evidence.assertion.append(saml.Assertion())
|
|
||||||
self.evidence.encrypted_assertion.append(saml.EncryptedAssertion())
|
|
||||||
new_evidence = saml.evidence_from_string(self.evidence.to_string())
|
|
||||||
print new_evidence
|
|
||||||
assert self.evidence.to_string() == new_evidence.to_string()
|
|
||||||
assert isinstance(new_evidence.assertion_id_ref[0],
|
|
||||||
saml.AssertionIDRef)
|
|
||||||
assert isinstance(new_evidence.assertion_uri_ref[0],
|
|
||||||
saml.AssertionURIRef)
|
|
||||||
assert len(new_evidence.assertion) == 1
|
|
||||||
assert isinstance(new_evidence.assertion[0], saml.Assertion)
|
|
||||||
assert len(new_evidence.encrypted_assertion) == 1
|
|
||||||
assert isinstance(new_evidence.encrypted_assertion[0],
|
|
||||||
saml.EncryptedAssertion)
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test evidence_from_string() using test data"""
|
|
||||||
# TODO:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class TestAuthzDecisionStatement:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.authz_decision_statement = saml.AuthzDecisionStatement()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for AuthzDecisionStatement accessors"""
|
|
||||||
self.authz_decision_statement.resource = "http://www.example.com/Resource"
|
|
||||||
self.authz_decision_statement.decision = saml.DECISION_TYPE_PERMIT
|
|
||||||
self.authz_decision_statement.action.append(saml.Action())
|
|
||||||
self.authz_decision_statement.evidence.append(saml.Evidence())
|
|
||||||
new_authz_decision_statement = saml.authz_decision_statement_from_string(
|
|
||||||
self.authz_decision_statement.to_string())
|
|
||||||
assert self.authz_decision_statement.to_string() == \
|
|
||||||
new_authz_decision_statement.to_string()
|
|
||||||
assert new_authz_decision_statement.resource == \
|
|
||||||
"http://www.example.com/Resource"
|
|
||||||
assert new_authz_decision_statement.decision == \
|
|
||||||
saml.DECISION_TYPE_PERMIT
|
|
||||||
assert isinstance(new_authz_decision_statement.action[0],
|
|
||||||
saml.Action)
|
|
||||||
assert isinstance(new_authz_decision_statement.evidence[0],
|
|
||||||
saml.Evidence)
|
|
||||||
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test authz_decision_statement_from_string() using test data"""
|
|
||||||
# TODO:
|
|
||||||
pass
|
|
||||||
|
|
||||||
class TestAdvice:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.advice = saml.Advice()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for Advice accessors"""
|
|
||||||
self.advice.assertion_id_ref.append(saml.AssertionIDRef())
|
|
||||||
self.advice.assertion_uri_ref.append(saml.AssertionURIRef())
|
|
||||||
self.advice.assertion.append(saml.Assertion())
|
|
||||||
self.advice.encrypted_assertion.append(saml.EncryptedAssertion())
|
|
||||||
new_advice = saml.advice_from_string(self.advice.to_string())
|
|
||||||
assert self.advice.to_string() == new_advice.to_string()
|
|
||||||
assert isinstance(new_advice.assertion_id_ref[0],
|
|
||||||
saml.AssertionIDRef)
|
|
||||||
assert isinstance(new_advice.assertion_uri_ref[0],
|
|
||||||
saml.AssertionURIRef)
|
|
||||||
assert isinstance(new_advice.assertion[0], saml.Assertion)
|
|
||||||
assert isinstance(new_advice.encrypted_assertion[0],
|
|
||||||
saml.EncryptedAssertion)
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test advice_from_string() using test data"""
|
|
||||||
# TODO:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class TestAssertion:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.assertion = saml.Assertion()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for Assertion accessors"""
|
|
||||||
self.assertion.id = "assertion id"
|
|
||||||
self.assertion.version = saml2.VERSION
|
|
||||||
self.assertion.issue_instant = "2007-08-31T01:05:02Z"
|
|
||||||
self.assertion.issuer = saml.issuer_from_string(saml2_data.TEST_ISSUER)
|
|
||||||
self.assertion.signature = ds.signature_from_string(
|
|
||||||
ds_data.TEST_SIGNATURE)
|
|
||||||
self.assertion.subject = saml.subject_from_string(saml2_data.TEST_SUBJECT)
|
|
||||||
self.assertion.conditions = saml.conditions_from_string(
|
|
||||||
saml2_data.TEST_CONDITIONS)
|
|
||||||
self.assertion.advice = saml.Advice()
|
|
||||||
self.assertion.statement.append(saml.Statement())
|
|
||||||
self.assertion.authn_statement.append(saml.authn_statement_from_string(
|
|
||||||
saml2_data.TEST_AUTHN_STATEMENT))
|
|
||||||
self.assertion.authz_decision_statement.append(
|
|
||||||
saml.AuthzDecisionStatement())
|
|
||||||
self.assertion.attribute_statement.append(
|
|
||||||
saml.attribute_statement_from_string(
|
|
||||||
saml2_data.TEST_ATTRIBUTE_STATEMENT))
|
|
||||||
|
|
||||||
new_assertion = saml.assertion_from_string(self.assertion.to_string())
|
|
||||||
assert new_assertion.id == "assertion id"
|
|
||||||
assert new_assertion.version == saml2.VERSION
|
|
||||||
assert new_assertion.issue_instant == "2007-08-31T01:05:02Z"
|
|
||||||
assert isinstance(new_assertion.issuer, saml.Issuer)
|
|
||||||
assert isinstance(new_assertion.signature, ds.Signature)
|
|
||||||
assert isinstance(new_assertion.subject, saml.Subject)
|
|
||||||
assert isinstance(new_assertion.conditions, saml.Conditions)
|
|
||||||
assert isinstance(new_assertion.advice, saml.Advice)
|
|
||||||
assert isinstance(new_assertion.statement[0], saml.Statement)
|
|
||||||
assert isinstance(new_assertion.authn_statement[0],
|
|
||||||
saml.AuthnStatement)
|
|
||||||
assert isinstance(new_assertion.authz_decision_statement[0],
|
|
||||||
saml.AuthzDecisionStatement)
|
|
||||||
assert isinstance(new_assertion.attribute_statement[0],
|
|
||||||
saml.AttributeStatement)
|
|
||||||
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test assertion_from_string() using test data"""
|
|
||||||
# TODO
|
|
||||||
pass
|
|
||||||
@@ -1,535 +0,0 @@
|
|||||||
#!/usr/bin/python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
#
|
|
||||||
# Copyright (C) 2009 Umeå University.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
"""Tests for saml2.samlp"""
|
|
||||||
|
|
||||||
__author__ = 'roland.hedberg@adm.umu.se (Roland Hedberg)'
|
|
||||||
|
|
||||||
import unittest
|
|
||||||
try:
|
|
||||||
from xml.etree import ElementTree
|
|
||||||
except ImportError:
|
|
||||||
from elementtree import ElementTree
|
|
||||||
import saml2
|
|
||||||
from saml2 import saml, samlp
|
|
||||||
import saml2_data, ds_data, samlp_data
|
|
||||||
import xmldsig as ds
|
|
||||||
|
|
||||||
|
|
||||||
class TestAbstractRequest:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.ar = samlp.AbstractRequest()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for AbstractRequest accessors"""
|
|
||||||
self.ar.id = "request id"
|
|
||||||
self.ar.version = saml2.VERSION
|
|
||||||
self.ar.issue_instant = "2007-09-14T01:05:02Z"
|
|
||||||
self.ar.destination = "http://www.example.com/Destination"
|
|
||||||
self.ar.consent = saml.CONSENT_UNSPECIFIED
|
|
||||||
self.ar.issuer = saml.Issuer()
|
|
||||||
self.ar.signature = ds.get_empty_signature()
|
|
||||||
self.ar.extensions = samlp.Extensions()
|
|
||||||
|
|
||||||
new_ar = samlp.abstract_request_from_string(self.ar.to_string())
|
|
||||||
assert new_ar.id == "request id"
|
|
||||||
assert new_ar.version == saml2.VERSION
|
|
||||||
assert new_ar.issue_instant == "2007-09-14T01:05:02Z"
|
|
||||||
assert new_ar.destination == "http://www.example.com/Destination"
|
|
||||||
assert new_ar.consent == saml.CONSENT_UNSPECIFIED
|
|
||||||
assert isinstance(new_ar.issuer, saml.Issuer)
|
|
||||||
assert isinstance(new_ar.signature, ds.Signature)
|
|
||||||
assert isinstance(new_ar.extensions, samlp.Extensions)
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test for abstract_request_from_string() using test data"""
|
|
||||||
# TODO:
|
|
||||||
pass
|
|
||||||
|
|
||||||
class TestStatusDetail:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.status_detail = samlp.StatusDetail()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for StatusDetail accessors"""
|
|
||||||
# TODO:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class TestStatusMessage:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.status_message = samlp.StatusMessage()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for StatusMessage accessors"""
|
|
||||||
# TODO:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class TestStatusCode:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.status_code = samlp.StatusCode()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for StatusCode accessors"""
|
|
||||||
self.status_code.value = samlp.STATUS_RESPONDER
|
|
||||||
self.status_code.status_code = samlp.StatusCode(
|
|
||||||
value=samlp.STATUS_REQUEST_DENIED)
|
|
||||||
print self.status_code.__dict__
|
|
||||||
new_status_code = samlp.status_code_from_string(self.status_code.to_string())
|
|
||||||
assert new_status_code.value == samlp.STATUS_RESPONDER
|
|
||||||
assert new_status_code.status_code.value == \
|
|
||||||
samlp.STATUS_REQUEST_DENIED
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test for status_code_from_string() using test data"""
|
|
||||||
new_status_code = samlp.status_code_from_string(
|
|
||||||
samlp_data.TEST_STATUS_CODE)
|
|
||||||
assert new_status_code.value == samlp.STATUS_RESPONDER
|
|
||||||
assert new_status_code.status_code.value == \
|
|
||||||
samlp.STATUS_REQUEST_DENIED
|
|
||||||
|
|
||||||
|
|
||||||
class TestStatus:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.status = samlp.Status()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for Status accessors"""
|
|
||||||
self.status.status_code = samlp.StatusCode()
|
|
||||||
self.status.status_message = samlp.StatusMessage()
|
|
||||||
self.status.status_detail = samlp.StatusDetail()
|
|
||||||
new_status = samlp.status_from_string(self.status.to_string())
|
|
||||||
assert isinstance(new_status.status_code, samlp.StatusCode)
|
|
||||||
assert isinstance(new_status.status_message, samlp.StatusMessage)
|
|
||||||
assert isinstance(new_status.status_detail, samlp.StatusDetail)
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test for status_from_string using test data"""
|
|
||||||
new_status = samlp.status_from_string(samlp_data.TEST_STATUS)
|
|
||||||
assert isinstance(new_status.status_code, samlp.StatusCode)
|
|
||||||
assert isinstance(new_status.status_code.status_code,
|
|
||||||
samlp.StatusCode)
|
|
||||||
assert isinstance(new_status.status_message, samlp.StatusMessage)
|
|
||||||
assert isinstance(new_status.status_detail, samlp.StatusDetail)
|
|
||||||
|
|
||||||
class TestStatusResponse:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.sr = samlp.StatusResponse()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for StatusResponse accessors"""
|
|
||||||
self.sr.id = "response id"
|
|
||||||
self.sr.in_response_to = "request id"
|
|
||||||
self.sr.version = saml2.VERSION
|
|
||||||
self.sr.issue_instant = "2007-09-14T01:05:02Z"
|
|
||||||
self.sr.destination = "http://www.example.com/Destination"
|
|
||||||
self.sr.consent = saml.CONSENT_UNSPECIFIED
|
|
||||||
self.sr.issuer = saml.Issuer()
|
|
||||||
self.sr.signature = ds.get_empty_signature()
|
|
||||||
self.sr.extensions = samlp.Extensions()
|
|
||||||
self.sr.status = samlp.Status()
|
|
||||||
|
|
||||||
new_sr = samlp.status_response_from_string(self.sr.to_string())
|
|
||||||
assert new_sr.id == "response id"
|
|
||||||
assert new_sr.in_response_to == "request id"
|
|
||||||
assert new_sr.version == saml2.VERSION
|
|
||||||
assert new_sr.issue_instant == "2007-09-14T01:05:02Z"
|
|
||||||
assert new_sr.destination == "http://www.example.com/Destination"
|
|
||||||
assert new_sr.consent == saml.CONSENT_UNSPECIFIED
|
|
||||||
assert isinstance(new_sr.issuer, saml.Issuer)
|
|
||||||
assert isinstance(new_sr.signature, ds.Signature)
|
|
||||||
assert isinstance(new_sr.extensions, samlp.Extensions)
|
|
||||||
assert isinstance(new_sr.status, samlp.Status)
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test for status_response_from_string() using test data"""
|
|
||||||
# TODO:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class TestResponse:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.response = samlp.Response()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for Response accessors"""
|
|
||||||
self.response.id = "response id"
|
|
||||||
self.response.in_response_to = "request id"
|
|
||||||
self.response.version = saml2.VERSION
|
|
||||||
self.response.issue_instant = "2007-09-14T01:05:02Z"
|
|
||||||
self.response.destination = "http://www.example.com/Destination"
|
|
||||||
self.response.consent = saml.CONSENT_UNSPECIFIED
|
|
||||||
self.response.issuer = saml.Issuer()
|
|
||||||
self.response.signature = ds.get_empty_signature()
|
|
||||||
self.response.extensions = samlp.Extensions()
|
|
||||||
self.response.status = samlp.Status()
|
|
||||||
self.response.assertion.append(saml.Assertion())
|
|
||||||
self.response.encrypted_assertion.append(saml.EncryptedAssertion())
|
|
||||||
|
|
||||||
new_response = samlp.response_from_string(self.response.to_string())
|
|
||||||
assert new_response.id == "response id"
|
|
||||||
assert new_response.in_response_to == "request id"
|
|
||||||
assert new_response.version == saml2.VERSION
|
|
||||||
assert new_response.issue_instant == "2007-09-14T01:05:02Z"
|
|
||||||
assert new_response.destination == "http://www.example.com/Destination"
|
|
||||||
assert new_response.consent == saml.CONSENT_UNSPECIFIED
|
|
||||||
assert isinstance(new_response.issuer, saml.Issuer)
|
|
||||||
assert isinstance(new_response.signature, ds.Signature)
|
|
||||||
assert isinstance(new_response.extensions, samlp.Extensions)
|
|
||||||
assert isinstance(new_response.status, samlp.Status)
|
|
||||||
|
|
||||||
assert isinstance(new_response.assertion[0], saml.Assertion)
|
|
||||||
assert isinstance(new_response.encrypted_assertion[0],
|
|
||||||
saml.EncryptedAssertion)
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test for response_from_string() using test data"""
|
|
||||||
# TODO:
|
|
||||||
pass
|
|
||||||
|
|
||||||
class TestNameIDPolicy:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.name_id_policy = samlp.NameIDPolicy()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for NameIDPolicy accessors"""
|
|
||||||
self.name_id_policy.format = saml.NAMEID_FORMAT_EMAILADDRESS
|
|
||||||
self.name_id_policy.sp_name_qualifier = saml.NAMEID_FORMAT_PERSISTENT
|
|
||||||
self.name_id_policy.allow_create = 'false'
|
|
||||||
|
|
||||||
new_name_id_policy = samlp.name_id_policy_from_string(
|
|
||||||
self.name_id_policy.to_string())
|
|
||||||
|
|
||||||
assert new_name_id_policy.format == saml.NAMEID_FORMAT_EMAILADDRESS
|
|
||||||
assert new_name_id_policy.sp_name_qualifier == \
|
|
||||||
saml.NAMEID_FORMAT_PERSISTENT
|
|
||||||
assert new_name_id_policy.allow_create == 'false'
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test for name_id_policy_from_string() using test data"""
|
|
||||||
new_name_id_policy = samlp.name_id_policy_from_string(
|
|
||||||
samlp_data.TEST_NAME_ID_POLICY)
|
|
||||||
|
|
||||||
assert new_name_id_policy.format == saml.NAMEID_FORMAT_EMAILADDRESS
|
|
||||||
assert new_name_id_policy.sp_name_qualifier == \
|
|
||||||
saml.NAMEID_FORMAT_PERSISTENT
|
|
||||||
assert new_name_id_policy.allow_create == 'false'
|
|
||||||
|
|
||||||
|
|
||||||
class TestIDPEntry:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.idp_entry = samlp.IDPEntry()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for IDPEntry accessors"""
|
|
||||||
self.idp_entry.provider_id = "http://www.example.com/provider"
|
|
||||||
self.idp_entry.name = "the provider"
|
|
||||||
self.idp_entry.loc = "http://www.example.com/Loc"
|
|
||||||
|
|
||||||
new_idp_entry = samlp.idp_entry_from_string(self.idp_entry.to_string())
|
|
||||||
assert new_idp_entry.provider_id == "http://www.example.com/provider"
|
|
||||||
assert new_idp_entry.name == "the provider"
|
|
||||||
assert new_idp_entry.loc == "http://www.example.com/Loc"
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test for idp_entry_from_string() using test data"""
|
|
||||||
new_idp_entry = samlp.idp_entry_from_string(samlp_data.TEST_IDP_ENTRY)
|
|
||||||
assert new_idp_entry.provider_id == "http://www.example.com/provider"
|
|
||||||
assert new_idp_entry.name == "the provider"
|
|
||||||
assert new_idp_entry.loc == "http://www.example.com/Loc"
|
|
||||||
|
|
||||||
|
|
||||||
class TestIDPList:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.idp_list = samlp.IDPList()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for IDPList accessors"""
|
|
||||||
self.idp_list.idp_entry.append(samlp.idp_entry_from_string(
|
|
||||||
samlp_data.TEST_IDP_ENTRY))
|
|
||||||
self.idp_list.get_complete = samlp.GetComplete(
|
|
||||||
text="http://www.example.com/GetComplete")
|
|
||||||
new_idp_list = samlp.idp_list_from_string(self.idp_list.to_string())
|
|
||||||
assert isinstance(new_idp_list.idp_entry[0], samlp.IDPEntry)
|
|
||||||
assert new_idp_list.get_complete.text.strip() == \
|
|
||||||
"http://www.example.com/GetComplete"
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test for idp_list_from_string() using test data"""
|
|
||||||
new_idp_list = samlp.idp_list_from_string(samlp_data.TEST_IDP_LIST)
|
|
||||||
assert isinstance(new_idp_list.idp_entry[0], samlp.IDPEntry)
|
|
||||||
assert new_idp_list.get_complete.text.strip() == \
|
|
||||||
"http://www.example.com/GetComplete"
|
|
||||||
|
|
||||||
|
|
||||||
class TestScoping:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.scoping = samlp.Scoping()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for Scoping accessors"""
|
|
||||||
|
|
||||||
self.scoping.proxy_count = "1"
|
|
||||||
self.scoping.idp_list = samlp.IDPList()
|
|
||||||
self.scoping.requester_id.append(samlp.RequesterID())
|
|
||||||
|
|
||||||
new_scoping = samlp.scoping_from_string(self.scoping.to_string())
|
|
||||||
|
|
||||||
assert new_scoping.proxy_count == "1"
|
|
||||||
assert isinstance(new_scoping.idp_list, samlp.IDPList)
|
|
||||||
assert isinstance(new_scoping.requester_id[0], samlp.RequesterID)
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test for scoping_from_string() using test data"""
|
|
||||||
new_scoping = samlp.scoping_from_string(samlp_data.TEST_SCOPING)
|
|
||||||
|
|
||||||
assert new_scoping.proxy_count == "1"
|
|
||||||
assert isinstance(new_scoping.idp_list, samlp.IDPList)
|
|
||||||
assert isinstance(new_scoping.requester_id[0], samlp.RequesterID)
|
|
||||||
|
|
||||||
|
|
||||||
class TestRequestedAuthnContext:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.context = samlp.RequestedAuthnContext()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for RequestedAuthnContext accessors"""
|
|
||||||
|
|
||||||
self.context.authn_context_class_ref.append(saml.AuthnContextClassRef())
|
|
||||||
self.context.authn_context_decl_ref.append(saml.AuthnContextDeclRef())
|
|
||||||
self.context.comparison = "exact"
|
|
||||||
|
|
||||||
new_context = samlp.requested_authn_context_from_string(
|
|
||||||
self.context.to_string())
|
|
||||||
|
|
||||||
assert isinstance(new_context.authn_context_class_ref[0],
|
|
||||||
saml.AuthnContextClassRef)
|
|
||||||
assert isinstance(new_context.authn_context_decl_ref[0],
|
|
||||||
saml.AuthnContextDeclRef)
|
|
||||||
assert new_context.comparison == "exact"
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test for requested_authn_context_from_string() using test data"""
|
|
||||||
new_context = samlp.requested_authn_context_from_string(
|
|
||||||
samlp_data.TEST_REQUESTED_AUTHN_CONTEXT)
|
|
||||||
|
|
||||||
assert isinstance(new_context.authn_context_class_ref[0],
|
|
||||||
saml.AuthnContextClassRef)
|
|
||||||
assert isinstance(new_context.authn_context_decl_ref[0],
|
|
||||||
saml.AuthnContextDeclRef)
|
|
||||||
assert new_context.comparison == "exact"
|
|
||||||
|
|
||||||
|
|
||||||
class TestAuthnRequest:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.ar = samlp.AuthnRequest()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for AuthnRequest accessors"""
|
|
||||||
self.ar.id = "request id"
|
|
||||||
self.ar.version = saml2.VERSION
|
|
||||||
self.ar.issue_instant = "2007-09-14T01:05:02Z"
|
|
||||||
self.ar.destination = "http://www.example.com/Destination"
|
|
||||||
self.ar.consent = saml.CONSENT_UNSPECIFIED
|
|
||||||
self.ar.issuer = saml.Issuer()
|
|
||||||
self.ar.signature = ds.get_empty_signature()
|
|
||||||
self.ar.extensions = samlp.Extensions()
|
|
||||||
|
|
||||||
self.ar.subject = saml.Subject()
|
|
||||||
self.ar.name_id_policy = samlp.NameIDPolicy()
|
|
||||||
self.ar.conditions = saml.Conditions()
|
|
||||||
self.ar.requested_authn_context = samlp.RequestedAuthnContext()
|
|
||||||
self.ar.scoping = samlp.Scoping()
|
|
||||||
self.ar.force_authn = 'true'
|
|
||||||
self.ar.is_passive = 'true'
|
|
||||||
self.ar.assertion_consumer_service_index = "1"
|
|
||||||
self.ar.assertion_consumer_service_url = "http://www.example.com/acs"
|
|
||||||
self.ar.protocol_binding = saml2.BINDING_HTTP_POST
|
|
||||||
self.ar.assertion_consuming_service_index = "2"
|
|
||||||
self.ar.provider_name = "provider name"
|
|
||||||
|
|
||||||
new_ar = samlp.authn_request_from_string(self.ar.to_string())
|
|
||||||
assert new_ar.id == "request id"
|
|
||||||
assert new_ar.version == saml2.VERSION
|
|
||||||
assert new_ar.issue_instant == "2007-09-14T01:05:02Z"
|
|
||||||
assert new_ar.destination == "http://www.example.com/Destination"
|
|
||||||
assert new_ar.consent == saml.CONSENT_UNSPECIFIED
|
|
||||||
assert isinstance(new_ar.issuer, saml.Issuer)
|
|
||||||
assert isinstance(new_ar.signature, ds.Signature)
|
|
||||||
assert isinstance(new_ar.extensions, samlp.Extensions)
|
|
||||||
|
|
||||||
assert isinstance(new_ar.subject, saml.Subject)
|
|
||||||
assert isinstance(new_ar.name_id_policy, samlp.NameIDPolicy)
|
|
||||||
assert isinstance(new_ar.conditions, saml.Conditions)
|
|
||||||
assert isinstance(new_ar.requested_authn_context,
|
|
||||||
samlp.RequestedAuthnContext)
|
|
||||||
assert isinstance(new_ar.scoping, samlp.Scoping)
|
|
||||||
assert new_ar.force_authn == 'true'
|
|
||||||
assert new_ar.is_passive == 'true'
|
|
||||||
assert new_ar.assertion_consumer_service_index == '1'
|
|
||||||
assert new_ar.assertion_consumer_service_url == \
|
|
||||||
'http://www.example.com/acs'
|
|
||||||
assert new_ar.protocol_binding == saml2.BINDING_HTTP_POST
|
|
||||||
assert new_ar.assertion_consuming_service_index == '2'
|
|
||||||
assert new_ar.provider_name == "provider name"
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test for authn_request_from_string() using test data"""
|
|
||||||
new_ar = samlp.authn_request_from_string(samlp_data.TEST_AUTHN_REQUEST)
|
|
||||||
assert new_ar.id == "request id"
|
|
||||||
assert new_ar.version == saml2.VERSION
|
|
||||||
assert new_ar.issue_instant == "2007-09-14T01:05:02Z"
|
|
||||||
assert new_ar.destination == "http://www.example.com/Destination"
|
|
||||||
assert new_ar.consent == saml.CONSENT_UNSPECIFIED
|
|
||||||
assert isinstance(new_ar.issuer, saml.Issuer)
|
|
||||||
assert isinstance(new_ar.signature, ds.Signature)
|
|
||||||
assert isinstance(new_ar.extensions, samlp.Extensions)
|
|
||||||
|
|
||||||
assert isinstance(new_ar.subject, saml.Subject)
|
|
||||||
assert isinstance(new_ar.name_id_policy, samlp.NameIDPolicy)
|
|
||||||
assert isinstance(new_ar.conditions, saml.Conditions)
|
|
||||||
assert isinstance(new_ar.requested_authn_context,
|
|
||||||
samlp.RequestedAuthnContext)
|
|
||||||
assert isinstance(new_ar.scoping, samlp.Scoping)
|
|
||||||
assert new_ar.force_authn == 'true'
|
|
||||||
assert new_ar.is_passive == 'true'
|
|
||||||
assert new_ar.assertion_consumer_service_index == '1'
|
|
||||||
assert new_ar.assertion_consumer_service_url == \
|
|
||||||
'http://www.example.com/acs'
|
|
||||||
assert new_ar.protocol_binding == saml2.BINDING_HTTP_POST
|
|
||||||
assert new_ar.assertion_consuming_service_index == '2'
|
|
||||||
assert new_ar.provider_name == "provider name"
|
|
||||||
|
|
||||||
|
|
||||||
class TestLogoutRequest:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.lr = samlp.LogoutRequest()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for LogoutRequest accessors"""
|
|
||||||
self.lr.id = "request id"
|
|
||||||
self.lr.version = saml2.VERSION
|
|
||||||
self.lr.issue_instant = "2007-09-14T01:05:02Z"
|
|
||||||
self.lr.destination = "http://www.example.com/Destination"
|
|
||||||
self.lr.consent = saml.CONSENT_UNSPECIFIED
|
|
||||||
self.lr.issuer = saml.Issuer()
|
|
||||||
self.lr.signature = ds.get_empty_signature()
|
|
||||||
self.lr.extensions = samlp.Extensions()
|
|
||||||
|
|
||||||
self.lr.not_on_or_after = "2007-10-14T01:05:02Z"
|
|
||||||
self.lr.reason = "http://www.example.com/Reason"
|
|
||||||
self.lr.base_id = saml.BaseID()
|
|
||||||
self.lr.name_id = saml.NameID()
|
|
||||||
self.lr.encrypted_id = saml.EncryptedID()
|
|
||||||
self.lr.session_index = samlp.SessionIndex()
|
|
||||||
|
|
||||||
new_lr = samlp.logout_request_from_string(self.lr.to_string())
|
|
||||||
assert new_lr.id == "request id"
|
|
||||||
assert new_lr.version == saml2.VERSION
|
|
||||||
assert new_lr.issue_instant == "2007-09-14T01:05:02Z"
|
|
||||||
assert new_lr.destination == "http://www.example.com/Destination"
|
|
||||||
assert new_lr.consent == saml.CONSENT_UNSPECIFIED
|
|
||||||
assert isinstance(new_lr.issuer, saml.Issuer)
|
|
||||||
assert isinstance(new_lr.signature, ds.Signature)
|
|
||||||
assert isinstance(new_lr.extensions, samlp.Extensions)
|
|
||||||
assert new_lr.not_on_or_after == "2007-10-14T01:05:02Z"
|
|
||||||
assert new_lr.reason == "http://www.example.com/Reason"
|
|
||||||
assert isinstance(new_lr.base_id, saml.BaseID)
|
|
||||||
assert isinstance(new_lr.name_id, saml.NameID)
|
|
||||||
assert isinstance(new_lr.encrypted_id, saml.EncryptedID)
|
|
||||||
assert isinstance(new_lr.session_index, samlp.SessionIndex)
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test for logout_request_from_string() using test data"""
|
|
||||||
new_lr = samlp.logout_request_from_string(samlp_data.TEST_LOGOUT_REQUEST)
|
|
||||||
assert new_lr.id == "request id"
|
|
||||||
assert new_lr.version == saml2.VERSION
|
|
||||||
assert new_lr.issue_instant == "2007-09-14T01:05:02Z"
|
|
||||||
assert new_lr.destination == "http://www.example.com/Destination"
|
|
||||||
assert new_lr.consent == saml.CONSENT_UNSPECIFIED
|
|
||||||
assert isinstance(new_lr.issuer, saml.Issuer)
|
|
||||||
assert isinstance(new_lr.signature, ds.Signature)
|
|
||||||
assert isinstance(new_lr.extensions, samlp.Extensions)
|
|
||||||
assert new_lr.not_on_or_after == "2007-10-14T01:05:02Z"
|
|
||||||
assert new_lr.reason == "http://www.example.com/Reason"
|
|
||||||
assert isinstance(new_lr.base_id, saml.BaseID)
|
|
||||||
assert isinstance(new_lr.name_id, saml.NameID)
|
|
||||||
assert isinstance(new_lr.encrypted_id, saml.EncryptedID)
|
|
||||||
assert isinstance(new_lr.session_index, samlp.SessionIndex)
|
|
||||||
assert new_lr.session_index.text.strip() == "session index"
|
|
||||||
|
|
||||||
|
|
||||||
class TestLogoutResponse:
|
|
||||||
|
|
||||||
def setup_class(self):
|
|
||||||
self.lr = samlp.LogoutResponse()
|
|
||||||
|
|
||||||
def testAccessors(self):
|
|
||||||
"""Test for LogoutResponse accessors"""
|
|
||||||
self.lr.id = "response id"
|
|
||||||
self.lr.in_response_to = "request id"
|
|
||||||
self.lr.version = saml2.VERSION
|
|
||||||
self.lr.issue_instant = "2007-09-14T01:05:02Z"
|
|
||||||
self.lr.destination = "http://www.example.com/Destination"
|
|
||||||
self.lr.consent = saml.CONSENT_UNSPECIFIED
|
|
||||||
self.lr.issuer = saml.Issuer()
|
|
||||||
self.lr.signature = ds.get_empty_signature()
|
|
||||||
self.lr.extensions = samlp.Extensions()
|
|
||||||
self.lr.status = samlp.Status()
|
|
||||||
|
|
||||||
new_lr = samlp.logout_response_from_string(self.lr.to_string())
|
|
||||||
assert new_lr.id == "response id"
|
|
||||||
assert new_lr.in_response_to == "request id"
|
|
||||||
assert new_lr.version == saml2.VERSION
|
|
||||||
assert new_lr.issue_instant == "2007-09-14T01:05:02Z"
|
|
||||||
assert new_lr.destination == "http://www.example.com/Destination"
|
|
||||||
assert new_lr.consent == saml.CONSENT_UNSPECIFIED
|
|
||||||
assert isinstance(new_lr.issuer, saml.Issuer)
|
|
||||||
assert isinstance(new_lr.signature, ds.Signature)
|
|
||||||
assert isinstance(new_lr.extensions, samlp.Extensions)
|
|
||||||
assert isinstance(new_lr.status, samlp.Status)
|
|
||||||
|
|
||||||
def testUsingTestData(self):
|
|
||||||
"""Test for logout_response_from_string() using test data"""
|
|
||||||
new_lr = samlp.logout_response_from_string(
|
|
||||||
samlp_data.TEST_LOGOUT_RESPONSE)
|
|
||||||
assert new_lr.id == "response id"
|
|
||||||
assert new_lr.in_response_to == "request id"
|
|
||||||
assert new_lr.version == saml2.VERSION
|
|
||||||
assert new_lr.issue_instant == "2007-09-14T01:05:02Z"
|
|
||||||
assert new_lr.destination == "http://www.example.com/Destination"
|
|
||||||
assert new_lr.consent == saml.CONSENT_UNSPECIFIED
|
|
||||||
assert isinstance(new_lr.issuer, saml.Issuer)
|
|
||||||
assert isinstance(new_lr.signature, ds.Signature)
|
|
||||||
assert isinstance(new_lr.extensions, samlp.Extensions)
|
|
||||||
assert isinstance(new_lr.status, samlp.Status)
|
|
||||||
|
|
||||||
@@ -1,325 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
from saml2.server import Server
|
|
||||||
from saml2 import server
|
|
||||||
from saml2 import samlp, saml, client, utils
|
|
||||||
from saml2.utils import make_instance, OtherError
|
|
||||||
from saml2.utils import do_attribute_statement
|
|
||||||
from py.test import raises
|
|
||||||
import shelve
|
|
||||||
import re
|
|
||||||
|
|
||||||
def _eq(l1,l2):
|
|
||||||
return set(l1) == set(l2)
|
|
||||||
|
|
||||||
class TestServer():
|
|
||||||
def setup_class(self):
|
|
||||||
self.server = Server("tests/idp.config")
|
|
||||||
|
|
||||||
def test_issuer(self):
|
|
||||||
issuer = make_instance( saml.Issuer, self.server.issuer())
|
|
||||||
assert isinstance(issuer, saml.Issuer)
|
|
||||||
assert _eq(issuer.keyswv(), ["text","format"])
|
|
||||||
assert issuer.format == saml.NAMEID_FORMAT_ENTITY
|
|
||||||
assert issuer.text == self.server.conf["entityid"]
|
|
||||||
|
|
||||||
|
|
||||||
def test_assertion(self):
|
|
||||||
tmp = utils.kd_assertion(
|
|
||||||
subject= utils.kd_subject("_aaa",
|
|
||||||
name_id=saml.NAMEID_FORMAT_TRANSIENT),
|
|
||||||
attribute_statement = utils.kd_attribute_statement(
|
|
||||||
attribute=[
|
|
||||||
utils.kd_attribute(attribute_value="Derek",
|
|
||||||
friendly_name="givenName"),
|
|
||||||
utils.kd_attribute(attribute_value="Jeter",
|
|
||||||
friendly_name="surName"),
|
|
||||||
]),
|
|
||||||
issuer=self.server.issuer(),
|
|
||||||
)
|
|
||||||
|
|
||||||
assertion = make_instance(saml.Assertion, tmp)
|
|
||||||
assert _eq(assertion.keyswv(),['attribute_statement', 'issuer', 'id',
|
|
||||||
'subject', 'issue_instant', 'version'])
|
|
||||||
assert assertion.version == "2.0"
|
|
||||||
assert assertion.issuer.text == "urn:mace:example.com:saml:roland:idp"
|
|
||||||
#
|
|
||||||
assert len(assertion.attribute_statement) == 1
|
|
||||||
attribute_statement = assertion.attribute_statement[0]
|
|
||||||
assert len(attribute_statement.attribute) == 2
|
|
||||||
attr0 = attribute_statement.attribute[0]
|
|
||||||
attr1 = attribute_statement.attribute[1]
|
|
||||||
if attr0.attribute_value[0].text == "Derek":
|
|
||||||
assert attr0.friendly_name == "givenName"
|
|
||||||
assert attr1.friendly_name == "surName"
|
|
||||||
assert attr1.attribute_value[0].text == "Jeter"
|
|
||||||
else:
|
|
||||||
assert attr1.friendly_name == "givenName"
|
|
||||||
assert attr1.attribute_value[0].text == "Derek"
|
|
||||||
assert attr0.friendly_name == "surName"
|
|
||||||
assert attr0.attribute_value[0].text == "Jeter"
|
|
||||||
#
|
|
||||||
subject = assertion.subject
|
|
||||||
assert _eq(subject.keyswv(),["text", "name_id"])
|
|
||||||
assert subject.text == "_aaa"
|
|
||||||
assert subject.name_id.text == saml.NAMEID_FORMAT_TRANSIENT
|
|
||||||
|
|
||||||
def test_response(self):
|
|
||||||
tmp = utils.kd_response(
|
|
||||||
in_response_to="_012345",
|
|
||||||
destination="https:#www.example.com",
|
|
||||||
status=utils.kd_success_status(),
|
|
||||||
assertion=utils.kd_assertion(
|
|
||||||
subject = utils.kd_subject("_aaa",
|
|
||||||
name_id=saml.NAMEID_FORMAT_TRANSIENT),
|
|
||||||
attribute_statement = utils.kd_attribute_statement([
|
|
||||||
utils.kd_attribute(attribute_value="Derek",
|
|
||||||
friendly_name="givenName"),
|
|
||||||
utils.kd_attribute(attribute_value="Jeter",
|
|
||||||
friendly_name="surName"),
|
|
||||||
]),
|
|
||||||
issuer=self.server.issuer(),
|
|
||||||
),
|
|
||||||
issuer=self.server.issuer(),
|
|
||||||
)
|
|
||||||
|
|
||||||
response = make_instance(samlp.Response, tmp)
|
|
||||||
print response.keyswv()
|
|
||||||
assert _eq(response.keyswv(),['destination', 'assertion','status',
|
|
||||||
'in_response_to', 'issue_instant',
|
|
||||||
'version', 'issuer', 'id'])
|
|
||||||
assert response.version == "2.0"
|
|
||||||
assert response.issuer.text == "urn:mace:example.com:saml:roland:idp"
|
|
||||||
assert response.destination == "https:#www.example.com"
|
|
||||||
assert response.in_response_to == "_012345"
|
|
||||||
#
|
|
||||||
status = response.status
|
|
||||||
print status
|
|
||||||
assert status.status_code.value == samlp.STATUS_SUCCESS
|
|
||||||
|
|
||||||
def test_parse_faulty_request(self):
|
|
||||||
sc = client.Saml2Client({},None)
|
|
||||||
authn_request = sc.authn_request(
|
|
||||||
query_id = "1",
|
|
||||||
destination = "http://www.example.com",
|
|
||||||
service_url = "http://www.example.org",
|
|
||||||
spentityid = "urn:mace:example.com:saml:roland:sp",
|
|
||||||
my_name = "My real name",
|
|
||||||
)
|
|
||||||
|
|
||||||
intermed = utils.deflate_and_base64_encode(authn_request)
|
|
||||||
# should raise an error because faulty spentityid
|
|
||||||
raises(OtherError,self.server.parse_authn_request,intermed)
|
|
||||||
|
|
||||||
def test_parse_faulty_request_to_err_status(self):
|
|
||||||
sc = client.Saml2Client({},None)
|
|
||||||
authn_request = sc.authn_request(
|
|
||||||
query_id = "1",
|
|
||||||
destination = "http://www.example.com",
|
|
||||||
service_url = "http://www.example.org",
|
|
||||||
spentityid = "urn:mace:example.com:saml:roland:sp",
|
|
||||||
my_name = "My real name",
|
|
||||||
)
|
|
||||||
|
|
||||||
intermed = utils.deflate_and_base64_encode(authn_request)
|
|
||||||
try:
|
|
||||||
self.server.parse_authn_request(intermed)
|
|
||||||
status = None
|
|
||||||
except OtherError, oe:
|
|
||||||
print oe.args
|
|
||||||
status = utils.make_instance(samlp.Status,
|
|
||||||
utils.kd_status_from_exception(oe))
|
|
||||||
|
|
||||||
assert status
|
|
||||||
print status
|
|
||||||
assert _eq(status.keyswv(), ["status_code", "status_message"])
|
|
||||||
assert status.status_message.text == (
|
|
||||||
'ConsumerURL and return destination mismatch')
|
|
||||||
status_code = status.status_code
|
|
||||||
assert _eq(status_code.keyswv(), ["status_code","value"])
|
|
||||||
assert status_code.value == samlp.STATUS_RESPONDER
|
|
||||||
assert status_code.status_code.value == samlp.STATUS_UNKNOWN_PRINCIPAL
|
|
||||||
|
|
||||||
def test_parse_ok_request(self):
|
|
||||||
sc = client.Saml2Client({},None)
|
|
||||||
authn_request = sc.authn_request(
|
|
||||||
query_id = "1",
|
|
||||||
destination = "http://www.example.com",
|
|
||||||
service_url = "http://localhost:8087/",
|
|
||||||
spentityid = "urn:mace:example.com:saml:roland:sp",
|
|
||||||
my_name = "My real name",
|
|
||||||
)
|
|
||||||
|
|
||||||
print authn_request
|
|
||||||
intermed = utils.deflate_and_base64_encode(authn_request)
|
|
||||||
response = self.server.parse_authn_request(intermed)
|
|
||||||
|
|
||||||
assert response["consumer_url"] == "http://localhost:8087/"
|
|
||||||
assert response["id"] == "1"
|
|
||||||
name_id_policy = response["request"].name_id_policy
|
|
||||||
assert _eq(name_id_policy.keyswv(), ["format", "allow_create"])
|
|
||||||
assert name_id_policy.format == saml.NAMEID_FORMAT_TRANSIENT
|
|
||||||
assert response["sp_entityid"] == "urn:mace:example.com:saml:roland:sp"
|
|
||||||
|
|
||||||
def test_sso_response(self):
|
|
||||||
resp = self.server.do_sso_response(
|
|
||||||
"http://localhost:8087/", # consumer_url
|
|
||||||
"12", # in_response_to
|
|
||||||
"urn:mace:example.com:saml:roland:sp", # sp_entity_id
|
|
||||||
{("urn:oid:1.3.6.1.4.1.5923.1.1.1.7",
|
|
||||||
"urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
|
|
||||||
"eduPersonEntitlement"):"Jeter"}
|
|
||||||
)
|
|
||||||
|
|
||||||
print resp.keyswv()
|
|
||||||
assert _eq(resp.keyswv(),['status', 'destination', 'assertion',
|
|
||||||
'in_response_to', 'issue_instant',
|
|
||||||
'version', 'id', 'issuer'])
|
|
||||||
assert resp.destination == "http://localhost:8087/"
|
|
||||||
assert resp.in_response_to == "12"
|
|
||||||
assert resp.status
|
|
||||||
assert resp.status.status_code.value == samlp.STATUS_SUCCESS
|
|
||||||
assert resp.assertion
|
|
||||||
assert len(resp.assertion) == 1
|
|
||||||
assertion = resp.assertion[0]
|
|
||||||
assert len(assertion.authn_statement) == 1
|
|
||||||
assert assertion.conditions
|
|
||||||
assert len(assertion.attribute_statement) == 1
|
|
||||||
assert assertion.subject
|
|
||||||
assert assertion.subject.name_id
|
|
||||||
assert len(assertion.subject.subject_confirmation) == 1
|
|
||||||
confirmation = assertion.subject.subject_confirmation[0]
|
|
||||||
print confirmation.keyswv()
|
|
||||||
print confirmation.subject_confirmation_data
|
|
||||||
assert confirmation.subject_confirmation_data.in_response_to == "12"
|
|
||||||
|
|
||||||
def test_persistence_0(self):
|
|
||||||
pid1 = self.server.persistent_id(
|
|
||||||
"urn:mace:example.com:saml:roland:sp", "jeter")
|
|
||||||
|
|
||||||
pid2 = self.server.persistent_id(
|
|
||||||
"urn:mace:example.com:saml:roland:sp", "jeter")
|
|
||||||
|
|
||||||
print pid1, pid2
|
|
||||||
assert pid1 == pid2
|
|
||||||
|
|
||||||
def test_filter_ava_0(self):
|
|
||||||
ava = { "givenName": ["Derek"], "surName": ["Jeter"],
|
|
||||||
"mail": ["derek@nyy.mlb.com"]}
|
|
||||||
|
|
||||||
# No restrictions apply
|
|
||||||
ava = self.server.filter_ava(ava,
|
|
||||||
"urn:mace:example.com:saml:roland:sp",
|
|
||||||
[], [], "idp")
|
|
||||||
|
|
||||||
assert _eq(ava.keys(), ["givenName", "surName", "mail"])
|
|
||||||
assert ava["givenName"] == ["Derek"]
|
|
||||||
assert ava["surName"] == ["Jeter"]
|
|
||||||
assert ava["mail"] == ["derek@nyy.mlb.com"]
|
|
||||||
|
|
||||||
|
|
||||||
def test_filter_ava_1(self):
|
|
||||||
""" No mail address returned """
|
|
||||||
self.server.conf["service"]["idp"]["assertions"][
|
|
||||||
"urn:mace:example.com:saml:roland:sp"] = {
|
|
||||||
"lifetime": {"minutes": 5},
|
|
||||||
"attribute_restrictions":{
|
|
||||||
"givenName": None,
|
|
||||||
"surName": None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
print self.server.conf["service"]["idp"]["assertions"]
|
|
||||||
|
|
||||||
ava = { "givenName": ["Derek"], "surName": ["Jeter"],
|
|
||||||
"mail": ["derek@nyy.mlb.com"]}
|
|
||||||
|
|
||||||
# No restrictions apply
|
|
||||||
ava = self.server.filter_ava(ava,
|
|
||||||
"urn:mace:example.com:saml:roland:sp",
|
|
||||||
[], [], "idp")
|
|
||||||
|
|
||||||
assert _eq(ava.keys(), ["givenName", "surName"])
|
|
||||||
assert ava["givenName"] == ["Derek"]
|
|
||||||
assert ava["surName"] == ["Jeter"]
|
|
||||||
|
|
||||||
def test_filter_ava_2(self):
|
|
||||||
""" Only mail returned """
|
|
||||||
self.server.conf["service"]["idp"]["assertions"][
|
|
||||||
"urn:mace:example.com:saml:roland:sp"] = {
|
|
||||||
"lifetime": {"minutes": 5},
|
|
||||||
"attribute_restrictions":{
|
|
||||||
"mail": None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
print self.server.conf["service"]["idp"]["assertions"]
|
|
||||||
|
|
||||||
ava = { "givenName": ["Derek"], "surName": ["Jeter"],
|
|
||||||
"mail": ["derek@nyy.mlb.com"]}
|
|
||||||
|
|
||||||
# No restrictions apply
|
|
||||||
ava = self.server.filter_ava(ava,
|
|
||||||
"urn:mace:example.com:saml:roland:sp",
|
|
||||||
[], [], "idp")
|
|
||||||
|
|
||||||
assert _eq(ava.keys(), ["mail"])
|
|
||||||
assert ava["mail"] == ["derek@nyy.mlb.com"]
|
|
||||||
|
|
||||||
def test_filter_ava_3(self):
|
|
||||||
""" Only example.com mail addresses returned """
|
|
||||||
self.server.conf["service"]["idp"]["assertions"][
|
|
||||||
"urn:mace:example.com:saml:roland:sp"] = {
|
|
||||||
"lifetime": {"minutes": 5},
|
|
||||||
"attribute_restrictions":{
|
|
||||||
"mail": [re.compile(".*@example\.com$")],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
print self.server.conf["service"]["idp"]["assertions"]
|
|
||||||
|
|
||||||
ava = { "givenName": ["Derek"], "surName": ["Jeter"],
|
|
||||||
"mail": ["derek@nyy.mlb.com", "dj@example.com"]}
|
|
||||||
|
|
||||||
# No restrictions apply
|
|
||||||
ava = self.server.filter_ava(ava,
|
|
||||||
"urn:mace:example.com:saml:roland:sp",
|
|
||||||
[], [], "idp")
|
|
||||||
|
|
||||||
assert _eq(ava.keys(), ["mail"])
|
|
||||||
assert ava["mail"] == ["dj@example.com"]
|
|
||||||
|
|
||||||
def test_authn_response_0(self):
|
|
||||||
# reset
|
|
||||||
del self.server.conf["service"]["idp"]["assertions"][
|
|
||||||
"urn:mace:example.com:saml:roland:sp"]
|
|
||||||
|
|
||||||
ava = { "givenName": ["Derek"], "surName": ["Jeter"],
|
|
||||||
"mail": ["derek@nyy.mlb.com"]}
|
|
||||||
|
|
||||||
resp_str = self.server.authn_response(ava,
|
|
||||||
"1", "http://local:8087/",
|
|
||||||
"urn:mace:example.com:saml:roland:sp",
|
|
||||||
utils.make_instance(samlp.NameIDPolicy,
|
|
||||||
utils.kd_name_id_policy(
|
|
||||||
format=saml.NAMEID_FORMAT_TRANSIENT,
|
|
||||||
allow_create="true")),
|
|
||||||
"foba0001@example.com")
|
|
||||||
|
|
||||||
response = samlp.response_from_string("\n".join(resp_str))
|
|
||||||
print response.keyswv()
|
|
||||||
assert _eq(response.keyswv(),['status', 'destination', 'assertion',
|
|
||||||
'in_response_to', 'issue_instant', 'version',
|
|
||||||
'issuer', 'id'])
|
|
||||||
print response.assertion[0].keyswv()
|
|
||||||
assert len(response.assertion) == 1
|
|
||||||
assert _eq(response.assertion[0].keyswv(), ['authn_statement',
|
|
||||||
'attribute_statement', 'subject', 'issue_instant',
|
|
||||||
'version', 'conditions', 'id'])
|
|
||||||
assertion = response.assertion[0]
|
|
||||||
assert len(assertion.attribute_statement) == 1
|
|
||||||
astate = assertion.attribute_statement[0]
|
|
||||||
print astate
|
|
||||||
assert len(astate.attribute) == 3
|
|
||||||
|
|
||||||
@@ -7,30 +7,31 @@ from saml2 import saml
|
|||||||
import xmldsig as ds
|
import xmldsig as ds
|
||||||
from py.test import raises
|
from py.test import raises
|
||||||
|
|
||||||
SIGNED = "tests/saml_signed.xml"
|
SIGNED = "saml_signed.xml"
|
||||||
UNSIGNED = "tests/saml_unsigned.xml"
|
UNSIGNED = "saml_unsigned.xml"
|
||||||
FALSE_SIGNED = "tests/saml_false_signed.xml"
|
FALSE_SIGNED = "saml_false_signed.xml"
|
||||||
XMLSEC = "/opt/local/bin/xmlsec1"
|
XMLSEC_BINARY = "/usr/local/bin/xmlsec1"
|
||||||
#PUB_KEY = "tests/test.pem"
|
#PUB_KEY = "test.pem"
|
||||||
PRIV_KEY = "tests/test.key"
|
PRIV_KEY = "test.key"
|
||||||
|
|
||||||
def _eq(l1,l2):
|
def _eq(l1,l2):
|
||||||
return set(l1) == set(l2)
|
return set(l1) == set(l2)
|
||||||
|
|
||||||
def test_verify_1():
|
def test_verify_1():
|
||||||
xml_response = open(SIGNED).read()
|
xml_response = open(SIGNED).read()
|
||||||
response = sigver.correctly_signed_response(xml_response)
|
response = sigver.correctly_signed_response(xml_response, XMLSEC_BINARY)
|
||||||
assert response
|
assert response
|
||||||
|
|
||||||
def test_non_verify_1():
|
def test_non_verify_1():
|
||||||
""" unsigned is OK if not good """
|
""" unsigned is OK if not good """
|
||||||
xml_response = open(UNSIGNED).read()
|
xml_response = open(UNSIGNED).read()
|
||||||
response = sigver.correctly_signed_response(xml_response)
|
response = sigver.correctly_signed_response(xml_response, XMLSEC_BINARY)
|
||||||
assert response
|
assert response
|
||||||
|
|
||||||
def test_non_verify_2():
|
def test_non_verify_2():
|
||||||
xml_response = open(FALSE_SIGNED).read()
|
xml_response = open(FALSE_SIGNED).read()
|
||||||
raises(sigver.SignatureError,sigver.correctly_signed_response,xml_response)
|
raises(sigver.SignatureError,sigver.correctly_signed_response,
|
||||||
|
xml_response, XMLSEC_BINARY)
|
||||||
|
|
||||||
SIGNED_VALUE= """Y88SEXrU3emeoaTgEqUKYAvDtWiLpPMx1sClw0GJV98O6A5QRvB14vNs8xnXNFFZ
|
SIGNED_VALUE= """Y88SEXrU3emeoaTgEqUKYAvDtWiLpPMx1sClw0GJV98O6A5QRvB14vNs8xnXNFFZ
|
||||||
XVjksKECcqmf10k/2C3oJfaEOaM4w0DgVLXeuJU08irXfdHcoe1g3276F1If1Kh7
|
XVjksKECcqmf10k/2C3oJfaEOaM4w0DgVLXeuJU08irXfdHcoe1g3276F1If1Kh7
|
||||||
@@ -58,7 +59,7 @@ def test_sign():
|
|||||||
})
|
})
|
||||||
|
|
||||||
print ass
|
print ass
|
||||||
sign_ass = sigver.sign_assertion_using_xmlsec("%s" % ass, XMLSEC,
|
sign_ass = sigver.sign_assertion_using_xmlsec("%s" % ass, XMLSEC_BINARY,
|
||||||
key_file=PRIV_KEY)
|
key_file=PRIV_KEY)
|
||||||
sass = saml.assertion_from_string(sign_ass)
|
sass = saml.assertion_from_string(sign_ass)
|
||||||
print sass
|
print sass
|
||||||
|
|||||||
@@ -324,7 +324,7 @@ def test_filter_attribute_value_assertions_2():
|
|||||||
assert ava["givenName"] == ["Roland"]
|
assert ava["givenName"] == ["Roland"]
|
||||||
|
|
||||||
def test_parse_attribute_map():
|
def test_parse_attribute_map():
|
||||||
(forward, backward) = utils.parse_attribute_map(["tests/attribute.map"])
|
(forward, backward) = utils.parse_attribute_map(["attribute.map"])
|
||||||
|
|
||||||
assert _eq(forward.keys(), backward.values())
|
assert _eq(forward.keys(), backward.values())
|
||||||
assert _eq(forward.values(), backward.keys())
|
assert _eq(forward.values(), backward.keys())
|
||||||
@@ -340,7 +340,7 @@ def test_parse_attribute_map():
|
|||||||
|
|
||||||
|
|
||||||
def test_identity_attribute_0():
|
def test_identity_attribute_0():
|
||||||
(forward, backward) = utils.parse_attribute_map(["tests/attribute.map"])
|
(forward, backward) = utils.parse_attribute_map(["attribute.map"])
|
||||||
a = Attribute(name="urn:oid:2.5.4.4", name_format=NAME_FORMAT_URI,
|
a = Attribute(name="urn:oid:2.5.4.4", name_format=NAME_FORMAT_URI,
|
||||||
friendly_name="surName")
|
friendly_name="surName")
|
||||||
|
|
||||||
@@ -348,14 +348,14 @@ def test_identity_attribute_0():
|
|||||||
assert utils.identity_attribute("friendly",a,forward) == "surName"
|
assert utils.identity_attribute("friendly",a,forward) == "surName"
|
||||||
|
|
||||||
def test_identity_attribute_1():
|
def test_identity_attribute_1():
|
||||||
(forward, backward) = utils.parse_attribute_map(["tests/attribute.map"])
|
(forward, backward) = utils.parse_attribute_map(["attribute.map"])
|
||||||
a = Attribute(name="urn:oid:2.5.4.4")
|
a = Attribute(name="urn:oid:2.5.4.4")
|
||||||
|
|
||||||
assert utils.identity_attribute("name",a,forward) == "urn:oid:2.5.4.4"
|
assert utils.identity_attribute("name",a,forward) == "urn:oid:2.5.4.4"
|
||||||
assert utils.identity_attribute("friendly",a,forward) == "surName"
|
assert utils.identity_attribute("friendly",a,forward) == "surName"
|
||||||
|
|
||||||
def test_identity_attribute_2():
|
def test_identity_attribute_2():
|
||||||
(forward, backward) = utils.parse_attribute_map(["tests/attribute.map"])
|
(forward, backward) = utils.parse_attribute_map(["attribute.map"])
|
||||||
a = Attribute(name="urn:oid:2.5.4.5")
|
a = Attribute(name="urn:oid:2.5.4.5")
|
||||||
|
|
||||||
assert utils.identity_attribute("name",a,forward) == "urn:oid:2.5.4.5"
|
assert utils.identity_attribute("name",a,forward) == "urn:oid:2.5.4.5"
|
||||||
@@ -512,7 +512,7 @@ def _surName(a):
|
|||||||
assert a["attribute_value"] == [{"text":"Jeter"}]
|
assert a["attribute_value"] == [{"text":"Jeter"}]
|
||||||
|
|
||||||
def test_ava_to_attributes():
|
def test_ava_to_attributes():
|
||||||
(forward, backward) = utils.parse_attribute_map(["tests/attribute.map"])
|
(forward, backward) = utils.parse_attribute_map(["attribute.map"])
|
||||||
attrs = utils.ava_to_attributes(AVA[0], backward)
|
attrs = utils.ava_to_attributes(AVA[0], backward)
|
||||||
|
|
||||||
assert len(attrs) == 2
|
assert len(attrs) == 2
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?xml version='1.0' encoding='UTF-8'?>
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
<ns0:EntitiesDescriptor
|
<ns0:EntitiesDescriptor
|
||||||
name="urn:mace:example.com:votest"
|
name="urn:mace:example.com:votest"
|
||||||
validUntil="2009-11-28T09:10:09Z"
|
validUntil="2010-11-28T09:10:09Z"
|
||||||
xmlns:ns0="urn:oasis:names:tc:SAML:2.0:metadata">
|
xmlns:ns0="urn:oasis:names:tc:SAML:2.0:metadata">
|
||||||
<ns0:EntityDescriptor
|
<ns0:EntityDescriptor
|
||||||
entityID="urn:mace:example.com:it:tek">
|
entityID="urn:mace:example.com:it:tek">
|
||||||
|
|||||||
Reference in New Issue
Block a user