コード例 #1
0
    def test_init_trust_token_none(self, mock_ks):
        self.ctx.project_id = None
        self.ctx.trust_id = None
        self.ctx.auth_token_info = {'not_this': 'urg'}

        magnum_ks_client = magnum_keystoneclient.KeystoneClientV3(self.ctx)
        self.assertRaises(exception.AuthorizationFailure,
                          magnum_ks_client._v3_client_init)
コード例 #2
0
 def test_init_v3_bad_nocreds(self, mock_ks):
     """Test creating the client, no credentials."""
     self.ctx.auth_token = None
     self.ctx.trust_id = None
     self.ctx.username = None
     magnum_ks_client = magnum_keystoneclient.KeystoneClientV3(self.ctx)
     self.assertRaises(exception.AuthorizationFailure,
                       magnum_ks_client._v3_client_init)
コード例 #3
0
    def test_client_is_admin(self, mock_admin_creds, mock_ks):
        """Test client is admin when passing an admin_context."""
        self.ctx.is_admin = True
        magnum_ks_client = magnum_keystoneclient.KeystoneClientV3(self.ctx)
        magnum_ks_client.client

        self.assertIsNone(magnum_ks_client._client)
        self.assertIsNotNone(magnum_ks_client._admin_client)
        mock_admin_creds.assert_called_once_with()
コード例 #4
0
 def test_init_v3_token(self, mock_ks):
     """Test creating the client, token auth."""
     self.ctx.project_id = None
     self.ctx.trust_id = None
     magnum_ks_client = magnum_keystoneclient.KeystoneClientV3(self.ctx)
     magnum_ks_client.client
     self.assertIsNotNone(magnum_ks_client._client)
     mock_ks.assert_called_once_with(token='abcd1234', project_id=None,
                                     auth_url='http://server.test:5000/v3',
                                     endpoint='http://server.test:5000/v3')
     mock_ks.return_value.authenticate.assert_called_once_with()
コード例 #5
0
    def test_init_trust_token_token(self, mock_ks):
        self.ctx.project_id = None
        self.ctx.trust_id = None
        self.ctx.auth_token_info = {'token': {}}

        magnum_ks_client = magnum_keystoneclient.KeystoneClientV3(self.ctx)
        magnum_ks_client.client
        self.assertIsNotNone(magnum_ks_client._client)
        mock_ks.assert_called_once_with(auth_ref={'auth_token': 'abcd1234',
                                                  'version': 'v3'},
                                        endpoint='http://server.test:5000/v3',
                                        auth_url='http://server.test:5000/v3')
コード例 #6
0
 def test_trust_init_token(self, mock_ks):
     """Test trust_id takes precedence when token specified."""
     self.ctx.username = None
     self.ctx.trust_id = 'atrust123'
     magnum_ks_client = magnum_keystoneclient.KeystoneClientV3(self.ctx)
     self.assertIsNotNone(magnum_ks_client._client)
     mock_ks.assert_called_once_with(username='******',
                                     auth_url='http://server.test:5000/v3',
                                     password='******',
                                     endpoint='http://server.test:5000/v3',
                                     trust_id='atrust123')
     mock_ks.return_value.authenticate.assert_called_once_with()
コード例 #7
0
    def test_create_trust_context_trust_id(self, mock_ks):
        """Test create_trust_context with existing trust_id."""
        self.ctx.trust_id = 'atrust123'

        magnum_ks_client = magnum_keystoneclient.KeystoneClientV3(self.ctx)
        trust_context = magnum_ks_client.create_trust_context()
        self.assertEqual(self.ctx.to_dict(), trust_context.to_dict())
        mock_ks.assert_called_once_with(username='******',
                                        auth_url='http://server.test:5000/v3',
                                        password='******',
                                        endpoint='http://server.test:5000/v3',
                                        trust_id='atrust123')
        mock_ks.return_value.authenticate.assert_called_once_with()
