当前位置: 首页>>代码示例>>Python>>正文


Python logout_request.OneLogin_Saml2_Logout_Request类代码示例

本文整理汇总了Python中onelogin.saml2.logout_request.OneLogin_Saml2_Logout_Request的典型用法代码示例。如果您正苦于以下问题:Python OneLogin_Saml2_Logout_Request类的具体用法?Python OneLogin_Saml2_Logout_Request怎么用?Python OneLogin_Saml2_Logout_Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了OneLogin_Saml2_Logout_Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testIsInvalidDestination

    def testIsInvalidDestination(self):
        """
        Tests the is_valid method of the OneLogin_Saml2_LogoutRequest
        Case Invalid Destination
        """
        request_data = {
            'http_host': 'example.com',
            'script_name': 'index.html'
        }
        request = self.file_contents(join(self.data_path, 'logout_requests', 'logout_request.xml'))
        settings = OneLogin_Saml2_Settings(self.loadSettingsJSON())
        self.assertTrue(OneLogin_Saml2_Logout_Request.is_valid(settings, request, request_data))

        settings.set_strict(True)
        try:
            valid = OneLogin_Saml2_Logout_Request.is_valid(settings, request, request_data)
            self.assertFalse(valid)
        except Exception as e:
            self.assertIn('The LogoutRequest was received at', e.message)

        dom = parseString(request)
        dom.documentElement.setAttribute('Destination', None)
        self.assertTrue(OneLogin_Saml2_Logout_Request.is_valid(settings, dom.toxml(), request_data))

        dom.documentElement.removeAttribute('Destination')
        self.assertTrue(OneLogin_Saml2_Logout_Request.is_valid(settings, dom.toxml(), request_data))
开发者ID:jmoseley,项目名称:python-saml,代码行数:26,代码来源:logout_request_test.py

示例2: testIsValid

    def testIsValid(self):
        """
        Tests the is_valid method of the OneLogin_Saml2_LogoutRequest
        """
        request_data = {
            'http_host': 'example.com',
            'script_name': 'index.html'
        }
        request = self.file_contents(join(self.data_path, 'logout_requests', 'logout_request.xml'))
        settings = OneLogin_Saml2_Settings(self.loadSettingsJSON())

        self.assertTrue(OneLogin_Saml2_Logout_Request.is_valid(settings, request, request_data))

        settings.set_strict(True)
        self.assertFalse(OneLogin_Saml2_Logout_Request.is_valid(settings, request, request_data))

        settings.set_strict(False)
        dom = parseString(request)
        self.assertTrue(OneLogin_Saml2_Logout_Request.is_valid(settings, dom, request_data))

        settings.set_strict(True)
        self.assertFalse(OneLogin_Saml2_Logout_Request.is_valid(settings, dom, request_data))

        current_url = OneLogin_Saml2_Utils.get_self_url_no_query(request_data)
        request_2 = request.replace('http://stuff.com/endpoints/endpoints/sls.php', current_url)
        self.assertTrue(OneLogin_Saml2_Logout_Request.is_valid(settings, request_2, request_data))
开发者ID:jmoseley,项目名称:python-saml,代码行数:26,代码来源:logout_request_test.py

示例3: testGetIDFromSAMLLogoutRequest

    def testGetIDFromSAMLLogoutRequest(self):
        """
        Tests the get_id method of the OneLogin_Saml2_LogoutRequest
        """
        logout_request = self.file_contents(join(self.data_path, 'logout_requests', 'logout_request.xml'))
        id = OneLogin_Saml2_Logout_Request.get_id(logout_request)
        self.assertEqual('ONELOGIN_21584ccdfaca36a145ae990442dcd96bfe60151e', id)

        dom = parseString(logout_request)
        id2 = OneLogin_Saml2_Logout_Request.get_id(dom)
        self.assertEqual('ONELOGIN_21584ccdfaca36a145ae990442dcd96bfe60151e', id2)
开发者ID:AvnerCohen,项目名称:python-saml,代码行数:11,代码来源:logout_request_test.py

