27
27
28
28
from saml2 .authn_context import INTERNETPROTOCOLPASSWORD
29
29
from saml2 .client import Saml2Client
30
- from saml2 .config import SPConfig
31
30
from saml2 .pack import parse_soap_enveloped_saml
32
31
from saml2 .response import LogoutResponse
33
32
from saml2 .saml import NAMEID_FORMAT_PERSISTENT , EncryptedAssertion , Advice
@@ -122,18 +121,6 @@ def _leq(l1, l2):
122
121
return set (l1 ) == set (l2 )
123
122
124
123
125
- # def test_parse_3():
126
- # xml_response = open(XML_RESPONSE_FILE3).read()
127
- # response = samlp.response_from_string(xml_response)
128
- # client = Saml2Client({})
129
- # (ava, name_id, real_uri) = \
130
- # client.do_response(response, "xenosmilus.umdc.umu.se")
131
- # print(40*"=")
132
- # print(ava)
133
- # print(40*",")
134
- # print(name_id)
135
- # assert False
136
-
137
124
REQ1 = {"1.2.14" : """<?xml version='1.0' encoding='UTF-8'?>
138
125
<ns0:AttributeQuery Destination="https://idp.example.com/idp/" ID="id1"
139
126
IssueInstant="%s" Version="2.0" xmlns:ns0="urn:oasis:names:tc:SAML:2
@@ -193,7 +180,6 @@ def test_create_attribute_query1(self):
193
180
194
181
attrq = samlp .attribute_query_from_string (reqstr )
195
182
196
- print (attrq .keyswv ())
197
183
assert _leq (attrq .keyswv (), ['destination' , 'subject' , 'issue_instant' ,
198
184
'version' , 'id' , 'issuer' ])
199
185
@@ -222,7 +208,6 @@ def test_create_attribute_query2(self):
222
208
format = saml .NAMEID_FORMAT_PERSISTENT ,
223
209
message_id = "id1" )
224
210
225
- print (req .to_string ())
226
211
assert req .destination == "https://idp.example.com/idp/"
227
212
assert req .id == "id1"
228
213
assert req .version == "2.0"
@@ -272,7 +257,6 @@ def test_create_auth_request_0(self):
272
257
"http://www.example.com/sso" , message_id = "id1" )[1 ]
273
258
274
259
ar = samlp .authn_request_from_string (ar_str )
275
- print (ar )
276
260
assert ar .assertion_consumer_service_url == ("http://lingon.catalogix"
277
261
".se:8087/" )
278
262
assert ar .destination == "http://www.example.com/sso"
@@ -317,7 +301,6 @@ def test_create_auth_request_nameid_policy_allow_create(self):
317
301
"http://www.example.com/sso" , message_id = "id1" )[1 ]
318
302
319
303
ar = samlp .authn_request_from_string (ar_str )
320
- print (ar )
321
304
assert ar .assertion_consumer_service_url == ("http://lingon.catalogix"
322
305
".se:8087/" )
323
306
assert ar .destination == "http://www.example.com/sso"
@@ -340,7 +323,6 @@ def test_create_auth_request_vo(self):
340
323
message_id = "666" )[1 ]
341
324
342
325
ar = samlp .authn_request_from_string (ar_str )
343
- print (ar )
344
326
assert ar .id == "666"
345
327
assert ar .assertion_consumer_service_url == "http://lingon.catalogix" \
346
328
".se:8087/"
@@ -355,8 +337,6 @@ def test_create_auth_request_vo(self):
355
337
assert nid_policy .sp_name_qualifier == "urn:mace:example.com:it:tek"
356
338
357
339
def test_sign_auth_request_0 (self ):
358
- # print(self.client.config)
359
-
360
340
req_id , areq = self .client .create_authn_request (
361
341
"http://www.example.com/sso" , sign = True , message_id = "id1" )
362
342
@@ -367,11 +347,9 @@ def test_sign_auth_request_0(self):
367
347
assert ar .signature
368
348
assert ar .signature .signature_value
369
349
signed_info = ar .signature .signed_info
370
- # print(signed_info)
371
350
assert len (signed_info .reference ) == 1
372
351
assert signed_info .reference [0 ].uri == "#id1"
373
352
assert signed_info .reference [0 ].digest_value
374
- print ("------------------------------------------------" )
375
353
try :
376
354
assert self .client .sec .correctly_signed_authn_request (
377
355
ar_str , self .client .config .xmlsec_binary ,
@@ -424,7 +402,6 @@ def test_response_1(self):
424
402
assert authn_response .response .assertion [0 ].issuer .text == IDP
425
403
session_info = authn_response .session_info ()
426
404
427
- print (session_info )
428
405
assert session_info [
"ava" ]
== {
'mail' : [
'[email protected] ' ],
429
406
'givenName' : ['Derek' ],
430
407
'sn' : ['Jeter' ],
@@ -438,7 +415,6 @@ def test_response_1(self):
438
415
# One person in the cache
439
416
assert len (self .client .users .subjects ()) == 1
440
417
subject_id = self .client .users .subjects ()[0 ]
441
- print ("||||" , self .client .users .get_info_from (subject_id , IDP ))
442
418
# The information I have about the subject comes from one source
443
419
assert self .client .users .issuers_of_info (subject_id ) == [IDP ]
444
420
@@ -468,7 +444,6 @@ def test_response_1(self):
468
444
issuers = [self .client .users .issuers_of_info (s ) for s in
469
445
self .client .users .subjects ()]
470
446
# The information I have about the subjects comes from the same source
471
- print (issuers )
472
447
assert issuers == [[IDP ], [IDP ]]
473
448
474
449
def test_response_2 (self ):
@@ -791,14 +766,10 @@ def verify_authn_response(self, idp, authn_response, _client, ava_verify):
791
766
792
767
def test_init_values (self ):
793
768
entityid = self .client .config .entityid
794
- print (entityid )
795
769
assert entityid == "urn:mace:example.com:saml:roland:sp"
796
- print (self .client .metadata .with_descriptor ("idpsso" ))
797
770
location = self .client ._sso_location ()
798
- print (location )
799
771
assert location == 'http://localhost:8088/sso'
800
772
my_name = self .client ._my_name ()
801
- print (my_name )
802
773
assert my_name == "urn:mace:example.com:saml:roland:sp"
803
774
804
775
def test_sign_then_encrypt_assertion (self ):
@@ -865,7 +836,6 @@ def test_sign_then_encrypt_assertion(self):
865
836
866
837
seresp .assertion = resp_ass
867
838
seresp .encrypted_assertion = None
868
- # print(_sresp)
869
839
870
840
assert seresp .assertion
871
841
@@ -1354,7 +1324,6 @@ def test_signed_redirect(self):
1354
1324
1355
1325
res = self .server .parse_authn_request (qs ["SAMLRequest" ][0 ],
1356
1326
BINDING_HTTP_REDIRECT )
1357
- print (res )
1358
1327
1359
1328
def test_do_logout_signed_redirect (self ):
1360
1329
conf = config .SPConfig ()
@@ -1395,7 +1364,6 @@ def test_do_logout_signed_redirect(self):
1395
1364
1396
1365
res = self .server .parse_logout_request (qs ["SAMLRequest" ][0 ],
1397
1366
BINDING_HTTP_REDIRECT )
1398
- print (res )
1399
1367
1400
1368
def test_do_logout_post (self ):
1401
1369
# information about the user from an IdP
@@ -1466,7 +1434,7 @@ class TestClientWithDummy():
1466
1434
def setup_class (self ):
1467
1435
self .server = FakeIDP ("idp_all_conf" )
1468
1436
1469
- conf = SPConfig ()
1437
+ conf = config . SPConfig ()
1470
1438
conf .load_file ("servera_conf" )
1471
1439
self .client = Saml2Client (conf )
1472
1440
@@ -1536,12 +1504,13 @@ def test_logout_1(self):
1536
1504
entity_ids = self .client .users .issuers_of_info (nid )
1537
1505
assert entity_ids == ["urn:mace:example.com:saml:roland:idp" ]
1538
1506
resp = self .client .global_logout (nid , "Tired" , in_a_while (minutes = 5 ))
1539
- print (resp )
1540
1507
assert resp
1541
1508
assert len (resp ) == 1
1542
1509
assert list (resp .keys ()) == entity_ids
1543
1510
response = resp [entity_ids [0 ]]
1544
1511
assert isinstance (response , LogoutResponse )
1512
+ assert response .return_addrs
1513
+ assert len (response .return_addrs ) == 1
1545
1514
1546
1515
def test_post_sso (self ):
1547
1516
binding = BINDING_HTTP_POST
@@ -1566,7 +1535,6 @@ def test_post_sso(self):
1566
1535
'application/x-www-form-urlencoded' )]
1567
1536
1568
1537
response = self .client .send (** http_args )
1569
- print (response .text )
1570
1538
_dic = unpack_form (response .text , "SAMLResponse" )
1571
1539
# Explicitly allow unsigned responses for this test
1572
1540
self .client .want_response_signed = False
@@ -1603,7 +1571,6 @@ def test_negotiated_post_sso(self):
1603
1571
'application/x-www-form-urlencoded' )]
1604
1572
1605
1573
response = self .client .send (** http_args )
1606
- print (response .text )
1607
1574
_dic = unpack_form (response .text , "SAMLResponse" )
1608
1575
resp = self .client .parse_authn_request_response (_dic ["SAMLResponse" ],
1609
1576
BINDING_HTTP_POST ,
@@ -1613,6 +1580,44 @@ def test_negotiated_post_sso(self):
1613
1580
'http://www.example.com/login'
1614
1581
assert ac .authn_context_class_ref .text == INTERNETPROTOCOLPASSWORD
1615
1582
1583
+
1584
+ class TestClientNoConfigContext ():
1585
+ def setup_class (self ):
1586
+ self .server = FakeIDP ("idp_all_conf" )
1587
+
1588
+ conf = config .Config () # not SPConfig
1589
+ conf .load_file ("servera_conf" )
1590
+ self .client = Saml2Client (conf )
1591
+
1592
+ self .client .send = self .server .receive
1593
+
1594
+ def test_logout_1 (self ):
1595
+ """ one IdP/AA logout from"""
1596
+
1597
+ # information about the user from an IdP
1598
+ session_info = {
1599
+ "name_id" : nid ,
1600
+ "issuer" : "urn:mace:example.com:saml:roland:idp" ,
1601
+ "not_on_or_after" : in_a_while (minutes = 15 ),
1602
+ "ava" : {
1603
+ "givenName" : "Anders" ,
1604
+ "sn" : "Andersson" ,
1605
+
1606
+ }
1607
+ }
1608
+ self .client .users .add_information_about_person (session_info )
1609
+ entity_ids = self .client .users .issuers_of_info (nid )
1610
+ assert entity_ids == ["urn:mace:example.com:saml:roland:idp" ]
1611
+ resp = self .client .global_logout (nid , "Tired" , in_a_while (minutes = 5 ))
1612
+ assert resp
1613
+ assert len (resp ) == 1
1614
+ assert list (resp .keys ()) == entity_ids
1615
+ response = resp [entity_ids [0 ]]
1616
+ assert isinstance (response , LogoutResponse )
1617
+ assert response .return_addrs
1618
+ assert len (response .return_addrs ) == 1
1619
+
1620
+
1616
1621
def test_parse_soap_enveloped_saml_xxe ():
1617
1622
xml = """<?xml version="1.0"?>
1618
1623
<!DOCTYPE lolz [
@@ -1625,10 +1630,6 @@ def test_parse_soap_enveloped_saml_xxe():
1625
1630
with raises (EntitiesForbidden ):
1626
1631
parse_soap_enveloped_saml (xml , None )
1627
1632
1628
- # if __name__ == "__main__":
1629
- # tc = TestClient()
1630
- # tc.setup_class()
1631
- # tc.test_response()
1632
1633
1633
1634
if __name__ == "__main__" :
1634
1635
tc = TestClient ()
0 commit comments