@@ -910,18 +910,26 @@ def testBuildResponseSignature(self):
910910 except Exception as e :
911911 self .assertIn ("Trying to sign the SAMLResponse but can't load the SP private key" , e .message )
912912
913- def testGetLastDecryptedResponse (self ):
913+ def testGetLastSAMLResponse (self ):
914914 settings = self .loadSettingsJSON ()
915+ message = self .file_contents (join (self .data_path , 'responses' , 'signed_message_response.xml.base64' ))
916+ message_wrapper = {'post_data' : {'SAMLResponse' : message }}
917+ auth = OneLogin_Saml2_Auth (message_wrapper , old_settings = settings )
918+ auth .process_response ()
919+ expected_message = self .file_contents (join (self .data_path , 'responses' , 'pretty_signed_message_response.xml' ))
920+ self .assertEqual (auth .get_last_response_xml (True ), expected_message )
921+
922+ # with encrypted assertion
915923 message = self .file_contents (join (self .data_path , 'responses' , 'valid_encrypted_assertion.xml.base64' ))
916924 message_wrapper = {'post_data' : {'SAMLResponse' : message }}
917925 auth = OneLogin_Saml2_Auth (message_wrapper , old_settings = settings )
918926 auth .process_response ()
919927 decrypted_response = self .file_contents (join (self .data_path , 'responses' , 'decrypted_valid_encrypted_assertion.xml' ))
920928 self .assertEqual (auth .get_last_response_xml (False ), decrypted_response )
921- decrypted_response = self .file_contents (join (self .data_path , 'responses' , 'pretty_decrypted_valid_encrypted_assertion.xml' ))
922- self .assertEqual (auth .get_last_response_xml (True ), decrypted_response )
929+ pretty_decrypted_response = self .file_contents (join (self .data_path , 'responses' , 'pretty_decrypted_valid_encrypted_assertion.xml' ))
930+ self .assertEqual (auth .get_last_response_xml (True ), pretty_decrypted_response )
923931
924- def testGetLastSentRequest (self ):
932+ def testGetLastAuthnRequest (self ):
925933 settings = self .loadSettingsJSON ()
926934 auth = OneLogin_Saml2_Auth ({'http_host' : 'localhost' , 'script_name' : 'thing' }, old_settings = settings )
927935 auth .login ()
@@ -940,6 +948,51 @@ def testGetLastSentRequest(self):
940948 )
941949 self .assertIn (expectedFragment , auth .get_last_request_xml ())
942950
951+ def testGetLastLogoutRequest (self ):
952+ settings = self .loadSettingsJSON ()
953+ auth = OneLogin_Saml2_Auth ({'http_host' : 'localhost' , 'script_name' : 'thing' }, old_settings = settings )
954+ auth .logout ()
955+ expectedFragment = (
956+ ' Destination="http://idp.example.com/SingleLogoutService.php">\n '
957+ ' <saml:Issuer>http://stuff.com/endpoints/metadata.php</saml:Issuer>\n '
958+ ' <saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity" SPNameQualifier="http://stuff.com/endpoints/metadata.php">http://idp.example.com/</saml:NameID>\n '
959+ ' \n </samlp:LogoutRequest>'
960+ )
961+ self .assertIn (expectedFragment , auth .get_last_request_xml ())
962+
963+ request = self .file_contents (join (self .data_path , 'logout_requests' , 'logout_request.xml' ))
964+ message = OneLogin_Saml2_Utils .deflate_and_base64_encode (request )
965+ message_wrapper = {'get_data' : {'SAMLRequest' : message }}
966+ auth = OneLogin_Saml2_Auth (message_wrapper , old_settings = settings )
967+ auth .process_slo ()
968+ self .assertEqual (request , auth .get_last_request_xml ())
969+
970+ def testGetLastLogoutResponse (self ):
971+ settings = self .loadSettingsJSON ()
972+ request = self .file_contents (join (self .data_path , 'logout_requests' , 'logout_request.xml' ))
973+ message = OneLogin_Saml2_Utils .deflate_and_base64_encode (request )
974+ message_wrapper = {'get_data' : {'SAMLRequest' : message }}
975+ auth = OneLogin_Saml2_Auth (message_wrapper , old_settings = settings )
976+ auth .process_slo ()
977+ expectedFragment = (
978+ 'Destination="http://idp.example.com/SingleLogoutService.php"\n '
979+ ' InResponseTo="ONELOGIN_21584ccdfaca36a145ae990442dcd96bfe60151e"\n >\n '
980+ ' <saml:Issuer>http://stuff.com/endpoints/metadata.php</saml:Issuer>\n '
981+ ' <samlp:Status>\n '
982+ ' <samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success" />\n '
983+ ' </samlp:Status>\n '
984+ '</samlp:LogoutResponse>'
985+ )
986+ self .assertIn (expectedFragment , auth .get_last_response_xml ())
987+
988+ response = self .file_contents (join (self .data_path , 'logout_responses' , 'logout_response.xml' ))
989+ message = OneLogin_Saml2_Utils .deflate_and_base64_encode (response )
990+ message_wrapper = {'get_data' : {'SAMLResponse' : message }}
991+ auth = OneLogin_Saml2_Auth (message_wrapper , old_settings = settings )
992+ auth .process_slo ()
993+ self .assertEqual (response , auth .get_last_response_xml ())
994+
995+
943996if __name__ == '__main__' :
944997 if is_running_under_teamcity ():
945998 runner = TeamcityTestRunner ()
0 commit comments