示例4: process_slo

    def process_slo(self, keep_local_session=False, request_id=None, delete_session_cb=None):
        """
        Process the SAML Logout Response / Logout Request sent by the IdP.

        :param keep_local_session: When false will destroy the local session, otherwise will destroy it
        :type keep_local_session: bool

        :param request_id: The ID of the LogoutRequest sent by this SP to the IdP
        :type request_id: string

        :returns: Redirection url
        """
        self.__errors = []

        if 'get_data' in self.__request_data and 'SAMLResponse' in self.__request_data['get_data']:
            logout_response = OneLogin_Saml2_Logout_Response(self.__settings, self.__request_data['get_data']['SAMLResponse'])
            if not logout_response.is_valid(self.__request_data, request_id):
                self.__errors.append('invalid_logout_response')
            elif logout_response.get_status() != OneLogin_Saml2_Constants.STATUS_SUCCESS:
                self.__errors.append('logout_not_success')
            elif not keep_local_session:
                OneLogin_Saml2_Utils.delete_local_session(delete_session_cb)

        elif 'get_data' in self.__request_data and 'SAMLRequest' in self.__request_data['get_data']:
            request = OneLogin_Saml2_Utils.decode_base64_and_inflate(self.__request_data['get_data']['SAMLRequest'])
            if not OneLogin_Saml2_Logout_Request.is_valid(self.__settings, request, self.__request_data):
                self.__errors.append('invalid_logout_request')
            else:
                if not keep_local_session:
                    OneLogin_Saml2_Utils.delete_local_session(delete_session_cb)

                in_response_to = OneLogin_Saml2_Logout_Request.get_id(request)
                response_builder = OneLogin_Saml2_Logout_Response(self.__settings)
                response_builder.build(in_response_to)
                logout_response = response_builder.get_response()

                parameters = {'SAMLResponse': logout_response}
                if 'RelayState' in self.__request_data['get_data']:
                    parameters['RelayState'] = self.__request_data['get_data']['RelayState']

                security = self.__settings.get_security_data()
                if 'logoutResponseSigned' in security and security['logoutResponseSigned']:
                    parameters['SigAlg'] = OneLogin_Saml2_Constants.RSA_SHA1
                    parameters['Signature'] = self.build_response_signature(logout_response, parameters.get('RelayState', None))

                return self.redirect_to(self.get_slo_url(), parameters)
        else:
            self.__errors.append('invalid_binding')
            raise OneLogin_Saml2_Error(
                'SAML LogoutRequest/LogoutResponse not found. Only supported HTTP_REDIRECT Binding',
                OneLogin_Saml2_Error.SAML_LOGOUTMESSAGE_NOT_FOUND
            )
开发者ID:jmoseley,项目名称:python-saml,代码行数:52,代码来源:auth.py

示例5: testIsInvalidXML

    def testIsInvalidXML(self):
        """
        Tests the is_valid method of the OneLogin_Saml2_LogoutRequest
        Case Invalid XML
        """
        request = '<xml>invalid</xml>'
        request_data = {
            'http_host': 'example.com',
            'script_name': 'index.html'
        }
        settings = OneLogin_Saml2_Settings(self.loadSettingsJSON())

        self.assertTrue(OneLogin_Saml2_Logout_Request.is_valid(settings, request, request_data))
        settings.set_strict(True)
        self.assertFalse(OneLogin_Saml2_Logout_Request.is_valid(settings, request, request_data))
开发者ID:jmoseley,项目名称:python-saml,代码行数:15,代码来源:logout_request_test.py

示例6: testGetSessionIndexes

    def testGetSessionIndexes(self):
        """
        Tests the get_session_indexes of the OneLogin_Saml2_LogoutRequest
        """
        request = self.file_contents(join(self.data_path, 'logout_requests', 'logout_request.xml'))

        session_indexes = OneLogin_Saml2_Logout_Request.get_session_indexes(request)
        self.assertEqual(len(session_indexes), 0)

        dom = parseString(request)
        session_indexes_2 = OneLogin_Saml2_Logout_Request.get_session_indexes(dom)
        self.assertEqual(len(session_indexes_2), 0)

        request_2 = self.file_contents(join(self.data_path, 'logout_requests', 'logout_request_with_sessionindex.xml'))
        session_indexes_3 = OneLogin_Saml2_Logout_Request.get_session_indexes(request_2)
        self.assertEqual(['_ac72a76526cb6ca19f8438e73879a0e6c8ae5131'], session_indexes_3)
