9
9
from saml2 import BINDING_HTTP_REDIRECT , BINDING_HTTP_POST
10
10
from saml2 .authn_context import PASSWORD
11
11
from saml2 .config import SPConfig
12
- from saml2 .saml import NAMEID_FORMAT_PERSISTENT
12
+ from saml2 .saml import NAMEID_FORMAT_PERSISTENT , NAMEID_FORMAT_TRANSIENT
13
+ from saml2 .samlp import NameIDPolicy
13
14
14
15
from satosa .context import Context
15
16
from satosa .frontends .saml2 import SamlFrontend
@@ -158,3 +159,85 @@ def test_get_filter_attributes_with_sp_requested_attributes_without_friendlyname
158
159
assert set (filtered_attributes ) == set (
159
160
["edupersontargetedid" , "edupersonprincipalname" , "edupersonaffiliation" , "mail" ,
160
161
"displayname" , "sn" , "givenname" ])
162
+
163
+ def test_acr_mapping_in_authn_response (self , idp_conf , sp_conf ):
164
+ eidas_loa_low = "http://eidas.europa.eu/LoA/low"
165
+ loa = {"" : eidas_loa_low }
166
+
167
+ base = self .construct_base_url_from_entity_id (idp_conf ["entityid" ])
168
+ conf = {"idp_config" : idp_conf , "endpoints" : ENDPOINTS , "base" : base ,
169
+ "state_id" : "state_id" , "acr_mapping" : loa }
170
+
171
+ samlfrontend = SamlFrontend (None , INTERNAL_ATTRIBUTES , conf )
172
+ samlfrontend .register_endpoints (["foo" ])
173
+
174
+ idp_metadata_str = create_metadata_from_config_dict (samlfrontend .config )
175
+ sp_conf ["metadata" ]["inline" ].append (idp_metadata_str )
176
+ fakesp = FakeSP (None , config = SPConfig ().load (sp_conf , metadata_construction = False ))
177
+
178
+ auth_info = AuthenticationInformation (PASSWORD , "2015-09-30T12:21:37Z" , "unittest_idp.xml" )
179
+ internal_response = InternalResponse (auth_info = auth_info )
180
+ context = Context ()
181
+ context .state = State ()
182
+
183
+ resp_args = {
184
+ "name_id_policy" : NameIDPolicy (format = NAMEID_FORMAT_TRANSIENT ),
185
+ "in_response_to" : None ,
186
+ "destination" : "" ,
187
+ "sp_entity_id" : None ,
188
+ "binding" : BINDING_HTTP_REDIRECT
189
+
190
+ }
191
+ request_state = samlfrontend .save_state (context , resp_args , "" )
192
+ context .state .add (conf ["state_id" ], request_state )
193
+
194
+ resp = samlfrontend .handle_authn_response (context , internal_response )
195
+ resp_dict = parse_qs (urlparse (resp .message ).query )
196
+ resp = fakesp .parse_authn_request_response (resp_dict ['SAMLResponse' ][0 ],
197
+ BINDING_HTTP_REDIRECT )
198
+
199
+ assert len (resp .assertion .authn_statement ) == 1
200
+ authn_context_class_ref = resp .assertion .authn_statement [
201
+ 0 ].authn_context .authn_context_class_ref
202
+ assert authn_context_class_ref .text == eidas_loa_low
203
+
204
+ def test_acr_mapping_per_idp_in_authn_response (self , idp_conf , sp_conf ):
205
+ expected_loa = "LoA1"
206
+ loa = {"" : "http://eidas.europa.eu/LoA/low" , idp_conf ["entityid" ]: expected_loa }
207
+
208
+ base = self .construct_base_url_from_entity_id (idp_conf ["entityid" ])
209
+ conf = {"idp_config" : idp_conf , "endpoints" : ENDPOINTS , "base" : base ,
210
+ "state_id" : "state_id" , "acr_mapping" : loa }
211
+
212
+ samlfrontend = SamlFrontend (None , INTERNAL_ATTRIBUTES , conf )
213
+ samlfrontend .register_endpoints (["foo" ])
214
+
215
+ idp_metadata_str = create_metadata_from_config_dict (samlfrontend .config )
216
+ sp_conf ["metadata" ]["inline" ].append (idp_metadata_str )
217
+ fakesp = FakeSP (None , config = SPConfig ().load (sp_conf , metadata_construction = False ))
218
+
219
+ auth_info = AuthenticationInformation (PASSWORD , "2015-09-30T12:21:37Z" , idp_conf ["entityid" ])
220
+ internal_response = InternalResponse (auth_info = auth_info )
221
+ context = Context ()
222
+ context .state = State ()
223
+
224
+ resp_args = {
225
+ "name_id_policy" : NameIDPolicy (format = NAMEID_FORMAT_TRANSIENT ),
226
+ "in_response_to" : None ,
227
+ "destination" : "" ,
228
+ "sp_entity_id" : None ,
229
+ "binding" : BINDING_HTTP_REDIRECT
230
+
231
+ }
232
+ request_state = samlfrontend .save_state (context , resp_args , "" )
233
+ context .state .add (conf ["state_id" ], request_state )
234
+
235
+ resp = samlfrontend .handle_authn_response (context , internal_response )
236
+ resp_dict = parse_qs (urlparse (resp .message ).query )
237
+ resp = fakesp .parse_authn_request_response (resp_dict ['SAMLResponse' ][0 ],
238
+ BINDING_HTTP_REDIRECT )
239
+
240
+ assert len (resp .assertion .authn_statement ) == 1
241
+ authn_context_class_ref = resp .assertion .authn_statement [
242
+ 0 ].authn_context .authn_context_class_ref
243
+ assert authn_context_class_ref .text == expected_loa
0 commit comments