Esempio n. 1
0
    def test_retrieve_keystone_bad_client_authorization_error(self):
        url = 'myurl'
        tenant_id = '789012345'
        token = 'abcdefABCDEF'
        bttl = 5

        redis_client = fakeredis_connection()

        with mock.patch(
                'keystoneclient.v2_0.client.Client') as MockKeystoneClient:
            MockKeystoneClient.side_effect = exceptions.Unauthorized(
                'Mock - invalid client object')
            keystone_create_error = auth._retrieve_data_from_keystone(
                redis_client,
                url,
                tenant_id,
                token,
                bttl,
                self.default_max_cache_life)
            self.assertIsNone(keystone_create_error)

        with mock.patch(
                'keystoneclient.v2_0.client.Client') as MockKeystoneClient:
            MockKeystoneClient.side_effect = exceptions.AuthorizationFailure(
                'Mock - invalid client object')
            keystone_create_error = auth._retrieve_data_from_keystone(
                redis_client,
                url,
                tenant_id,
                token,
                bttl,
                self.default_max_cache_life)
            self.assertIsNone(keystone_create_error)
Esempio n. 2
0
    def test_retrieve_keystone_bad_client_authorization_error(self):
        url = 'myurl'
        tenant_id = '789012345'
        token = 'abcdefABCDEF'
        bttl = 5

        redis_client = fakeredis_connection()

        with mock.patch(
                'keystoneclient.v2_0.client.Client') as MockKeystoneClient:
            MockKeystoneClient.side_effect = exceptions.Unauthorized(
                'Mock - invalid client object')
            keystone_create_error = auth._retrieve_data_from_keystone(
                redis_client, url, tenant_id, token, bttl,
                self.default_max_cache_life)
            self.assertIsNone(keystone_create_error)

        with mock.patch(
                'keystoneclient.v2_0.client.Client') as MockKeystoneClient:
            MockKeystoneClient.side_effect = exceptions.AuthorizationFailure(
                'Mock - invalid client object')
            keystone_create_error = auth._retrieve_data_from_keystone(
                redis_client, url, tenant_id, token, bttl,
                self.default_max_cache_life)
            self.assertIsNone(keystone_create_error)
Esempio n. 3
0
    def test__retrieve_data_from_keystone_alt_auth(self):
        redis_client = fakeredis_connection()

        tenant_id = '172839405'
        token = 'AaBbCcDdEeFf'
        url = 'myurl'
        bttl = 5

        with mock.patch('eom.auth.get_conf') as mock_auth_conf:
            with mock.patch('requests.get') as mock_requests:
                mock_auth_conf.return_value.alternate_validation = True
                cat = servicecatalog.ServiceCatalogGenerator(token, tenant_id)
                resp_json = cat.generate_without_catalog()
                mock_requests.return_value.json.return_value = resp_json
                mock_requests.return_value.status_code = 200

                access_info = auth._retrieve_data_from_keystone(
                    redis_client,
                    url,
                    tenant_id,
                    token,
                    bttl,
                    self.default_max_cache_life
                )

                self.assertEqual(
                    access_info,
                    access.AccessInfoV2(
                        cat.generate_without_catalog()['access']
                    )
                )
Esempio n. 4
0
    def test_retrieve_keystone_check_credentials(self):
        url = 'myurl'
        bttl = 5

        redis_client = fakeredis_connection()

        with mock.patch(
                'keystoneclient.v2_0.client.Client') as MockKeystoneClient:
            MockKeystoneClient.return_value = (
                fake_client_object_check_credentials())

            credential_sets = [{
                'projectid': 'valid_projectid',
                'authtoken': 'valid_token',
                'is_none': False
            }, {
                'projectid': None,
                'authtoken': 'valid_token',
                'is_none': True
            }, {
                'projectid': 'valid_projectid',
                'authtoken': None,
                'is_none': True
            }, {
                'projectid': None,
                'authtoken': None,
                'is_none': True
            }, {
                'projectid': 'invalid_projectid',
                'authtoken': 'valid_token',
                'is_none': True
            }, {
                'projectid': 'valid_projectid',
                'authtoken': 'invalid_token',
                'is_none': True
            }, {
                'projectid': 'invalid_projectid',
                'authtoken': 'invalid_token',
                'is_none': True
            }]

            for creds in credential_sets:
                keystone_error = auth._retrieve_data_from_keystone(
                    redis_client, url, creds['projectid'], creds['authtoken'],
                    bttl, self.default_max_cache_life)
                if creds['is_none']:
                    self.assertIsNone(keystone_error)
                else:
                    self.assertIsNotNone(keystone_error)
