Skip to content

Commit 6a85250

Browse files
author
Roland Hedberg
committed
Fixed a couple of tests
1 parent 9af7555 commit 6a85250

File tree

4 files changed

+67
-59
lines changed

4 files changed

+67
-59
lines changed

tests/test_02_saml.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def test_make_vals_multi_dict(self):
215215

216216
attr = Attribute()
217217
saml2.make_vals(ava, AttributeValue, attr, prop="attribute_value")
218-
assert attr.keyswv() == ["attribute_value"]
218+
assert attr.keyswv() == ["name_format", "attribute_value"]
219219
assert len(attr.attribute_value) == 4
220220

221221
def test_to_string_nspair(self):
@@ -1211,3 +1211,7 @@ def testUsingTestData(self):
12111211
"""Test assertion_from_string() using test data"""
12121212
# TODO
12131213
pass
1214+
1215+
if __name__ == "__main__":
1216+
t = TestSAMLBase()
1217+
t.test_make_vals_multi_dict()

tests/test_12_s_utils.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ def test_attribute_statement():
137137
assert statement.keyswv() == ["attribute"]
138138
assert len(statement.attribute) == 2
139139
attr0 = statement.attribute[0]
140-
assert _eq(attr0.keyswv(), ["name", "attribute_value"])
140+
assert _eq(attr0.keyswv(), ["name", "attribute_value", "name_format"])
141141
assert len(attr0.attribute_value) == 1
142142
attr1 = statement.attribute[1]
143-
assert _eq(attr1.keyswv(), ["name", "attribute_value"])
143+
assert _eq(attr1.keyswv(), ["name", "attribute_value", "name_format"])
144144
assert len(attr1.attribute_value) == 1
145145
if attr0.name == "givenName":
146146
assert attr0.attribute_value[0].text == "Derek"
@@ -222,7 +222,8 @@ def test_value_4():
222222
saml.AttributeValue, text="Derek")],
223223
friendly_name="givenName")
224224

