From b8bf448dbe9de9972bdd5fd0aa433e96e64913d6 Mon Sep 17 00:00:00 2001 From: Mike Fedosin Date: Sat, 4 Nov 2017 14:24:17 +0300 Subject: [PATCH] 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 aa65b57816bd29e31355b8cecc9b20d10b0aa307) --- mistralclient/api/v2/client.py | 9 +++++++-- mistralclient/tests/unit/test_client.py | 16 +++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/mistralclient/api/v2/client.py b/mistralclient/api/v2/client.py index 166cbf88..0c571684 100644 --- a/mistralclient/api/v2/client.py +++ b/mistralclient/api/v2/client.py @@ -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) diff --git a/mistralclient/tests/unit/test_client.py b/mistralclient/tests/unit/test_client.py index 7348e885..e4fab80f 100644 --- a/mistralclient/tests/unit/test_client.py +++ b/mistralclient/tests/unit/test_client.py @@ -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)