Support no_auth mode in mistral client

Now it is impossible to send requests without authentication.
This patch allows to disable it if user doesn't provide auth_url
to the client.

Change-Id: I3b964e349dd6843ceb022264abe451a1b407786b
Closes-bug: #1730067
(cherry picked from commit aa65b57816)
This commit is contained in:
Mike Fedosin
2017-11-04 14:24:17 +03:00
parent 291501ae6d
commit b8bf448dbe
2 changed files with 22 additions and 3 deletions

View File

@@ -49,8 +49,13 @@ class Client(object):
if mistral_url and not isinstance(mistral_url, six.string_types):
raise RuntimeError('Mistral url should be a string.')
auth_handler = auth.get_auth_handler(auth_type)
auth_response = auth_handler.authenticate(req, session=session) or {}
# If auth url was provided then we perform an authentication, otherwise
# just ignore this step
if req.get('auth_url'):
auth_handler = auth.get_auth_handler(auth_type)
auth_response = auth_handler.authenticate(req, session=session)
else:
auth_response = {}
req.update(auth_response)

View File

@@ -127,10 +127,11 @@ class BaseClientTests(base.BaseTestCase):
keystone_client_mock
)
url_for = mock.Mock(return_value='http://mistral_host:8989/v2')
url_for = mock.Mock(return_value=MISTRAL_HTTP_URL)
keystone_client_instance.service_catalog.url_for = url_for
client.client(
auth_url=AUTH_HTTP_URL_v3,
target_username='tmistral',
target_project_name='tmistralp',
target_auth_url=AUTH_HTTP_URL_v3,
@@ -274,3 +275,16 @@ class BaseClientTests(base.BaseTestCase):
profiler = osprofiler.profiler.get()
self.assertEqual(profiler.hmac_key, PROFILER_HMAC_KEY)
@mock.patch('mistralclient.auth.get_auth_handler')
def test_mistral_no_auth(self, get_auth_handler_mock):
# Test that we don't authenticate if auth url wasn't provided
client.client(
username='mistral',
project_name='mistral',
api_key='password',
service_type='workflowv2'
)
self.assertEqual(0, get_auth_handler_mock.call_count)