@@ -40,6 +40,35 @@ class TestSamlFrontend:
40
40
def construct_base_url_from_entity_id (self , entity_id ):
41
41
return "{parsed.scheme}://{parsed.netloc}" .format (parsed = urlparse (entity_id ))
42
42
43
+ def setup_for_authn_req (self , idp_conf , sp_conf , nameid_format ):
44
+ base = self .construct_base_url_from_entity_id (idp_conf ["entityid" ])
45
+ config = {"idp_config" : idp_conf , "endpoints" : ENDPOINTS , "base" : base ,
46
+ "state_id" : "state_id" }
47
+ sp_metadata_str = create_metadata_from_config_dict (sp_conf )
48
+ idp_conf ["metadata" ]["inline" ] = [sp_metadata_str ]
49
+
50
+ samlfrontend = SamlFrontend (lambda context , internal_req : (context , internal_req ),
51
+ INTERNAL_ATTRIBUTES , config )
52
+ samlfrontend .register_endpoints (["saml" ])
53
+
54
+ idp_metadata_str = create_metadata_from_config_dict (samlfrontend .config )
55
+ sp_conf ["metadata" ]["inline" ].append (idp_metadata_str )
56
+
57
+ fakesp = FakeSP (None , config = SPConfig ().load (sp_conf , metadata_construction = False ))
58
+ context = Context ()
59
+ context .state = State ()
60
+ context .request = parse .parse_qs (
61
+ urlparse (fakesp .make_auth_req (samlfrontend .config ["entityid" ], nameid_format )).query )
62
+ tmp_dict = {}
63
+ for val in context .request :
64
+ if isinstance (context .request [val ], list ):
65
+ tmp_dict [val ] = context .request [val ][0 ]
66
+ else :
67
+ tmp_dict [val ] = context .request [val ]
68
+ context .request = tmp_dict
69
+
70
+ return context , samlfrontend
71
+
43
72
@pytest .mark .parametrize ("conf" , [
44
73
None ,
45
74
{"idp_config_notok" : {}, "endpoints" : {}, "base" : "base" ,
@@ -76,31 +105,29 @@ def test_handle_authn_request(self, idp_conf, sp_conf):
76
105
"""
77
106
Performs a complete test for the module. The flow should be accepted.
78
107
"""
79
- base = self .construct_base_url_from_entity_id (idp_conf ["entityid" ])
80
- config = {"idp_config" : idp_conf , "endpoints" : ENDPOINTS , "base" : base ,
81
- "state_id" : "state_id" }
82
- sp_metadata_str = create_metadata_from_config_dict (sp_conf )
83
- idp_conf ["metadata" ]["inline" ] = [sp_metadata_str ]
108
+ context , samlfrontend = self .setup_for_authn_req (idp_conf , sp_conf , None )
109
+ _ , internal_req = samlfrontend .handle_authn_request (context , BINDING_HTTP_REDIRECT )
110
+ assert internal_req .requestor == sp_conf ["entityid" ]
84
111
85
- samlfrontend = SamlFrontend (lambda context , internal_req : (context , internal_req ),
86
- INTERNAL_ATTRIBUTES , config )
87
- samlfrontend .register_endpoints (["saml" ])
112
+ auth_info = AuthenticationInformation (PASSWORD , "2015-09-30T12:21:37Z" , "unittest_idp.xml" )
113
+ internal_response = InternalResponse (auth_info = auth_info )
114
+ internal_response .set_user_id_hash_type (internal_req .user_id_hash_type )
115
+ internal_response .add_attributes (USERS ["testuser1" ])
116
+
117
+ resp = samlfrontend .handle_authn_response (context , internal_response )
118
+ resp_dict = parse_qs (urlparse (resp .message ).query )
88
119
89
- idp_metadata_str = create_metadata_from_config_dict (samlfrontend .config )
90
- sp_conf ["metadata" ]["inline" ].append (idp_metadata_str )
91
120
fakesp = FakeSP (None , config = SPConfig ().load (sp_conf , metadata_construction = False ))
92
- context = Context ()
93
- context .state = State ()
94
- context .request = parse .parse_qs (
95
- urlparse (fakesp .make_auth_req (samlfrontend .config ["entityid" ])).query )
96
- tmp_dict = {}
97
- for val in context .request :
98
- if isinstance (context .request [val ], list ):
99
- tmp_dict [val ] = context .request [val ][0 ]
100
- else :
101
- tmp_dict [val ] = context .request [val ]
102
- context .request = tmp_dict
121
+ resp = fakesp .parse_authn_request_response (resp_dict ['SAMLResponse' ][0 ],
122
+ BINDING_HTTP_REDIRECT )
123
+ for key in resp .ava :
124
+ assert USERS ["testuser1" ][key ] == resp .ava [key ]
103
125
126
+ def test_handle_authn_request_without_name_id_policy (self , idp_conf , sp_conf ):
127
+ """
128
+ Performs a complete test for the module. The flow should be accepted.
129
+ """
130
+ context , samlfrontend = self .setup_for_authn_req (idp_conf , sp_conf , "" )
104
131
_ , internal_req = samlfrontend .handle_authn_request (context , BINDING_HTTP_REDIRECT )
105
132
assert internal_req .requestor == sp_conf ["entityid" ]
106
133
@@ -111,6 +138,8 @@ def test_handle_authn_request(self, idp_conf, sp_conf):
111
138
112
139
resp = samlfrontend .handle_authn_response (context , internal_response )
113
140
resp_dict = parse_qs (urlparse (resp .message ).query )
141
+
142
+ fakesp = FakeSP (None , config = SPConfig ().load (sp_conf , metadata_construction = False ))
114
143
resp = fakesp .parse_authn_request_response (resp_dict ['SAMLResponse' ][0 ],
115
144
BINDING_HTTP_REDIRECT )
116
145
for key in resp .ava :
0 commit comments