Esempio n. 5
0
    def test_retrieve_keystone_bad_identity_access(self):
        url = 'myurl'
        tenant_id = '789012345'
        token = 'abcdefABCDEF'
        bttl = 5

        redis_client = fakeredis_connection()

        with mock.patch(
                'keystoneclient.v2_0.client.Client') as MockKeystoneClient:
            MockKeystoneClient.return_value = fake_client_object_raise()
            # Fail to get a valid Client object
            # Note: Client() uses the requests package to do an auth;
            #   on failure it is the requests module that fails.
            keystone_error = auth._retrieve_data_from_keystone(
                redis_client, url, tenant_id, token, bttl,
                self.default_max_cache_life)
            self.assertIsNone(keystone_error)
Esempio n. 6
0
    def test_retrieve_keystone_bad_identity_access(self):
        url = 'myurl'
        tenant_id = '789012345'
        token = 'abcdefABCDEF'
        bttl = 5

        redis_client = fakeredis_connection()

        with mock.patch(
                'keystoneclient.v2_0.client.Client') as MockKeystoneClient:
            MockKeystoneClient.return_value = fake_client_object_raise()
            # Fail to get a valid Client object
            # Note: Client() uses the requests package to do an auth;
            #   on failure it is the requests module that fails.
            keystone_error = auth._retrieve_data_from_keystone(
                redis_client,
                url,
                tenant_id,
                token,
                bttl,
                self.default_max_cache_life)
            self.assertIsNone(keystone_error)
Esempio n. 7
0
    def test__retrieve_data_from_keystone_alt_auth(self):
        redis_client = fakeredis_connection()

        tenant_id = '172839405'
        token = 'AaBbCcDdEeFf'
        url = 'myurl'
        bttl = 5

        with mock.patch('eom.auth.get_conf') as mock_auth_conf:
            with mock.patch('requests.get') as mock_requests:
                mock_auth_conf.return_value.alternate_validation = True
                cat = servicecatalog.ServiceCatalogGenerator(token, tenant_id)
                resp_json = cat.generate_without_catalog()
                mock_requests.return_value.json.return_value = resp_json
                mock_requests.return_value.status_code = 200

                access_info = auth._retrieve_data_from_keystone(
                    redis_client, url, tenant_id, token, bttl,
                    self.default_max_cache_life)

                self.assertEqual(
                    access_info,
                    access.AccessInfoV2(
                        cat.generate_without_catalog()['access']))
Esempio n. 8
0
    def test_retrieve_keystone_check_credentials(self):
        url = 'myurl'
        bttl = 5

        redis_client = fakeredis_connection()

        with mock.patch(
                'keystoneclient.v2_0.client.Client') as MockKeystoneClient:
            MockKeystoneClient.return_value = (
                fake_client_object_check_credentials())

            credential_sets = [
                {
                    'projectid': 'valid_projectid',
                    'authtoken': 'valid_token',
                    'is_none': False
                },
                {
                    'projectid': None,
                    'authtoken': 'valid_token',
                    'is_none': True
                },
                {
                    'projectid': 'valid_projectid',
                    'authtoken': None,
                    'is_none': True
                },
                {
                    'projectid': None,
                    'authtoken': None,
                    'is_none': True
                },
                {
                    'projectid': 'invalid_projectid',
                    'authtoken': 'valid_token',
                    'is_none': True
                },
                {
                    'projectid': 'valid_projectid',
                    'authtoken': 'invalid_token',
                    'is_none': True
                },
                {
                    'projectid': 'invalid_projectid',
                    'authtoken': 'invalid_token',
                    'is_none': True
                }
            ]

            for creds in credential_sets:
                keystone_error = auth._retrieve_data_from_keystone(
                    redis_client,
                    url,
                    creds['projectid'],
                    creds['authtoken'],
                    bttl,
                    self.default_max_cache_life)
                if creds['is_none']:
                    self.assertIsNone(keystone_error)
                else:
                    self.assertIsNotNone(keystone_error)