コード例 #1
0
    def test_check_token_without_token(self, m):
        auth = AuthorizationManager(identity_url='http://fake_url', api_version=AUTH_API_V2)

        m.get('http://fake_url/tokens/token', json=self.validate_info_v2)

        try:
            auth.check_token(admin_token='admin_token', token=None)
            self.assertFalse(False)
        except Unauthorized as e:
            self.assertEquals(e.message, "Token is empty", 'The expected auth token is not the same')
コード例 #2
0
    def test_check_token_without_token(self, m):
        auth = AuthorizationManager(identity_url='http://fake_url',
                                    api_version=AUTH_API_V2)

        m.get('http://fake_url/tokens/token', json=self.validate_info_v2)

        try:
            auth.check_token(admin_token='admin_token', token=None)
            self.assertFalse(False)
        except Unauthorized as e:
            self.assertEquals(e.message, "Token is empty",
                              'The expected auth token is not the same')
コード例 #3
0
    def test_check_token_and_raise_general_exception(self, m, get_info_token_mock):
        auth = AuthorizationManager(identity_url='http://fake_url', api_version=AUTH_API_V2)

        get_info_token_mock.side_effect = Exception("error message")
        m.get('http://fake_url/tokens/token', json=self.validate_info_v2)

        try:
            auth.check_token(admin_token='admin_token', token='token')
            self.assertFalse(True)
        except Exception as e:
            self.assertEquals(e.message, "error message")
        finally:
            self.assertTrue(get_info_token_mock.called)
            get_info_token_mock.reset_mock()
コード例 #4
0
    def test_check_token_and_raise_general_exception(self, m,
                                                     get_info_token_mock):
        auth = AuthorizationManager(identity_url='http://fake_url',
                                    api_version=AUTH_API_V2)

        get_info_token_mock.side_effect = Exception("error message")
        m.get('http://fake_url/tokens/token', json=self.validate_info_v2)

        try:
            auth.check_token(admin_token='admin_token', token='token')
            self.assertFalse(True)
        except Exception as e:
            self.assertEquals(e.message, "error message")
        finally:
            self.assertTrue(get_info_token_mock.called)
            get_info_token_mock.reset_mock()
コード例 #5
0
    def test_check_token_and_raise_internal_server_error(self, m, get_info_token_mock):
        auth = AuthorizationManager(identity_url='http://fake_url', api_version=AUTH_API_V2)

        get_info_token_mock.side_effect = InternalServerError("internal server message")
        m.get('http://fake_url/tokens/token', json=self.validate_info_v2)

        try:
            auth.check_token(admin_token='admin_token', token='token')
            self.assertFalse(True)
        except AuthorizationFailure as e:
            result = (e.message == 'Cannot authorize API client.' or
                      e.message == 'Token could not have enough permissions to access tenant')

            self.assertTrue(result, 'The expected error message is not the same')

        finally:
            self.assertTrue(get_info_token_mock.called)
            get_info_token_mock.reset_mock()
コード例 #6
0
    def test_check_token_and_raise_internal_server_error(
            self, m, get_info_token_mock):
        auth = AuthorizationManager(identity_url='http://fake_url',
                                    api_version=AUTH_API_V2)

        get_info_token_mock.side_effect = InternalServerError(
            "internal server message")
        m.get('http://fake_url/tokens/token', json=self.validate_info_v2)

        try:
            auth.check_token(admin_token='admin_token', token='token')
            self.assertFalse(True)
        except AuthorizationFailure as e:
            result = (
                e.message == 'Cannot authorize API client.' or e.message
                == 'Token could not have enough permissions to access tenant')

            self.assertTrue(result,
                            'The expected error message is not the same')

        finally:
            self.assertTrue(get_info_token_mock.called)
            get_info_token_mock.reset_mock()
コード例 #7
0
    def test_check_token(self, m):
        """
        Test the operation to check is a token is valid or not.

        :param m: Request mock decorator.
        :return: Nothing
        """
        auth = AuthorizationManager(identity_url='http://fake_url', api_version=AUTH_API_V2)

        m.get('http://fake_url/tokens/token', json=self.validate_info_v2)

        tokenExpected = auth.check_token(admin_token='admin_token', token='token')

        self.assertEquals(tokenExpected.expires, self.expiredExpectedv2, 'The expired time expected is not the same')
        self.assertEquals(tokenExpected.id, self.idExpected, 'The token id expected is not the same')
        self.assertEquals(tokenExpected.username, self.usernameExpected, 'The username expected is not the same')
        self.assertEquals(tokenExpected.tenant, self.tenantExpectedv2, 'The tenant expected is not the same')
コード例 #8
0
    def test_check_token(self, m):
        """
        Test the operation to check is a token is valid or not.

        :param m: Request mock decorator.
        :return: Nothing
        """
        auth = AuthorizationManager(identity_url='http://fake_url',
                                    api_version=AUTH_API_V2)

        m.get('http://fake_url/tokens/token', json=self.validate_info_v2)

        tokenExpected = auth.check_token(admin_token='admin_token',
                                         token='token')

        self.assertEquals(tokenExpected.expires, self.expiredExpectedv2,
                          'The expired time expected is not the same')
        self.assertEquals(tokenExpected.id, self.idExpected,
                          'The token id expected is not the same')
        self.assertEquals(tokenExpected.username, self.usernameExpected,
                          'The username expected is not the same')
        self.assertEquals(tokenExpected.tenant, self.tenantExpectedv2,
                          'The tenant expected is not the same')