Skip to content

Commit b8c7c3e

Browse files
author
Jimmy John
committed
unit tests for attributeConsumingService
1 parent fe3ad90 commit b8c7c3e

4 files changed

Lines changed: 180 additions & 4 deletions

File tree

tests/settings/settings4.json

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{
2+
"strict": false,
3+
"debug": false,
4+
"custom_base_path": "../../../tests/data/customPath/",
5+
"sp": {
6+
"entityId": "http://pytoolkit.com:8000/metadata/",
7+
"assertionConsumerService": {
8+
"url": "http://pytoolkit.com:8000/?acs"
9+
},
10+
"attributeConsumingService": [
11+
{
12+
"isDefault": false,
13+
"serviceName": "Test Service",
14+
"serviceDescription": "Test Service",
15+
"requestedAttributes": [ {
16+
"name": "urn:oid:2.5.4.42",
17+
"nameFormat": "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
18+
"friendlyName": "givenName",
19+
"isRequired": false
20+
},
21+
{
22+
"name": "urn:oid:2.5.4.4",
23+
"nameFormat": "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
24+
"friendlyName": "sn",
25+
"isRequired": false
26+
},
27+
{
28+
"name": "urn:oid:2.16.840.1.113730.3.1.241",
29+
"nameFormat": "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
30+
"friendlyName": "displayName",
31+
"isRequired": false
32+
},
33+
{
34+
"name": "urn:oid:0.9.2342.19200300.100.1.3",
35+
"nameFormat": "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
36+
"friendlyName": "mail",
37+
"isRequired": false
38+
},
39+
{
40+
"name": "urn:oid:0.9.2342.19200300.100.1.1",
41+
"nameFormat": "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
42+
"friendlyName": "uid",
43+
"isRequired": false
44+
}
45+
]
46+
}
47+
],
48+
"singleLogoutService": {
49+
"url": "http://pytoolkit.com:8000/?sls"
50+
},
51+
"NameIDFormat": "urn:oasis:names:tc:SAML:2.0:nameid-format:unspecified"
52+
},
53+
"idp": {
54+
"entityId": "https://pitbulk.no-ip.org/simplesaml/saml2/idp/metadata.php",
55+
"singleSignOnService": {
56+
"url": "http://pitbulk.no-ip.org/SSOService.php"
57+
},
58+
"singleLogoutService": {
59+
"url": "http://pitbulk.no-ip.org/SingleLogoutService.php"
60+
},
61+
"x509cert": "MIICbDCCAdWgAwIBAgIBADANBgkqhkiG9w0BAQ0FADBTMQswCQYDVQQGEwJ1czETMBEGA1UECAwKQ2FsaWZvcm5pYTEVMBMGA1UECgwMT25lbG9naW4gSW5jMRgwFgYDVQQDDA9pZHAuZXhhbXBsZS5jb20wHhcNMTQwOTIzMTIyNDA4WhcNNDIwMjA4MTIyNDA4WjBTMQswCQYDVQQGEwJ1czETMBEGA1UECAwKQ2FsaWZvcm5pYTEVMBMGA1UECgwMT25lbG9naW4gSW5jMRgwFgYDVQQDDA9pZHAuZXhhbXBsZS5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAOWA+YHU7cvPOrBOfxCscsYTJB+kH3MaA9BFrSHFS+KcR6cw7oPSktIJxUgvDpQbtfNcOkE/tuOPBDoech7AXfvH6d7Bw7xtW8PPJ2mB5Hn/HGW2roYhxmfh3tR5SdwN6i4ERVF8eLkvwCHsNQyK2Ref0DAJvpBNZMHCpS24916/AgMBAAGjUDBOMB0GA1UdDgQWBBQ77/qVeiigfhYDITplCNtJKZTM8DAfBgNVHSMEGDAWgBQ77/qVeiigfhYDITplCNtJKZTM8DAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBDQUAA4GBAJO2j/1uO80E5C2PM6Fk9mzerrbkxl7AZ/mvlbOn+sNZE+VZ1AntYuG8ekbJpJtG1YfRfc7EA9mEtqvv4dhv7zBy4nK49OR+KpIBjItWB5kYvrqMLKBa32sMbgqqUqeF1ENXKjpvLSuPdfGJZA3dNa/+Dyb8GGqWe707zLyc5F8m"
62+
},
63+
"security": {
64+
"authnRequestsSigned": false,
65+
"wantAssertionsSigned": false,
66+
"signMetadata": false
67+
},
68+
"contactPerson": {
69+
"technical": {
70+
"givenName": "technical_name",
71+
"emailAddress": "technical@example.com"
72+
},
73+
"support": {
74+
"givenName": "support_name",
75+
"emailAddress": "support@example.com"
76+
}
77+
},
78+
"organization": {
79+
"en-US": {
80+
"name": "sp_test",
81+
"displayname": "SP test",
82+
"url": "http://sp.example.com"
83+
}
84+
}
85+
}