コード例 #8
0
    def test_init_trust_token_access(self, mock_ks):
        """Test creating the client, token auth."""
        self.ctx.project_id = 'abcd1234'
        self.ctx.trust_id = None
        self.ctx.auth_token_info = {'access': {'token': {'id': 'placeholder'}}}

        magnum_ks_client = magnum_keystoneclient.KeystoneClientV3(self.ctx)
        magnum_ks_client.client
        self.assertIsNotNone(magnum_ks_client._client)
        mock_ks.assert_called_once_with(auth_ref={'version': 'v2.0',
                                                  'token': {
                                                      'id': 'abcd1234'}},
                                        endpoint='http://server.test:5000/v3',
                                        auth_url='http://server.test:5000/v3')
コード例 #9
0
    def test_init_admin_client_denied(self, mock_ks):
        """Test the admin_client property, auth failure path."""
        self.ctx.username = None
        self.ctx.password = None
        self.ctx.trust_id = None
        mock_ks.return_value.authenticate.return_value = False

        magnum_ks_client = magnum_keystoneclient.KeystoneClientV3(self.ctx)

        # Define wrapper for property or the property raises the exception
        # outside of the assertRaises which fails the test
        def get_admin_client():
            magnum_ks_client.admin_client

        self.assertRaises(exception.AuthorizationFailure, get_admin_client)
コード例 #10
0
    def test_create_trust_context_trust_create(self, mock_ks):
        """Test create_trust_context when creating a trust."""
        class FakeTrust(object):
            id = 'atrust123'

        cfg.CONF.set_override('trusts_delegated_roles',
                              ['magnum_assembly_update'])

        getter_mock = mock.PropertyMock(side_effect=['1234', '5678'])
        type(mock_ks.return_value.auth_ref).user_id = getter_mock

        mock_ks.return_value.auth_ref.project_id = '42'
        mock_ks.return_value.trusts.create.return_value = FakeTrust()
        self.ctx.trust_id = None

        magnum_ks_client = magnum_keystoneclient.KeystoneClientV3(self.ctx)
        trust_context = magnum_ks_client.create_trust_context()

        # admin_client and user client
        expected = [
            mock.call(username='******',
                      project_name='service',
                      password='******',
                      auth_url='http://server.test:5000/v3',
                      endpoint='http://server.test:5000/v3'),
            mock.call(token='abcd1234',
                      project_id='test_tenant_id',
                      auth_url='http://server.test:5000/v3',
                      endpoint='http://server.test:5000/v3')
        ]

        self.assertEqual(expected, mock_ks.call_args_list)
        self.assertEqual([mock.call(), mock.call()],
                         mock_ks.return_value.authenticate.call_args_list)

        # trust creation
        self.assertEqual('atrust123', trust_context.trust_id)
        mock_ks.return_value.trusts.create.assert_called_once_with(
            trustor_user='******',
            trustee_user='******',
            project='42',
            impersonation=True,
            role_names=['magnum_assembly_update'])
コード例 #11
0
    def keystone(self):
        if self._keystone:
            return self._keystone

        self._keystone = magnum_keystoneclient.KeystoneClientV3(self.context)
        return self._keystone
コード例 #12
0
 def test_delete_trust_not_found(self, mock_ks):
     """Test delete_trust when trust already deleted."""
     mock_delete = mock_ks.return_value.trusts.delete
     mock_delete.side_effect = kc_exception.NotFound()
     magnum_ks_client = magnum_keystoneclient.KeystoneClientV3(self.ctx)
     self.assertIsNone(magnum_ks_client.delete_trust(trust_id='atrust123'))
コード例 #13
0
 def test_delete_trust(self, mock_ks):
     """Test delete_trust when deleting trust."""
     mock_ks.return_value.trusts.delete.return_value = None
     magnum_ks_client = magnum_keystoneclient.KeystoneClientV3(self.ctx)
     self.assertIsNone(magnum_ks_client.delete_trust(trust_id='atrust123'))
     mock_ks.return_value.trusts.delete.assert_called_once_with('atrust123')