From aa65b57816bd29e31355b8cecc9b20d10b0aa307 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 --- mistralclient/api/v2/client.py | 9 +++++++-- mistralclient/tests/unit/test_client.py | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/mistralclient/api/v2/client.py b/mistralclient/api/v2/client.py index 123e88b5..880083bb 100644 --- a/mistralclient/api/v2/client.py +++ b/mistralclient/api/v2/client.py @@ -51,8 +51,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 = {} # If the session was None and we're using keystone auth, it will be # created by the auth_handler. diff --git a/mistralclient/tests/unit/test_client.py b/mistralclient/tests/unit/test_client.py index ebeadf6b..20f59ff2 100644 --- a/mistralclient/tests/unit/test_client.py +++ b/mistralclient/tests/unit/test_client.py @@ -141,6 +141,7 @@ class BaseClientTests(base.BaseTestCase): auth.get_access = mock.Mock(return_value=mock_access) client.client( + auth_url=AUTH_HTTP_URL_v3, username='user', api_key='password', user_domain_name='Default', @@ -303,3 +304,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)