tests/src/OneLogin/saml2_tests/authn_request_test.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020

2121
class OneLogin_Saml2_Authn_Request_Test(unittest.TestCase):
22-
def loadSettingsJSON(self):
23-
filename = join(dirname(dirname(dirname(dirname(__file__)))), 'settings', 'settings1.json')
22+
def loadSettingsJSON(self, filename='settings1.json'):
23+
filename = join(dirname(dirname(dirname(dirname(__file__)))), 'settings', filename)
2424
if exists(filename):
2525
stream = open(filename, 'r')
2626
settings = json.load(stream)
@@ -260,6 +260,26 @@ def testCreateEncSAMLRequest(self):
260260
self.assertRegexpMatches(inflated, 'Format="urn:oasis:names:tc:SAML:2.0:nameid-format:encrypted"')
261261
self.assertRegexpMatches(inflated, 'ProviderName="SP prueba"')
262262

263+
def testAttributeConsumingService(self):
264+
"""
265+
Tests that the attributeConsumingServiceIndex is present as an attribute
266+
"""
267+
268+
saml_settings = self.loadSettingsJSON('settings4.json')
269+
settings = OneLogin_Saml2_Settings(saml_settings)
270+
settings._OneLogin_Saml2_Settings__organization = {
271+
u'en-US': {
272+
u'url': u'http://sp.example.com',
273+
u'name': u'sp_test'
274+
}
275+
}
276+
277+
authn_request = OneLogin_Saml2_Authn_Request(settings)
278+
authn_request_encoded = authn_request.get_request()
279+
decoded = b64decode(authn_request_encoded)
280+
inflated = decompress(decoded, -15)
281+
282+
self.assertRegexpMatches(inflated, 'AttributeConsumingServiceIndex="1"')
263283

264284
if __name__ == '__main__':
265285
if is_running_under_teamcity():

tests/src/OneLogin/saml2_tests/metadata_test.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
class OneLogin_Saml2_Metadata_Test(unittest.TestCase):
2020
settings_path = join(dirname(dirname(dirname(dirname(__file__)))), 'settings')
2121

22-
def loadSettingsJSON(self):
23-
filename = join(self.settings_path, 'settings1.json')
22+
def loadSettingsJSON(self, filename='settings1.json'):
23+
filename = join(self.settings_path, filename)
2424
if exists(filename):
2525
stream = open(filename, 'r')
2626
settings = json.load(stream)
@@ -143,6 +143,36 @@ def testBuilder(self):
143143
parsed_datetime = strftime(r'%Y-%m-%dT%H:%M:%SZ', datetime_value.timetuple())
144144
self.assertIn('validUntil="%s"' % parsed_datetime, metadata6)
145145

