@@ -270,6 +270,41 @@ def test_unknown_idp(self):
270270 response = self .client .get (reverse ('saml2_login' )+ '?idp=https://unknown.org' )
271271 self .assertEqual (response .status_code , 403 )
272272
273+
274+ def test_login_authn_context (self ):
275+ sp_kwargs = {"requested_authn_context" : {
276+ "authn_context_class_ref" : [
277+ "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport" ,
278+ "urn:oasis:names:tc:SAML:2.0:ac:classes:TLSClient" ,
279+ ],
280+ "comparison" : "minimum" ,
281+ }
282+ }
283+
284+ # monkey patch SAML configuration
285+ settings .SAML_CONFIG = conf .create_conf (
286+ sp_host = 'sp.example.com' ,
287+ idp_hosts = ['idp.example.com' ],
288+ metadata_file = 'remote_metadata_one_idp.xml' ,
289+ sp_kwargs = sp_kwargs
290+ )
291+
292+ response = self .client .get (reverse ('saml2_login' ))
293+ self .assertEqual (response .status_code , 302 )
294+ location = response ['Location' ]
295+
296+ url = urlparse (location )
297+ self .assertEqual (url .hostname , 'idp.example.com' )
298+ self .assertEqual (url .path , '/simplesaml/saml2/idp/SSOService.php' )
299+
300+ params = parse_qs (url .query )
301+ self .assertIn ('SAMLRequest' , params )
302+
303+ saml_request = params ['SAMLRequest' ][0 ]
304+ self .assertIn ('urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport' , decode_base64_and_inflate (
305+ saml_request ).decode ('utf-8' ))
306+
307+
273308 def test_login_one_idp (self ):
274309 # monkey patch SAML configuration
275310 settings .SAML_CONFIG = conf .create_conf (
@@ -294,6 +329,7 @@ def test_login_one_idp(self):
294329 self .assertIn ('AuthnRequest xmlns' , decode_base64_and_inflate (
295330 saml_request ).decode ('utf-8' ))
296331
332+
297333 # if we set a next arg in the login view, it is preserverd
298334 # in the RelayState argument
299335 nexturl = '/another-view/'
0 commit comments