开发者ID:AvnerCohen,项目名称:python-saml,代码行数:16,代码来源:logout_request_test.py

示例7: testGetNameId

    def testGetNameId(self):
        """
        Tests the get_nameid of the OneLogin_Saml2_LogoutRequest
        """
        request = self.file_contents(join(self.data_path, 'logout_requests', 'logout_request.xml'))
        name_id = OneLogin_Saml2_Logout_Request.get_nameid(request)
        self.assertEqual(name_id, 'ONELOGIN_1e442c129e1f822c8096086a1103c5ee2c7cae1c')

        request_2 = self.file_contents(join(self.data_path, 'logout_requests', 'logout_request_encrypted_nameid.xml'))
        self.assertRaisesRegexp(Exception, 'Key is required in order to decrypt the NameID',
                                OneLogin_Saml2_Logout_Request.get_nameid, request_2)

        settings = OneLogin_Saml2_Settings(self.loadSettingsJSON())
        key = settings.get_sp_key()
        name_id_3 = OneLogin_Saml2_Logout_Request.get_nameid(request_2, key)
        self.assertEqual('ONELOGIN_9c86c4542ab9d6fce07f2f7fd335287b9b3cdf69', name_id_3)
开发者ID:aidanlister,项目名称:python3-saml,代码行数:16,代码来源:logout_request_test.py

示例8: testGetNameIdData

    def testGetNameIdData(self):
        """
        Tests the get_nameid_data method of the OneLogin_Saml2_LogoutRequest
        """
        expected_name_id_data = {
            'Value': 'ONELOGIN_1e442c129e1f822c8096086a1103c5ee2c7cae1c',
            'Format': 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified',
            'SPNameQualifier': 'http://idp.example.com/'
        }

        request = self.file_contents(join(self.data_path, 'logout_requests', 'logout_request.xml'))
        name_id_data = OneLogin_Saml2_Logout_Request.get_nameid_data(request)
        self.assertEqual(expected_name_id_data, name_id_data)

        dom = parseString(request)
        name_id_data_2 = OneLogin_Saml2_Logout_Request.get_nameid_data(dom)
        self.assertEqual(expected_name_id_data, name_id_data_2)

        request_2 = self.file_contents(join(self.data_path, 'logout_requests', 'logout_request_encrypted_nameid.xml'))
        try:
            OneLogin_Saml2_Logout_Request.get_nameid_data(request_2)
            self.assertTrue(False)
        except Exception as e:
            self.assertIn('Key is required in order to decrypt the NameID', e.message)

        settings = OneLogin_Saml2_Settings(self.loadSettingsJSON())
        key = settings.get_sp_key()
        name_id_data_4 = OneLogin_Saml2_Logout_Request.get_nameid_data(request_2, key)
        expected_name_id_data = {
            'Value': 'ONELOGIN_9c86c4542ab9d6fce07f2f7fd335287b9b3cdf69',
            'Format': 'urn:oasis:names:tc:SAML:2.0:nameid-format:emailAddress',
            'SPNameQualifier': 'https://pitbulk.no-ip.org/newonelogin/demo1/metadata.php'
        }
        self.assertEqual(expected_name_id_data, name_id_data_4)

        dom_2 = parseString(request_2)
        encrypted_id_nodes = dom_2.getElementsByTagName('saml:EncryptedID')
        encrypted_data = encrypted_id_nodes[0].firstChild.nextSibling
        encrypted_id_nodes[0].removeChild(encrypted_data)
        try:
            OneLogin_Saml2_Logout_Request.get_nameid_data(dom_2.toxml(), key)
            self.assertTre(False)
        except Exception as e:
            self.assertIn('Not NameID found in the Logout Request', e.message)

        inv_request = self.file_contents(join(self.data_path, 'logout_requests', 'invalids', 'no_nameId.xml'))
        try:
            OneLogin_Saml2_Logout_Request.get_nameid_data(inv_request)
            self.assertTre(False)
        except Exception as e:
            self.assertIn('Not NameID found in the Logout Request', e.message)
