Coverage for manila/tests/common/test_client_auth.py: 100%
55 statements
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
1# Copyright 2016 SAP SE
2# All Rights Reserved
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
16from unittest import mock
18from keystoneauth1 import loading as auth
19from oslo_config import cfg
21from manila.common import client_auth
22from manila import exception
23from manila import test
24from manila.tests import fake_client_exception_class
27class ClientAuthTestCase(test.TestCase):
28 def setUp(self):
29 super(ClientAuthTestCase, self).setUp()
30 self.context = mock.Mock()
31 self.fake_client = mock.Mock()
32 self.exception_mod = fake_client_exception_class
33 self.auth = client_auth.AuthClientLoader(self.fake_client, 'foo_group')
35 def test_get_client_admin_true(self):
36 mock_load_session = self.mock_object(auth,
37 'load_session_from_conf_options')
39 self.auth.get_client(self.context, admin=True)
41 mock_load_session.assert_called_once_with(client_auth.CONF,
42 'foo_group')
43 self.fake_client.assert_called_once_with(
44 session=mock_load_session(),
45 auth=auth.load_auth_from_conf_options(
46 client_auth.CONF, 'foo_group'))
48 def test_get_client_admin_false(self):
49 self.mock_object(auth, 'load_session_from_conf_options')
51 self.assertRaises(exception.ManilaException, self.auth.get_client,
52 self.context, admin=False)
54 def test_load_auth_plugin_caching(self):
55 self.auth.admin_auth = 'admin obj'
56 result = self.auth._load_auth_plugin()
58 self.assertEqual(self.auth.admin_auth, result)
60 def test_load_auth_plugin_no_auth(self):
61 auth.load_auth_from_conf_options.return_value = None
63 self.assertRaises(exception.BadConfigurationException,
64 self.auth._load_auth_plugin)
66 @mock.patch.object(auth, 'get_session_conf_options')
67 @mock.patch.object(auth, 'get_auth_common_conf_options')
68 @mock.patch.object(auth, 'get_auth_plugin_conf_options')
69 def test_list_opts(self, auth_conf, common_conf, session_conf):
70 session_conf.return_value = [cfg.StrOpt('username'),
71 cfg.StrOpt('password')]
72 common_conf.return_value = ([cfg.StrOpt('auth_url')])
73 auth_conf.return_value = [cfg.StrOpt('password')]
75 result = client_auth.AuthClientLoader.list_opts("foo_group")
77 self.assertEqual('foo_group', result[0][0])
78 for entry in result[0][1]:
79 self.assertIn(entry.name, ['username', 'auth_url', 'password'])
80 common_conf.assert_called_once_with()
81 auth_conf.assert_called_once_with('password')
83 @mock.patch.object(auth, 'get_session_conf_options')
84 @mock.patch.object(auth, 'get_auth_common_conf_options')
85 @mock.patch.object(auth, 'get_auth_plugin_conf_options')
86 def test_list_opts_not_found(self, auth_conf, common_conf, session_conf):
87 session_conf.return_value = [cfg.StrOpt('username'),
88 cfg.StrOpt('password')]
89 common_conf.return_value = ([cfg.StrOpt('auth_url')])
90 auth_conf.return_value = [cfg.StrOpt('tenant')]
92 result = client_auth.AuthClientLoader.list_opts("foo_group")
94 self.assertEqual('foo_group', result[0][0])
95 for entry in result[0][1]:
96 self.assertIn(entry.name, ['username', 'auth_url', 'password',
97 'tenant'])
98 common_conf.assert_called_once_with()
99 auth_conf.assert_called_once_with('password')