updated tests

This commit is contained in:
Roland Hedberg
2010-03-05 13:42:40 +01:00
parent 4e3e40d7a0
commit f8473c4db0

View File

@@ -5,6 +5,7 @@ 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.server import Server
XML_RESPONSE_FILE = "tests/saml_signed.xml" XML_RESPONSE_FILE = "tests/saml_signed.xml"
XML_RESPONSE_FILE2 = "tests/saml2_response.xml" XML_RESPONSE_FILE2 = "tests/saml2_response.xml"
@@ -52,32 +53,52 @@ def ava(attribute_statement):
REQ1 = """<?xml version='1.0' encoding='UTF-8'?> REQ1 = """<?xml version='1.0' encoding='UTF-8'?>
<ns0:AttributeQuery Destination="https://idp.example.com/idp/" ID="1" IssueInstant="%s" Version="2.0" xmlns:ns0="urn:oasis:names:tc:SAML:2.0:protocol"><ns1:Issuer xmlns:ns1="urn:oasis:names:tc:SAML:2.0:assertion">http://vo.example.com/sp1</ns1:Issuer><ns1:Subject xmlns:ns1="urn:oasis:names:tc:SAML:2.0:assertion"><ns1:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent">E8042FB4-4D5B-48C3-8E14-8EDD852790DD</ns1:NameID></ns1:Subject></ns0:AttributeQuery>""" <ns0:AttributeQuery Destination="https://idp.example.com/idp/" ID="1" IssueInstant="%s" Version="2.0" xmlns:ns0="urn:oasis:names:tc:SAML:2.0:protocol"><ns1:Issuer xmlns:ns1="urn:oasis:names:tc:SAML:2.0:assertion">http://vo.example.com/sp1</ns1:Issuer><ns1:Subject xmlns:ns1="urn:oasis:names:tc:SAML:2.0:assertion"><ns1:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent">E8042FB4-4D5B-48C3-8E14-8EDD852790DD</ns1:NameID></ns1:Subject></ns0:AttributeQuery>"""
class TestClient: class TestClient:
def setup_class(self): def setup_class(self):
server = Server("idp.config")
self._resp_ = server.do_sso_response(
"http://lingon.catalogix.se: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"}
)
conf = config.Config() conf = config.Config()
conf.load_file("tests/server.config") try:
conf.load_file("tests/server.config")
except IOError:
conf.load_file("server.config")
self.client = Saml2Client({},conf) self.client = Saml2Client({},conf)
def test_verify_1(self): def test_verify_1(self):
xml_response = open(XML_RESPONSE_FILE).read() xml_response = ("%s" % (self._resp_,)).split("\n")[1]
outstanding = {"12": "http://localhost:8088/sso"}
session_info = self.client.verify_response(xml_response, session_info = self.client.verify_response(xml_response,
"xenosmilus.umdc.umu.se", "urn:mace:example.com:saml:roland:sp",
outstanding=outstanding,
decode=False) decode=False)
assert session_info["ava"] == { del session_info["name_id"]
'__userid': '_cddc88563d433f556d4cc70c3162deabddea3b5019', del session_info["not_on_or_after"]
'eduPersonAffiliation': ['member', 'student'], del session_info["ava"]["__userid"]
'uid': ['student']} print session_info
assert session_info == {'session_id': '12',
'came_from': 'http://localhost:8088/sso',
'ava': {'eduPersonEntitlement': ['Jeter'] },
'issuer': 'urn:mace:example.com:saml:roland:idp'}
def test_parse_1(self): def test_parse_1(self):
xml_response = open(XML_RESPONSE_FILE).read() xml_response = ("%s" % (self._resp_,)).split("\n")[1]
response = samlp.response_from_string(xml_response) response = correctly_signed_response(decoded_xml,
self.config["xmlsec_binary"], log=log)
outstanding = {"12": "http://localhost:8088/sso"}
session_info = self.client.do_response(response, session_info = self.client.do_response(response,
"xenosmilus.umdc.umu.se") "urn:mace:example.com:saml:roland:sp",
assert session_info["ava"] == { outstanding=outstanding)
'eduPersonAffiliation': ['member', 'student'], assert session_info["ava"]["eduPersonEntitlement"] == ["Jeter"]
'uid': ['student']}
assert session_info["name_id"] == "_cddc88563d433f556d4cc70c3162deabddea3b5019"
def test_parse_2(self): def test_parse_2(self):
xml_response = open(XML_RESPONSE_FILE2).read() xml_response = open(XML_RESPONSE_FILE2).read()