@@ -857,6 +857,98 @@ def testSetStrict(self):
857857 with self .assertRaises (AssertionError ):
858858 auth .set_strict ('42' )
859859
860+ def testIsAuthenticated (self ):
861+ """
862+ Tests the is_authenticated method of the OneLogin_Saml2_Auth
863+ """
864+ request_data = self .get_request ()
865+ del request_data ['get_data' ]
866+ message = self .file_contents (join (self .data_path , 'responses' , 'response1.xml.base64' ))
867+ request_data ['post_data' ] = {
868+ 'SAMLResponse' : message
869+ }
870+ auth = OneLogin_Saml2_Auth (request_data , old_settings = self .loadSettingsJSON ())
871+ auth .process_response ()
872+ self .assertFalse (auth .is_authenticated ())
873+
874+ message = self .file_contents (join (self .data_path , 'responses' , 'valid_response.xml.base64' ))
875+ request_data ['post_data' ] = {
876+ 'SAMLResponse' : message
877+ }
878+ auth = OneLogin_Saml2_Auth (request_data , old_settings = self .loadSettingsJSON ())
879+ auth .process_response ()
880+ self .assertTrue (auth .is_authenticated ())
881+
882+ def testGetNameId (self ):
883+ """
884+ Tests the get_nameid method of the OneLogin_Saml2_Auth
885+ """
886+ settings = self .loadSettingsJSON ()
887+ request_data = self .get_request ()
888+ del request_data ['get_data' ]
889+ message = self .file_contents (join (self .data_path , 'responses' , 'response1.xml.base64' ))
890+ request_data ['post_data' ] = {
891+ 'SAMLResponse' : message
892+ }
893+ auth = OneLogin_Saml2_Auth (request_data , old_settings = settings )
894+ auth .process_response ()
895+ self .assertFalse (auth .is_authenticated ())
896+ self .assertEqual (auth .get_nameid (), None )
897+
898+ message = self .file_contents (join (self .data_path , 'responses' , 'valid_response.xml.base64' ))
899+ request_data ['post_data' ] = {
900+ 'SAMLResponse' : message
901+ }
902+ auth = OneLogin_Saml2_Auth (request_data , old_settings = settings )
903+ auth .process_response ()
904+ self .assertTrue (auth .is_authenticated ())
905+ self .assertEqual ("492882615acf31c8096b627245d76ae53036c090" , auth .get_nameid ())
906+
907+ settings_2 = self .loadSettingsJSON ('settings2.json' )
908+ message = self .file_contents (join (self .data_path , 'responses' , 'signed_message_encrypted_assertion2.xml.base64' ))
909+ request_data ['post_data' ] = {
910+ 'SAMLResponse' : message
911+ }
912+ auth = OneLogin_Saml2_Auth (request_data , old_settings = settings_2 )
913+ auth .process_response ()
914+ self .assertTrue (auth .is_authenticated ())
915+ self .assertEqual ("25ddd7d34a7d79db69167625cda56a320adf2876" , auth .get_nameid ())
916+
917+ def testGetNameIdFormat (self ):
918+ """
919+ Tests the get_nameid_format method of the OneLogin_Saml2_Auth
920+ """
921+ settings = self .loadSettingsJSON ()
922+ request_data = self .get_request ()
923+ del request_data ['get_data' ]
924+ message = self .file_contents (join (self .data_path , 'responses' , 'response1.xml.base64' ))
925+ request_data ['post_data' ] = {
926+ 'SAMLResponse' : message
927+ }
928+ auth = OneLogin_Saml2_Auth (request_data , old_settings = settings )
929+ auth .process_response ()
930+ self .assertFalse (auth .is_authenticated ())
931+ self .assertEqual (auth .get_nameid_format (), None )
932+
933+ message = self .file_contents (join (self .data_path , 'responses' , 'valid_response.xml.base64' ))
934+ request_data ['post_data' ] = {
935+ 'SAMLResponse' : message
936+ }
937+ auth = OneLogin_Saml2_Auth (request_data , old_settings = settings )
938+ auth .process_response ()
939+ self .assertTrue (auth .is_authenticated ())
940+ self .assertEqual ("urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress" , auth .get_nameid_format ())
941+
942+ settings_2 = self .loadSettingsJSON ('settings2.json' )
943+ message = self .file_contents (join (self .data_path , 'responses' , 'signed_message_encrypted_assertion2.xml.base64' ))
944+ request_data ['post_data' ] = {
945+ 'SAMLResponse' : message
946+ }
947+ auth = OneLogin_Saml2_Auth (request_data , old_settings = settings_2 )
948+ auth .process_response ()
949+ self .assertTrue (auth .is_authenticated ())
950+ self .assertEqual ("urn:oasis:names:tc:SAML:2.0:nameid-format:unspecified" , auth .get_nameid_format ())
951+
860952 def testBuildRequestSignature (self ):
861953 """
862954 Tests the build_request_signature method of the OneLogin_Saml2_Auth
0 commit comments