コード例 #1
0
    def test_raise_exception_with_user_not_admin_with_keystone_v2(self, m):
        # Given
        response_with_v2 = {
            "access": {
                "token": {
                    "expires": "2016-02-10T11:16:56Z",
                    "id": "7cd3b96409ef497587c98c8c5f596b8d"
                },
                "user": {
                    "username":
                    "******",
                    "roles": [{
                        "id": "8d27cbfdaf3845b8a5cfc349f0b52bac",
                        "name": "owner"
                    }, {
                        "is_default": True,
                        "id": "a6c6f50bc3ff438ab311a9063610d383",
                        "name": "other"
                    }],
                }
            }
        }

        auth = AuthorizationManager(identity_url='http://fake_url',
                                    api_version=AUTH_API_V2)

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

        try:
            # When
            auth.get_info_token(admin_token='admin_token', token='token')
        except Exception as exception:
            # Then
            self.assertEqual('Role is not admin', exception.args[0])
コード例 #2
0
    def test_raise_exception_with_user_not_admin_with_keystone_v3(self, m):
        # Given
        response_with_v3 = {
            "token": {
                "roles": [
                    {
                        "id": "8d2767fdak5k45b8a5cfc349f0b52bac",
                        "name": "owner"
                    },
                    {
                        "id": "a6c6f50bc3kkk38ab311a9063610d383",
                        "name": "other"
                    }
                ],
                "expires_at": "2016-02-10T11:16:56.000000Z",
                "project": {
                    "id": "00000000000000000000960090160000", "name": "admin"
                },
                "user": {
                    "id": "5a919b072cac4b02917e785f1898826e", "name": "admin"
                },
                "issued_at": "2016-02-09T11:16:56.440835"
            }
        }

        auth = AuthorizationManager(identity_url='http://fake_url', api_version=AUTH_API_V3)

        m.get('http://fake_url/auth/tokens/', json=response_with_v3)

        try:
            # When
            auth.get_info_token(admin_token='admin_token', token=self.idExpected)
        except Exception as exception:
            # Then
            self.assertEqual('Role is not admin', exception.args[0])
コード例 #3
0
    def test_error_from_keystone_v3(self, m):
        """
        Test the procedure to request a wrong information to Kesyone v3.

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

        m.get('http://fake_url/auth/tokens/', status_code=404)

        try:
            auth.get_info_token(admin_token='admin_token', token='token')
        except AuthorizationFailure as e:
            result = (e.message == 'Cannot authorize API client.' or e.message.status_code == 404)
            self.assertTrue(result, 'The expected error message is not the same')
コード例 #4
0
    def test_error_from_keystone_v3(self, m):
        """
        Test the procedure to request a wrong information to Kesyone v3.

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

        m.get('http://fake_url/auth/tokens/', status_code=404)

        try:
            auth.get_info_token(admin_token='admin_token', token='token')
        except AuthorizationFailure as e:
            result = (e.message == 'Cannot authorize API client.'
                      or e.message.status_code == 404)
            self.assertTrue(result,
                            'The expected error message is not the same')
コード例 #5
0
    def test_raise_exception_with_user_not_admin_with_keystone_v3(self, m):
        # Given
        response_with_v3 = {
            "token": {
                "roles": [{
                    "id": "8d2767fdak5k45b8a5cfc349f0b52bac",
                    "name": "owner"
                }, {
                    "id": "a6c6f50bc3kkk38ab311a9063610d383",
                    "name": "other"
                }],
                "expires_at":
                "2016-02-10T11:16:56.000000Z",
                "project": {
                    "id": "00000000000000000000960090160000",
                    "name": "admin"
                },
                "user": {
                    "id": "5a919b072cac4b02917e785f1898826e",
                    "name": "admin"
                },
                "issued_at":
                "2016-02-09T11:16:56.440835"
            }
        }

        auth = AuthorizationManager(identity_url='http://fake_url',
                                    api_version=AUTH_API_V3)

        m.get('http://fake_url/auth/tokens/', json=response_with_v3)

        try:
            # When
            auth.get_info_token(admin_token='admin_token',
                                token=self.idExpected)
        except Exception as exception:
            # Then
            self.assertEqual('Role is not admin', exception.args[0])
コード例 #6
0
    def test_raise_exception_with_user_not_admin_with_keystone_v2(self, m):
        # Given
        response_with_v2 = {
            "access": {
                "token": {
                    "expires": "2016-02-10T11:16:56Z",
                    "id": "7cd3b96409ef497587c98c8c5f596b8d"
                },
                "user": {
                    "username": "******",
                    "roles": [
                        {
                            "id": "8d27cbfdaf3845b8a5cfc349f0b52bac",
                            "name": "owner"
                        },
                        {
                            "is_default": True,
                            "id": "a6c6f50bc3ff438ab311a9063610d383",
                            "name": "other"
                        }
                    ],

                }
            }
        }

        auth = AuthorizationManager(identity_url='http://fake_url', api_version=AUTH_API_V2)

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

        try:
            # When
            auth.get_info_token(admin_token='admin_token', token='token')
        except Exception as exception:
            # Then
            self.assertEqual('Role is not admin', exception.args[0])
コード例 #7
0
    def test_receive_correct_data_from_keystone_v3(self, m):
        """
        Test the procedure to read information from catalog and extract the
        correct information from keystone v3.

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

        m.get('http://fake_url/auth/tokens/', json=self.validate_info_v3)

        tokenExpected = auth.get_info_token(admin_token='admin_token', token=self.idExpected)

        self.assertEquals(tokenExpected.expires, self.expiredExpectedv3, '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.tenantExpectedv3, 'The tenant expected is not the same')
コード例 #8
0
    def test_receive_correct_data_from_keystone_v3(self, m):
        """
        Test the procedure to read information from catalog and extract the
        correct information from keystone v3.

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

        m.get('http://fake_url/auth/tokens/', json=self.validate_info_v3)

        tokenExpected = auth.get_info_token(admin_token='admin_token',
                                            token=self.idExpected)

        self.assertEquals(tokenExpected.expires, self.expiredExpectedv3,
                          '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.tenantExpectedv3,
                          'The tenant expected is not the same')