예제 #1
0
 def test_is_token_valid_keystone_v2_invalid_location(self, mock_get):
     client_backup = tokens.v2_client.Client
     tokens.v2_client.Client = mock.MagicMock()
     self.assertRaises(ValueError, tokens.is_token_valid, 'a', 'b',
                       tokens.TokenConf('a', 'b', 'c', 'd', '2.0'), 'test',
                       {'domain': 'test'})
     tokens.v2_client.Client = client_backup
예제 #2
0
 def test_is_token_valid_token_not_found(self, mock_get):
     client_backup = tokens.v3_client.Client
     tokens.v3_client.Client = mock.MagicMock(return_value=MyClient())
     self.assertFalse(
         tokens.is_token_valid('a', 'b',
                               tokens.TokenConf('a', 'b', 'c', 'd', '3')))
     tokens.v3_client.Client = client_backup
예제 #3
0
 def test_is_token_valid_sanity_role_required(self, mock_get, mock_client):
     user = {'user': {'id': 'test_id', 'domain': {'id': 'test'}}}
     mock_client.tokens.validate = mock.MagicMock(return_value=user)
     self.assertTrue(
         tokens.is_token_valid('a', 'b',
                               tokens.TokenConf('a', 'b', 'c', 'd', '3'),
                               'test', {'domain': 'test'}))
예제 #4
0
 def test_is_token_valid_keystone_v2(self, mock_get):
     client_backup = tokens.v2_client.Client
     tokens.v2_client.Client = mock.MagicMock()
     self.assertFalse(
         tokens.is_token_valid('a', 'b',
                               tokens.TokenConf('a', 'b', 'c', 'd', '2.0'),
                               'test', {'tenant': 'test'}))
     tokens.v2_client.Client = client_backup
예제 #5
0
def _get_token_conf(app_conf):
    mech_id = app_conf.authentication.mech_id
    mech_password = app_conf.authentication.mech_pass
    rms_url = app_conf.authentication.rms_url
    tenant_name = app_conf.authentication.tenant_name
    keystone_version = app_conf.authentication.keystone_version
    conf = tokens.TokenConf(mech_id, mech_password, rms_url, tenant_name,
                            keystone_version)
    return conf
예제 #6
0
def get_token_conf(app_conf):
    mech_id = app_conf.authentication.mech_id
    mech_password = app_conf.authentication.mech_pass
    # RMS URL is not necessary since this service is RMS
    rms_url = ''
    tenant_name = app_conf.authentication.tenant_name
    keystone_version = app_conf.authentication.keystone_version
    conf = tokens.TokenConf(mech_id, mech_password, rms_url, tenant_name,
                            keystone_version)
    return conf
예제 #7
0
    def test_get_token_user_success(self, mock_get_keystone_client):
        token_info = mock.MagicMock()
        token_info.token = 'a'
        token_info.user = '******'
        ks = mock.MagicMock()
        ks.tokens.validate.return_value = token_info
        mock_get_keystone_client.return_value = ks

        conf = tokens.TokenConf(*('2.0', ) * 5)
        result = tokens.get_token_user('a', conf, 'c', 'd')

        self.assertEqual(result.token, 'a')
        self.assertEqual(result.user, 'test_user')
예제 #8
0
def _get_token_conf():
    conf = tokens.TokenConf(mech_id, mech_password, rms_url, tenant_name)
    return conf
예제 #9
0
 def test_get_token_user_token_not_found(self, mock_get_keystone_client):
     ks = mock.MagicMock()
     ks.tokens.validate.side_effect = exceptions.NotFound()
     mock_get_keystone_client.return_value = ks
     conf = tokens.TokenConf(*('3', ) * 5)
     self.assertIsNone(tokens.get_token_user('a', conf, 'c', 'd'))
예제 #10
0
 def test_get_token_user_invalid_keystone_version(self):
     conf = tokens.TokenConf(*(None, ) * 5)
     self.assertRaises(ValueError, tokens.get_token_user, 'a', conf, 'c',
                       'd')
예제 #11
0
 def test_is_token_valid_role_does_not_exist(self, mock_get):
     tokens.v3_client.Client = mock.MagicMock(return_value=MyClient(False))
     self.assertRaises(ValueError, tokens.is_token_valid, 'a', 'b',
                       tokens.TokenConf('a', 'b', 'c', 'd', '3'), 'test',
                       {'domain': 'test'})
예제 #12
0
 def test_is_token_valid_no_role_location(self, mock_get):
     tokens.v3_client.Client = mock.MagicMock()
     self.assertRaises(ValueError, tokens.is_token_valid, 'a', 'b',
                       tokens.TokenConf('a', 'b', 'c', 'd', '3'), 'test')
예제 #13
0
 def test_is_token_valid_keystone_ep_not_found(self, mock_get):
     self.assertRaises(tokens.KeystoneNotFoundError, tokens.is_token_valid,
                       'a', 'b', tokens.TokenConf('a', 'b', 'c', 'd', '3'))
예제 #14
0
 def test_is_token_valid_invalid_version(self, mock_get):
     client_backup = tokens.v3_client.Client
     tokens.v3_client.Client = mock.MagicMock(return_value=MyClient())
     self.assertRaises(ValueError, tokens.is_token_valid, 'a', 'b',
                       tokens.TokenConf('a', 'b', 'c', 'd', '4'))
     tokens.v3_client.Client = client_backup
예제 #15
0
 def test_is_token_valid_sanity(self, mock_get, mock_client):
     self.assertTrue(
         tokens.is_token_valid('a', 'b',
                               tokens.TokenConf('a', 'b', 'c', 'd', '3')))