@@ -615,7 +615,7 @@ def testLoginSigned(self):
615615 def testLoginForceAuthN (self ):
616616 """
617617 Tests the login method of the OneLogin_Saml2_Auth class
618- Case Login with no parameters. A AuthN Request is built with ForceAuthn and redirect executed
618+ Case AuthN Request is built with ForceAuthn and redirect executed
619619 """
620620 settings_info = self .loadSettingsJSON ()
621621 return_to = u'http://example.com/returnto'
@@ -649,7 +649,7 @@ def testLoginForceAuthN(self):
649649 def testLoginIsPassive (self ):
650650 """
651651 Tests the login method of the OneLogin_Saml2_Auth class
652- Case Login with no parameters. A AuthN Request is built with IsPassive and redirect executed
652+ Case AuthN Request is built with IsPassive and redirect executed
653653 """
654654 settings_info = self .loadSettingsJSON ()
655655 return_to = u'http://example.com/returnto'
@@ -683,7 +683,7 @@ def testLoginIsPassive(self):
683683 def testLoginSetNameIDPolicy (self ):
684684 """
685685 Tests the login method of the OneLogin_Saml2_Auth class
686- Case Logout with no parameters. A AuthN Request is built with and without NameIDPolicy
686+ Case AuthN Request is built with and without NameIDPolicy
687687 """
688688 settings_info = self .loadSettingsJSON ()
689689 return_to = u'http://example.com/returnto'
@@ -714,6 +714,47 @@ def testLoginSetNameIDPolicy(self):
714714 request_3 = OneLogin_Saml2_Utils .decode_base64_and_inflate (parsed_query_3 ['SAMLRequest' ][0 ])
715715 self .assertNotIn ('<samlp:NameIDPolicy' , request_3 )
716716
717+ def testLoginWithSubject (self ):
718+ """
719+ Tests the login method of the OneLogin_Saml2_Auth class
720+ Case AuthN Request is built with and without Subject
721+ """
722+ settings_info = self .loadSettingsJSON ()
723+ return_to = u'http://example.com/returnto'
724+ sso_url = settings_info ['idp' ]['singleSignOnService' ]['url' ]
725+
726+ auth = OneLogin_Saml2_Auth (self .get_request (), old_settings = settings_info )
727+ target_url = auth .login (return_to )
728+ parsed_query = parse_qs (urlparse (target_url )[4 ])
729+ self .assertIn (sso_url , target_url )
730+ self .assertIn ('SAMLRequest' , parsed_query )
731+ request = OneLogin_Saml2_Utils .decode_base64_and_inflate (parsed_query ['SAMLRequest' ][0 ])
732+ self .assertNotIn ('<saml:Subject>' , request )
733+ self .assertNotIn ('<saml:NameID' , request )
734+ self .assertNotIn ('<saml:saml:SubjectConfirmation' , request )
735+
736+ auth_2 = OneLogin_Saml2_Auth (self .get_request (), old_settings = settings_info )
737+ target_url_2 = auth_2 .login (return_to , name_id_value_req = 'testuser@example.com' )
738+ parsed_query_2 = parse_qs (urlparse (target_url_2 )[4 ])
739+ self .assertIn (sso_url , target_url_2 )
740+ self .assertIn ('SAMLRequest' , parsed_query_2 )
741+ request_2 = OneLogin_Saml2_Utils .decode_base64_and_inflate (parsed_query_2 ['SAMLRequest' ][0 ])
742+ self .assertIn ('<saml:Subject>' , request_2 )
743+ self .assertIn ('Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified">testuser@example.com</saml:NameID>' , request_2 )
744+ self .assertIn ('<saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">' , request_2 )
745+
746+ settings_info ['sp' ]['NameIDFormat' ] = 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress'
747+ auth_3 = OneLogin_Saml2_Auth (self .get_request (), old_settings = settings_info )
748+ target_url_3 = auth_3 .login (return_to , name_id_value_req = 'testuser@example.com' )
749+ parsed_query_3 = parse_qs (urlparse (target_url_3 )[4 ])
750+ self .assertIn (sso_url , target_url_3 )
751+ self .assertIn ('SAMLRequest' , parsed_query_3 )
752+ request_3 = OneLogin_Saml2_Utils .decode_base64_and_inflate (parsed_query_3 ['SAMLRequest' ][0 ])
753+ self .assertIn ('<saml:Subject>' , request_3 )
754+ self .assertIn ('Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress">testuser@example.com</saml:NameID>' , request_3 )
755+ self .assertIn ('<saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">' , request_3 )
756+
757+
717758 def testLogout (self ):
718759 """
719760 Tests the logout method of the OneLogin_Saml2_Auth class
0 commit comments