开发者ID:AvnerCohen,项目名称:python-saml,代码行数:51,代码来源:logout_request_test.py

示例9: testGetIDFromDeflatedSAMLLogoutRequest

 def testGetIDFromDeflatedSAMLLogoutRequest(self):
     """
     Tests the get_id method of the OneLogin_Saml2_LogoutRequest
     """
     deflated_logout_request = self.file_contents(join(self.data_path, 'logout_requests', 'logout_request_deflated.xml.base64'))
     logout_request = OneLogin_Saml2_Utils.decode_base64_and_inflate(deflated_logout_request)
     id = OneLogin_Saml2_Logout_Request.get_id(logout_request)
     self.assertEqual('ONELOGIN_21584ccdfaca36a145ae990442dcd96bfe60151e', id)
开发者ID:AvnerCohen,项目名称:python-saml,代码行数:8,代码来源:logout_request_test.py

示例10: testGetIssuer

    def testGetIssuer(self):
        """
        Tests the get_issuer of the OneLogin_Saml2_LogoutRequest
        """
        request = self.file_contents(join(self.data_path, 'logout_requests', 'logout_request.xml'))

        issuer = OneLogin_Saml2_Logout_Request.get_issuer(request)
        self.assertEqual('http://idp.example.com/', issuer)

        dom = parseString(request)
        issuer_2 = OneLogin_Saml2_Logout_Request.get_issuer(dom)
        self.assertEqual('http://idp.example.com/', issuer_2)

        issuer_node = dom.getElementsByTagName('saml:Issuer')[0]
        issuer_node.parentNode.removeChild(issuer_node)
        issuer_3 = OneLogin_Saml2_Logout_Request.get_issuer(dom)
        self.assertIsNone(issuer_3)
开发者ID:AvnerCohen,项目名称:python-saml,代码行数:17,代码来源:logout_request_test.py

示例11: testIsInvalidNotOnOrAfter

    def testIsInvalidNotOnOrAfter(self):
        """
        Tests the is_valid method of the OneLogin_Saml2_LogoutRequest
        Case Invalid NotOnOrAfter
        """
        request_data = {
            'http_host': 'example.com',
            'script_name': 'index.html'
        }
        request = self.file_contents(join(self.data_path, 'logout_requests', 'invalids', 'not_after_failed.xml'))
        current_url = OneLogin_Saml2_Utils.get_self_url_no_query(request_data)
        request = request.replace('http://stuff.com/endpoints/endpoints/sls.php', current_url)
        settings = OneLogin_Saml2_Settings(self.loadSettingsJSON())
        self.assertTrue(OneLogin_Saml2_Logout_Request.is_valid(settings, request, request_data))

        settings.set_strict(True)
        try:
            valid = OneLogin_Saml2_Logout_Request.is_valid(settings, request, request_data)
            self.assertFalse(valid)
        except Exception as e:
            self.assertIn('Timing issues (please check your clock settings)', e.message)
开发者ID:jmoseley,项目名称:python-saml,代码行数:21,代码来源:logout_request_test.py

示例12: testLogoutNameIDandSessionIndex

    def testLogoutNameIDandSessionIndex(self):
        """
        Tests the logout method of the OneLogin_Saml2_Auth class
        Case nameID and sessionIndex as parameters.
        """
        settings_info = self.loadSettingsJSON()
        request_data = self.get_request()
        auth = OneLogin_Saml2_Auth(request_data, old_settings=settings_info)

        name_id = 'name_id_example'
        session_index = 'session_index_example'
        target_url = auth.logout(name_id=name_id, session_index=session_index)
        parsed_query = parse_qs(urlparse(target_url)[4])
        slo_url = settings_info['idp']['singleLogoutService']['url']
        self.assertIn(slo_url, target_url)
        self.assertIn('SAMLRequest', parsed_query)

        logout_request = OneLogin_Saml2_Utils.decode_base64_and_inflate(parsed_query['SAMLRequest'][0])
        name_id_from_request = OneLogin_Saml2_Logout_Request.get_nameid(logout_request)
        sessions_index_in_request = OneLogin_Saml2_Logout_Request.get_session_indexes(logout_request)
        self.assertIn(session_index, sessions_index_in_request)
        self.assertEqual(name_id, name_id_from_request)
