Skip to content

Commit 4f2b814

Browse files
author
Roland Hedberg
committed
Script to update the metadata that is used in some tests.
Added tests on new functionality.
1 parent bfc6b55 commit 4f2b814

File tree

7 files changed

+6950
-2625
lines changed

7 files changed

+6950
-2625
lines changed

tests/InCommon-metadata.xml

Lines changed: 5995 additions & 1795 deletions
Large diffs are not rendered by default.

tests/get_metadata.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
curl -G -O http://md.incommon.org/InCommon/InCommon-metadata.xml
2+
curl -G -O http://metadata.aai.switch.ch/metadata.aaitest.xml

tests/metadata.aaitest.xml

Lines changed: 890 additions & 819 deletions
Large diffs are not rendered by default.

tests/test_20_assertion.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,5 +774,27 @@ def test_assertion_with_zero_attributes():
774774
assert msg.attribute_statement == []
775775

776776

777+
def test_assertion_with_authn_instant():
778+
ava = {}
779+
ast = Assertion(ava)
780+
policy = Policy({
781+
"default": {
782+
"lifetime": {"minutes": 240},
783+
"attribute_restrictions": None, # means all I have
784+
"name_form": NAME_FORMAT_URI
785+
},
786+
})
787+
name_id = NameID(format=NAMEID_FORMAT_TRANSIENT, text="foobar")
788+
issuer = Issuer(text="entityid", format=NAMEID_FORMAT_ENTITY)
789+
msg = ast.construct("sp_entity_id", "in_response_to", "consumer_url",
790+
name_id, [AttributeConverterNOOP(NAME_FORMAT_URI)],
791+
policy, issuer=issuer, authn_decl=ACD,
792+
authn_auth="authn_authn",
793+
authn_instant=1234567890)
794+
795+
print msg
796+
assert msg.authn_statement[0].authn_instant == "2009-02-13T23:31:30Z"
797+
798+
777799
if __name__ == "__main__":
778-
test_assertion_with_zero_attributes()
800+
test_assertion_with_authn_instant()

tests/test_30_mdstore.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ def test_incommon_1():
126126
mds.imp(METADATACONF["2"])
127127

128128
print mds.entities()
129-
assert mds.entities() == 1727
129+
assert mds.entities() > 1700
130130
idps = mds.with_descriptor("idpsso")
131131
print idps.keys()
132-
assert len(idps) == 318 # ~ 18%
132+
assert len(idps) > 300 # ~ 18%
133133
try:
134134
_ = mds.single_sign_on_service('urn:mace:incommon:uiuc.edu')
135135
except UnknownPrincipal:
@@ -191,7 +191,7 @@ def test_switch_1():
191191
disable_ssl_certificate_validation=True)
192192

193193
mds.imp(METADATACONF["5"])
194-
assert len(mds.keys()) == 167
194+
assert len(mds.keys()) > 160
195195
idps = mds.with_descriptor("idpsso")
196196
print idps.keys()
197197
idpsso = mds.single_sign_on_service(
@@ -200,7 +200,7 @@ def test_switch_1():
200200
print idpsso
201201
assert destinations(idpsso) == [
202202
'https://aai-demo-idp.switch.ch/idp/profile/SAML2/Redirect/SSO']
203-
assert len(idps) == 31
203+
assert len(idps) > 30
204204
aas = mds.with_descriptor("attribute_authority")
205205
print aas.keys()
206206
aad = aas['https://aai-demo-idp.switch.ch/idp/shibboleth']

tests/test_41_response.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,8 @@ def test_only_use_keys_in_metadata(self):
100100
# should fail
101101
raises(MissingKey,
102102
'sc.correctly_signed_response("%s" % self._sign_resp_)')
103+
104+
if __name__ == "__main__":
105+
t = TestResponse()
106+
t.setup_class()
107+
t.test_1()

tests/test_50_server.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# -*- coding: utf-8 -*-
33
import base64
44
from urlparse import parse_qs
5+
from saml2.assertion import Policy
56
from saml2.authn_context import INTERNETPROTOCOLPASSWORD
67
from saml2.saml import NameID, NAMEID_FORMAT_TRANSIENT
78
from saml2.samlp import response_from_string
@@ -241,22 +242,46 @@ def test_sso_response_with_identity(self):
241242
def test_sso_response_without_identity(self):
242243
resp = self.server.create_authn_response(
243244
{},
244-
"id12", # in_response_to
245-
"http://localhost:8087/", # consumer_url
245+
"id12", # in_response_to
246+
"http://localhost:8087/", # consumer_url
246247
"urn:mace:example.com:saml:roland:sp", # sp_entity_id
247248
userid="USER1",
248-
authn=AUTHN
249+
authn=AUTHN,
250+
release_policy=Policy(),
251+
best_effort=True
249252
)
250253

251254
print resp.keyswv()
252255
assert _eq(resp.keyswv(), ['status', 'destination', 'in_response_to',
253-
'issue_instant', 'version', 'id', 'issuer'])
256+
'issue_instant', 'version', 'id', 'issuer',
257+
'assertion'])
254258
assert resp.destination == "http://localhost:8087/"
255259
assert resp.in_response_to == "id12"
256260
assert resp.status
257261
assert resp.status.status_code.value == samlp.STATUS_SUCCESS
258262
assert resp.issuer.text == "urn:mace:example.com:saml:roland:idp"
259-
assert not resp.assertion
263+
assert not resp.assertion.attribute_statement
264+
265+
def test_sso_response_specific_instant(self):
266+
_authn = AUTHN.copy()
267+
_authn["authn_instant"] = 1234567890
268+
269+
resp = self.server.create_authn_response(
270+
{},
271+
"id12", # in_response_to
272+
"http://localhost:8087/", # consumer_url
273+
"urn:mace:example.com:saml:roland:sp", # sp_entity_id
274+
userid="USER1",
275+
authn=_authn,
276+
best_effort=True
277+
)
278+
279+
print resp.keyswv()
280+
assert _eq(resp.keyswv(), ['status', 'destination', 'in_response_to',
281+
'issue_instant', 'version', 'id', 'issuer',
282+
'assertion'])
283+
authn_statement = resp.assertion.authn_statement[0]
284+
assert authn_statement.authn_instant == '2009-02-13T23:31:30Z'
260285

261286
def test_sso_failure_response(self):
262287
exc = s_utils.MissingValue("eduPersonAffiliation missing")
@@ -477,4 +502,4 @@ def test_1(self):
477502
if __name__ == "__main__":
478503
ts = TestServer1()
479504
ts.setup_class()
480-
ts.test_authn_response_0()
505+
ts.test_sso_response_specific_instant()

0 commit comments

Comments
 (0)