Fixed a couple of tests

This commit is contained in:
Roland Hedberg
2014-10-20 10:29:31 +02:00
parent 9af755597d
commit 6a85250075
4 changed files with 67 additions and 59 deletions

View File

@@ -215,7 +215,7 @@ class TestSAMLBase:
attr = Attribute() attr = Attribute()
saml2.make_vals(ava, AttributeValue, attr, prop="attribute_value") saml2.make_vals(ava, AttributeValue, attr, prop="attribute_value")
assert attr.keyswv() == ["attribute_value"] assert attr.keyswv() == ["name_format", "attribute_value"]
assert len(attr.attribute_value) == 4 assert len(attr.attribute_value) == 4
def test_to_string_nspair(self): def test_to_string_nspair(self):
@@ -1211,3 +1211,7 @@ class TestAssertion:
"""Test assertion_from_string() using test data""" """Test assertion_from_string() using test data"""
# TODO # TODO
pass pass
if __name__ == "__main__":
t = TestSAMLBase()
t.test_make_vals_multi_dict()

View File

@@ -137,10 +137,10 @@ def test_attribute_statement():
assert statement.keyswv() == ["attribute"] assert statement.keyswv() == ["attribute"]
assert len(statement.attribute) == 2 assert len(statement.attribute) == 2
attr0 = statement.attribute[0] attr0 = statement.attribute[0]
assert _eq(attr0.keyswv(), ["name", "attribute_value"]) assert _eq(attr0.keyswv(), ["name", "attribute_value", "name_format"])
assert len(attr0.attribute_value) == 1 assert len(attr0.attribute_value) == 1
attr1 = statement.attribute[1] attr1 = statement.attribute[1]
assert _eq(attr1.keyswv(), ["name", "attribute_value"]) assert _eq(attr1.keyswv(), ["name", "attribute_value", "name_format"])
assert len(attr1.attribute_value) == 1 assert len(attr1.attribute_value) == 1
if attr0.name == "givenName": if attr0.name == "givenName":
assert attr0.attribute_value[0].text == "Derek" assert attr0.attribute_value[0].text == "Derek"
@@ -222,7 +222,8 @@ def test_value_4():
saml.AttributeValue, text="Derek")], saml.AttributeValue, text="Derek")],
friendly_name="givenName") friendly_name="givenName")
assert _eq(attribute.keyswv(), ["friendly_name", "attribute_value"]) assert _eq(attribute.keyswv(), ["friendly_name", "attribute_value",
"name_format"])
assert attribute.friendly_name == "givenName" assert attribute.friendly_name == "givenName"
assert len(attribute.attribute_value) == 1 assert len(attribute.attribute_value) == 1
assert attribute.attribute_value[0].text == "Derek" assert attribute.attribute_value[0].text == "Derek"
@@ -234,7 +235,7 @@ def test_do_attribute_statement_0():
assert statement.keyswv() == ["attribute"] assert statement.keyswv() == ["attribute"]
assert len(statement.attribute) == 1 assert len(statement.attribute) == 1
attr0 = statement.attribute[0] attr0 = statement.attribute[0]
assert _eq(attr0.keyswv(), ["name", "attribute_value"]) assert _eq(attr0.keyswv(), ["name", "attribute_value", "name_format"])
assert attr0.name == "vo_attr" assert attr0.name == "vo_attr"
assert len(attr0.attribute_value) == 1 assert len(attr0.attribute_value) == 1
assert attr0.attribute_value[0].text == "foobar" assert attr0.attribute_value[0].text == "foobar"
@@ -248,9 +249,9 @@ def test_do_attribute_statement():
assert statement.keyswv() == ["attribute"] assert statement.keyswv() == ["attribute"]
assert len(statement.attribute) == 2 assert len(statement.attribute) == 2
attr0 = statement.attribute[0] attr0 = statement.attribute[0]
assert _eq(attr0.keyswv(), ["name", "attribute_value"]) assert _eq(attr0.keyswv(), ["name", "attribute_value", "name_format"])
attr1 = statement.attribute[1] attr1 = statement.attribute[1]
assert _eq(attr1.keyswv(), ["name", "attribute_value"]) assert _eq(attr1.keyswv(), ["name", "attribute_value", "name_format"])
if attr0.name == "givenName": if attr0.name == "givenName":
assert len(attr0.attribute_value) == 2 assert len(attr0.attribute_value) == 2
assert _eq([av.text for av in attr0.attribute_value], assert _eq([av.text for av in attr0.attribute_value],

View File

@@ -150,8 +150,11 @@ class TestAC():
# assert result == {'givenName': [], 'sn': [], 'title': []} # assert result == {'givenName': [], 'sn': [], 'title': []}
def test_to_local_name_from_basic(self): def test_to_local_name_from_basic(self):
attr = [saml.Attribute( attr = [
name="urn:mace:dir:attribute-def:eduPersonPrimaryOrgUnitDN")] saml.Attribute(
name="urn:mace:dir:attribute-def:eduPersonPrimaryOrgUnitDN",
name_format="urn:oasis:names:tc:SAML:2.0:attrname-format:basic")
]
lan = [attribute_converter.to_local_name(self.acs, a) for a in attr] lan = [attribute_converter.to_local_name(self.acs, a) for a in attr]
@@ -222,7 +225,7 @@ def test_schac():
if __name__ == "__main__": if __name__ == "__main__":
# t = TestAC() t = TestAC()
# t.setup_class() t.setup_class()
# t.test_mixed_attributes_1() t.test_to_local_name_from_basic()
test_schac() #test_schac()

View File

@@ -9,29 +9,30 @@ from s2repoze.plugins.sp import make_plugin
from saml2.server import Server from saml2.server import Server
ENV1 = {'SERVER_SOFTWARE': 'CherryPy/3.1.2 WSGI Server', ENV1 = {'SERVER_SOFTWARE': 'CherryPy/3.1.2 WSGI Server',
'SCRIPT_NAME': '', 'SCRIPT_NAME': '',
'ACTUAL_SERVER_PROTOCOL': 'HTTP/1.1', 'ACTUAL_SERVER_PROTOCOL': 'HTTP/1.1',
'REQUEST_METHOD': 'GET', 'REQUEST_METHOD': 'GET',
'PATH_INFO': '/krissms', 'PATH_INFO': '/krissms',
'SERVER_PROTOCOL': 'HTTP/1.1', 'SERVER_PROTOCOL': 'HTTP/1.1',
'QUERY_STRING': '', 'QUERY_STRING': '',
'REMOTE_ADDR': '127.0.0.1', 'REMOTE_ADDR': '127.0.0.1',
'HTTP_USER_AGENT': 'HTTP_USER_AGENT':
'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; en-us) ', 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; en-us) ',
'HTTP_CONNECTION': 'keep-alive', 'HTTP_CONNECTION': 'keep-alive',
'SERVER_NAME': 'lingon-catalogix-se-2.local', 'SERVER_NAME': 'lingon-catalogix-se-2.local',
'REMOTE_PORT': '57309', 'REMOTE_PORT': '57309',
'wsgi.url_scheme': 'http', 'wsgi.url_scheme': 'http',
'SERVER_PORT': '8087', 'SERVER_PORT': '8087',
'HTTP_HOST': '127.0.0.1:8087', 'HTTP_HOST': '127.0.0.1:8087',
'wsgi.multithread': True, 'wsgi.multithread': True,
'HTTP_ACCEPT': 'HTTP_ACCEPT':
'application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5', 'application/xml,application/xhtml+xml,text/html;q=0.9,'
'wsgi.version': (1, 0), 'text/plain;q=0.8,image/png,*/*;q=0.5',
'wsgi.run_once': False, 'wsgi.version': (1, 0),
'wsgi.multiprocess': False, 'wsgi.run_once': False,
'HTTP_ACCEPT_LANGUAGE': 'en-us', 'wsgi.multiprocess': False,
'HTTP_ACCEPT_ENCODING': 'gzip, deflate'} 'HTTP_ACCEPT_LANGUAGE': 'en-us',
'HTTP_ACCEPT_ENCODING': 'gzip, deflate'}
trans_name_policy = NameIDPolicy(format=NAMEID_FORMAT_TRANSIENT, trans_name_policy = NameIDPolicy(format=NAMEID_FORMAT_TRANSIENT,
allow_create="true") allow_create="true")
@@ -51,10 +52,9 @@ class TestSP():
assert self.sp assert self.sp
def test_identify(self): def test_identify(self):
# Create a SAMLResponse # Create a SAMLResponse
ava = { "givenName": ["Derek"], "surName": ["Jeter"], ava = {"givenName": ["Derek"], "surName": ["Jeter"],
"mail": ["derek@nyy.mlb.com"], "title":["The man"]} "mail": ["derek@nyy.mlb.com"], "title": ["The man"]}
resp_str = "%s" % self.server.create_authn_response( resp_str = "%s" % self.server.create_authn_response(
ava, "id1", "http://lingon.catalogix.se:8087/", ava, "id1", "http://lingon.catalogix.se:8087/",
@@ -62,16 +62,16 @@ class TestSP():
"foba0001@example.com", authn=AUTHN) "foba0001@example.com", authn=AUTHN)
resp_str = base64.encodestring(resp_str) resp_str = base64.encodestring(resp_str)
self.sp.outstanding_queries = {"id1":"http://www.example.com/service"} self.sp.outstanding_queries = {"id1": "http://www.example.com/service"}
session_info = self.sp._eval_authn_response({}, session_info = self.sp._eval_authn_response(
{"SAMLResponse": resp_str}) {}, {"SAMLResponse": [resp_str]})
assert len(session_info) > 1 assert len(session_info) > 1
assert session_info["came_from"] == 'http://www.example.com/service' assert session_info["came_from"] == 'http://www.example.com/service'
assert session_info["ava"] == {'givenName': ['Derek'], assert session_info["ava"] == {'givenName': ['Derek'],
'mail': ['derek@nyy.mlb.com'], 'mail': ['derek@nyy.mlb.com'],
'sn': ['Jeter'], 'sn': ['Jeter'],
'title': ['The man']} 'title': ['The man']}
if __name__ == "__main__": if __name__ == "__main__":