Fixes Auth Token being sent as lambda function

Change-Id: Id6d7db4b2d3c7350147b26d42fc77f66a530a29b
Closes-Bug: #1244810
This commit is contained in:
Kevin McDonald 2013-10-25 16:57:52 -05:00
parent bce795f2fe
commit 94e0fb78e4
3 changed files with 65 additions and 2 deletions

View File

@ -73,9 +73,9 @@ def get_client(api_version, **kwargs):
'insecure': kwargs.get('insecure'),
}
_ksclient = _get_ksclient(**ks_kwargs)
token = ((lambda: kwargs.get('os_auth_token'))
token = (kwargs.get('os_auth_token')
if kwargs.get('os_auth_token')
else (lambda: _ksclient.auth_token))
else _ksclient.auth_token)
endpoint = kwargs.get('ironic_url') or \
_get_endpoint(_ksclient, **ks_kwargs)

View File

@ -0,0 +1,51 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import fixtures
from ironicclient.client import get_client
from ironicclient.tests import utils
def fake_get_ksclient(**kwargs):
return utils.FakeKeystone('KSCLIENT_AUTH_TOKEN')
class ClientTest(utils.BaseTestCase):
def test_get_client_no_auth_token(self):
self.useFixture(fixtures.MonkeyPatch(
'ironicclient.client._get_ksclient', fake_get_ksclient))
kwargs = {
'os_tenant_name': 'TENANT_NAME',
'os_username': 'USERNAME',
'os_password': 'PASSWORD',
'os_auth_url': 'http://localhost:35357/v2.0',
'os_auth_token': '',
}
client = get_client('1', **kwargs)
self.assertEqual(client.auth_token, 'KSCLIENT_AUTH_TOKEN')
def test_get_client_with_auth_token(self):
self.useFixture(fixtures.MonkeyPatch(
'ironicclient.client._get_ksclient', fake_get_ksclient))
kwargs = {
'os_tenant_name': 'TENANT_NAME',
'os_username': 'USERNAME',
'os_password': 'PASSWORD',
'os_auth_url': 'http://localhost:35357/v2.0',
'os_auth_token': 'USER_AUTH_TOKEN',
}
client = get_client('1', **kwargs)
self.assertEqual(client.auth_token, 'USER_AUTH_TOKEN')

View File

@ -64,3 +64,15 @@ class FakeResponse(object):
def read(self, amt):
return self.body.read(amt)
class FakeServiceCatalog():
def url_for(self, endpoint_type, service_type):
return 'http://localhost:6385/v1/f14b41234'
class FakeKeystone():
service_catalog = FakeServiceCatalog()
def __init__(self, auth_token):
self.auth_token = auth_token