225-
assert _eq(attribute.keyswv(), ["friendly_name", "attribute_value"])
225+
assert _eq(attribute.keyswv(), ["friendly_name", "attribute_value",
226+
"name_format"])
226227
assert attribute.friendly_name == "givenName"
227228
assert len(attribute.attribute_value) == 1
228229
assert attribute.attribute_value[0].text == "Derek"
@@ -234,7 +235,7 @@ def test_do_attribute_statement_0():
234235
assert statement.keyswv() == ["attribute"]
235236
assert len(statement.attribute) == 1
236237
attr0 = statement.attribute[0]
237-
assert _eq(attr0.keyswv(), ["name", "attribute_value"])
238+
assert _eq(attr0.keyswv(), ["name", "attribute_value", "name_format"])
238239
assert attr0.name == "vo_attr"
239240
assert len(attr0.attribute_value) == 1
240241
assert attr0.attribute_value[0].text == "foobar"
@@ -248,9 +249,9 @@ def test_do_attribute_statement():
248249
assert statement.keyswv() == ["attribute"]
249250
assert len(statement.attribute) == 2
250251
attr0 = statement.attribute[0]
251-
assert _eq(attr0.keyswv(), ["name", "attribute_value"])
252+
assert _eq(attr0.keyswv(), ["name", "attribute_value", "name_format"])
252253
attr1 = statement.attribute[1]
253-
assert _eq(attr1.keyswv(), ["name", "attribute_value"])
254+
assert _eq(attr1.keyswv(), ["name", "attribute_value", "name_format"])
254255
if attr0.name == "givenName":
255256
assert len(attr0.attribute_value) == 2
256257
assert _eq([av.text for av in attr0.attribute_value],

tests/test_19_attribute_converter.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_default():
2626
class TestAC():
2727
def setup_class(self):
2828
self.acs = attribute_converter.ac_factory(full_path("attributemaps"))
29-
29+
3030
def test_setup(self):
3131
print self.acs
3232
assert len(self.acs) == 3
@@ -67,9 +67,9 @@ def test_ava_fro_2(self):
6767

6868
def test_to_attrstat_1(self):
6969
ava = { "givenName": "Roland", "sn": "Hedberg" }
70-
70+
7171
statement = attribute_converter.from_local(self.acs, ava, BASIC_NF)
72-
72+
7373
assert statement is not None
7474
assert len(statement) == 2
7575
a0 = statement[0]
@@ -88,12 +88,12 @@ def test_to_attrstat_1(self):
8888
assert a1.name_format == BASIC_NF
8989
else:
9090
assert False
91-
91+
9292
def test_to_attrstat_2(self):
9393
ava = { "givenName": "Roland", "surname": "Hedberg" }
94-
94+
9595
statement = attribute_converter.from_local(self.acs, ava, URI_NF)
96-
96+
9797
assert len(statement) == 2
9898
a0 = statement[0]
9999
a1 = statement[1]
@@ -111,9 +111,9 @@ def test_to_attrstat_2(self):
111111
assert a1.name_format == URI_NF
112112
else:
113113
assert False
114-
114+
115115
def test_to_local_name(self):
116-
116+
117117
attr = [
118118
saml.Attribute(
119119
friendly_name="surName",
@@ -127,9 +127,9 @@ def test_to_local_name(self):
127127
friendly_name="titel",
128128
name="urn:oid:2.5.4.12",
129129
name_format="urn:oasis:names:tc:SAML:2.0:attrname-format:uri")]
130-
130+
131131
lan = [attribute_converter.to_local_name(self.acs, a) for a in attr]
132-
132+
133133
assert _eq(lan, ['sn', 'givenName', 'title'])
134134

135135
# def test_ava_fro_1(self):
@@ -150,8 +150,11 @@ def test_to_local_name(self):
150150
# assert result == {'givenName': [], 'sn': [], 'title': []}
151151

152152
def test_to_local_name_from_basic(self):
153-
attr = [saml.Attribute(
154-
name="urn:mace:dir:attribute-def:eduPersonPrimaryOrgUnitDN")]
153+
attr = [
154+
saml.Attribute(
155+
name="urn:mace:dir:attribute-def:eduPersonPrimaryOrgUnitDN",
156+
name_format="urn:oasis:names:tc:SAML:2.0:attrname-format:basic")
157+
]
155158

156159
lan = [attribute_converter.to_local_name(self.acs, a) for a in attr]
157160

@@ -222,7 +225,7 @@ def test_schac():
222225

223226

224227
if __name__ == "__main__":
225-
# t = TestAC()
226-
# t.setup_class()
227-
# t.test_mixed_attributes_1()
228-
test_schac()
228+
t = TestAC()
229+
t.setup_class()
230+
t.test_to_local_name_from_basic()
231+
#test_schac()

tests/test_60_sp.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,31 @@
88
from s2repoze.plugins.sp import make_plugin
99
from saml2.server import Server
1010

11-
ENV1 = {'SERVER_SOFTWARE': 'CherryPy/3.1.2 WSGI Server',
12-
'SCRIPT_NAME': '',
13-
'ACTUAL_SERVER_PROTOCOL': 'HTTP/1.1',
14-
'REQUEST_METHOD': 'GET',
15-
'PATH_INFO': '/krissms',
16-
'SERVER_PROTOCOL': 'HTTP/1.1',
17-
'QUERY_STRING': '',
18-
'REMOTE_ADDR': '127.0.0.1',
19-
'HTTP_USER_AGENT':
20-
'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; en-us) ',
21-
'HTTP_CONNECTION': 'keep-alive',
22-
'SERVER_NAME': 'lingon-catalogix-se-2.local',
23-
'REMOTE_PORT': '57309',
24-
'wsgi.url_scheme': 'http',
25-
'SERVER_PORT': '8087',
26-
'HTTP_HOST': '127.0.0.1:8087',
27-
'wsgi.multithread': True,
28-
'HTTP_ACCEPT':
29-
'application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
30-
'wsgi.version': (1, 0),
31-
'wsgi.run_once': False,
32-
'wsgi.multiprocess': False,
33-
'HTTP_ACCEPT_LANGUAGE': 'en-us',
34-
'HTTP_ACCEPT_ENCODING': 'gzip, deflate'}
11+
ENV1 = {'SERVER_SOFTWARE': 'CherryPy/3.1.2 WSGI Server',
12+
'SCRIPT_NAME': '',
13+
'ACTUAL_SERVER_PROTOCOL': 'HTTP/1.1',
14+
'REQUEST_METHOD': 'GET',
15+
'PATH_INFO': '/krissms',
16+
'SERVER_PROTOCOL': 'HTTP/1.1',
17+
'QUERY_STRING': '',
18+
'REMOTE_ADDR': '127.0.0.1',
19+
'HTTP_USER_AGENT':
20+
'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; en-us) ',
21+
'HTTP_CONNECTION': 'keep-alive',
22+
'SERVER_NAME': 'lingon-catalogix-se-2.local',
23+
'REMOTE_PORT': '57309',
24+
'wsgi.url_scheme': 'http',
25+
'SERVER_PORT': '8087',
26+
'HTTP_HOST': '127.0.0.1:8087',
27+
'wsgi.multithread': True,
28+
'HTTP_ACCEPT':
29+
'application/xml,application/xhtml+xml,text/html;q=0.9,'
30+
'text/plain;q=0.8,image/png,*/*;q=0.5',
31+
'wsgi.version': (1, 0),
32+
'wsgi.run_once': False,
33+
'wsgi.multiprocess': False,
34+
'HTTP_ACCEPT_LANGUAGE': 'en-us',
35+
'HTTP_ACCEPT_ENCODING': 'gzip, deflate'}
3536

3637
trans_name_policy = NameIDPolicy(format=NAMEID_FORMAT_TRANSIENT,
3738
allow_create="true")
@@ -49,29 +50,28 @@ def setup_class(self):
4950

5051
def test_setup(self):
5152
assert self.sp
52-
53-
def test_identify(self):
5453

54+
def test_identify(self):
5555
# Create a SAMLResponse
56-
ava = { "givenName": ["Derek"], "surName": ["Jeter"],
57-
"mail": ["[email protected]"], "title":["The man"]}
56+
ava = {"givenName": ["Derek"], "surName": ["Jeter"],
57+
"mail": ["[email protected]"], "title": ["The man"]}
5858

5959
resp_str = "%s" % self.server.create_authn_response(
6060
ava, "id1", "http://lingon.catalogix.se:8087/",
6161
"urn:mace:example.com:saml:roland:sp", trans_name_policy,
6262
"[email protected]", authn=AUTHN)
6363

6464
resp_str = base64.encodestring(resp_str)
65-
self.sp.outstanding_queries = {"id1":"http://www.example.com/service"}
66-
session_info = self.sp._eval_authn_response({},
67-
{"SAMLResponse": resp_str})
68-
65+
self.sp.outstanding_queries = {"id1": "http://www.example.com/service"}
66+
session_info = self.sp._eval_authn_response(
67+
{}, {"SAMLResponse": [resp_str]})
68+
6969
assert len(session_info) > 1
7070
assert session_info["came_from"] == 'http://www.example.com/service'
71-
assert session_info["ava"] == {'givenName': ['Derek'],
72-
'mail': ['[email protected]'],
73-
'sn': ['Jeter'],
74-
'title': ['The man']}
71+
assert session_info["ava"] == {'givenName': ['Derek'],
72+
'mail': ['[email protected]'],
73+
'sn': ['Jeter'],
74+
'title': ['The man']}
7575

7676

7777
if __name__ == "__main__":

0 commit comments

Comments
 (0)