开发者ID:FancyFane,项目名称:python3-saml,代码行数:22,代码来源:auth_test.py

示例13: testConstructorWithoutNameIdFormat

 def testConstructorWithoutNameIdFormat(self):
     """
     Tests the OneLogin_Saml2_LogoutRequest Constructor.
     Case: Checks that NameIDFormat is not added
     """
     settings_info = self.loadSettingsJSON()
     name_id = 'ONELOGIN_1e442c129e1f822c8096086a1103c5ee2c7cae1c'
     name_id_format = 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified'
     settings_info['sp']['NameIDFormat'] = name_id_format
     settings = OneLogin_Saml2_Settings(settings_info)
     logout_request = OneLogin_Saml2_Logout_Request(settings, name_id=name_id)
     logout_request_xml = OneLogin_Saml2_Utils.decode_base64_and_inflate(logout_request.get_request())
     name_id_data = OneLogin_Saml2_Logout_Request.get_nameid_data(logout_request_xml)
     expected_name_id_data = {
         'Value': name_id
     }
     self.assertEqual(expected_name_id_data, name_id_data)
开发者ID:onelogin,项目名称:python-saml,代码行数:17,代码来源:logout_request_test.py

示例14: testConstructorWithNameIdFormatOnSettings

 def testConstructorWithNameIdFormatOnSettings(self):
     """
     Tests the OneLogin_Saml2_LogoutRequest Constructor.
     Case: Defines NameIDFormat from settings
     """
     settings_info = self.loadSettingsJSON()
     name_id = 'ONELOGIN_1e442c129e1f822c8096086a1103c5ee2c7cae1c'
     name_id_format = 'urn:oasis:names:tc:SAML:2.0:nameid-format:transient'
     settings_info['sp']['NameIDFormat'] = name_id_format
     settings = OneLogin_Saml2_Settings(settings_info)
     logout_request = OneLogin_Saml2_Logout_Request(settings, name_id=name_id)
     logout_request_xml = OneLogin_Saml2_Utils.decode_base64_and_inflate(logout_request.get_request())
     name_id_data = OneLogin_Saml2_Logout_Request.get_nameid_data(logout_request_xml)
     expected_name_id_data = {
         'Value': name_id,
         'Format': name_id_format
     }
     self.assertEqual(expected_name_id_data, name_id_data)
开发者ID:onelogin,项目名称:python-saml,代码行数:18,代码来源:logout_request_test.py

示例15: testLogoutNameID

    def testLogoutNameID(self):
        """
        Tests the logout method of the OneLogin_Saml2_Auth class
        Case nameID loaded after process SAML Response
        """
        request_data = self.get_request()
        message = self.file_contents(join(self.data_path, "responses", "valid_response.xml.base64"))
        del request_data["get_data"]
        request_data["post_data"] = {"SAMLResponse": message}
        auth = OneLogin_Saml2_Auth(request_data, old_settings=self.loadSettingsJSON())
        auth.process_response()

        name_id_from_response = auth.get_nameid()

        target_url = auth.logout()
        parsed_query = parse_qs(urlparse(target_url)[4])
        self.assertIn("SAMLRequest", parsed_query)
        logout_request = OneLogin_Saml2_Utils.decode_base64_and_inflate(parsed_query["SAMLRequest"][0])

        name_id_from_request = OneLogin_Saml2_Logout_Request.get_nameid(logout_request)
        self.assertEqual(name_id_from_response, name_id_from_request)
开发者ID:actmd,项目名称:python-saml,代码行数:21,代码来源:auth_test.py


注:本文中的onelogin.saml2.logout_request.OneLogin_Saml2_Logout_Request类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。