146+
def testBuilderAttributeConsumingService(self):
147+
settings = OneLogin_Saml2_Settings(self.loadSettingsJSON('settings4.json'))
148+
sp_data = settings.get_sp_data()
149+
security = settings.get_security_data()
150+
organization = settings.get_organization()
151+
contacts = settings.get_contacts()
152+
153+
metadata = OneLogin_Saml2_Metadata.builder(
154+
sp_data, security['authnRequestsSigned'],
155+
security['wantAssertionsSigned'], None, None, contacts,
156+
organization
157+
)
158+
159+
self.assertIn('xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"', metadata)
160+
self.assertIn('<md:AttributeConsumingService index="1" isDefault="false"><md:ServiceName \
161+
xml:lang="en">Test Service</md:ServiceName><md:ServiceDescription xml:lang="en">Test Service\
162+
</md:ServiceDescription><md:RequestedAttribute Name="urn:oid:2.5.4.42" \
163+
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" FriendlyName="givenName" \
164+
isRequired="false"/><md:RequestedAttribute Name="urn:oid:2.5.4.4" \
165+
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" FriendlyName="sn" \
166+
isRequired="false"/><md:RequestedAttribute Name="urn:oid:2.16.840.1.113730.3.1.241" \
167+
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" FriendlyName="displayName" \
168+
isRequired="false"/><md:RequestedAttribute Name="urn:oid:0.9.2342.19200300.100.1.3" \
169+
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" FriendlyName="mail" \
170+
isRequired="false"/><md:RequestedAttribute Name="urn:oid:0.9.2342.19200300.100.1.1" \
171+
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" FriendlyName="uid" \
172+
isRequired="false"/></md:AttributeConsumingService>', metadata)
173+
174+
175+
146176
def testSignMetadata(self):
147177
"""
148178
Tests the signMetadata method of the OneLogin_Saml2_Metadata

tests/src/OneLogin/saml2_tests/settings_test.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,47 @@ def testCheckSettings(self):
298298
self.assertIn('sp_entityId_not_found', e.message)
299299
self.assertIn('sp_acs_not_found', e.message)
300300

301+
#AttributeConsumingService tests
302+
303+
#serviceName, requestedAttributes are required
304+
settings_info['sp']['attributeConsumingService'] = [
305+
{
306+
"isDefault": False,
307+
"serviceDescription": "Test Service"
308+
}
309+
]
310+
try:
311+
OneLogin_Saml2_Settings(settings_info)
312+
self.assertTrue(False)
313+
except Exception as e:
314+
self.assertIn('sp_attributeConsumingService_serviceName_not_found', e.message)
315+
self.assertIn('sp_attributeConsumingService_requestedAttributes_not_found', e.message)
316+
317+
# requestedAttributes/name is required
318+
settings_info['sp']['attributeConsumingService'] = [
319+
{
320+
"isDefault": "False",
321+
"serviceName": {},
322+
"serviceDescription": ["Test Service"],
323+
"requestedAttributes": [ {
324+
"nameFormat": "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
325+
"friendlyName": "givenName",
326+
"isRequired": "False"
327+
}
328+
]
329+
}
330+
]
331+
try:
332+
OneLogin_Saml2_Settings(settings_info)
333+
self.assertTrue(False)
334+
except Exception as e:
335+
self.assertIn('sp_attributeConsumingService_requestedAttributes_name_not_found', e.message)
336+
self.assertIn('sp_attributeConsumingService_requestedAttributes_isRequired_type_invalid', e.message)
337+
self.assertIn('sp_attributeConsumingService_serviceDescription_type_invalid', e.message)
338+
self.assertIn('sp_attributeConsumingService_serviceName_type_invalid', e.message)
339+
self.assertIn('sp_attributeConsumingService_isDefault_type_invalid', e.message)
340+
341+
301342
settings_info['idp']['entityID'] = 'entityId'
302343
settings_info['idp']['singleSignOnService'] = {}
303344
settings_info['idp']['singleSignOnService']['url'] = 'invalid_value'

0 commit comments

Comments
 (0)