2015-07-19 12:15:04 -06:00
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
|
2020-01-10 14:21:47 -06:00
|
|
|
from unittest import mock
|
2016-06-20 12:37:22 +02:00
|
|
|
|
2015-07-19 12:15:04 -06:00
|
|
|
from openstackclient.common import configuration
|
2016-09-05 22:14:33 -07:00
|
|
|
from openstackclient.tests.unit import fakes
|
|
|
|
from openstackclient.tests.unit import utils
|
2015-07-19 12:15:04 -06:00
|
|
|
|
|
|
|
|
|
|
|
class TestConfiguration(utils.TestCommand):
|
2016-01-09 11:39:01 +05:30
|
|
|
columns = (
|
|
|
|
'auth.password',
|
|
|
|
'auth.token',
|
|
|
|
'auth.username',
|
|
|
|
'identity_api_version',
|
|
|
|
'region',
|
|
|
|
)
|
|
|
|
datalist = (
|
|
|
|
configuration.REDACTED,
|
|
|
|
configuration.REDACTED,
|
|
|
|
fakes.USERNAME,
|
|
|
|
fakes.VERSION,
|
|
|
|
fakes.REGION_NAME,
|
|
|
|
)
|
|
|
|
|
2021-10-09 12:05:43 +09:00
|
|
|
opts = [
|
|
|
|
mock.Mock(secret=True, dest="password"),
|
|
|
|
mock.Mock(secret=True, dest="token"),
|
|
|
|
]
|
2016-06-20 12:37:22 +02:00
|
|
|
|
2021-10-09 12:05:43 +09:00
|
|
|
@mock.patch(
|
|
|
|
"keystoneauth1.loading.base.get_plugin_options", return_value=opts
|
|
|
|
)
|
2016-06-20 12:37:22 +02:00
|
|
|
def test_show(self, m_get_plugin_opts):
|
2015-07-19 12:15:04 -06:00
|
|
|
arglist = []
|
|
|
|
verifylist = [('mask', True)]
|
|
|
|
cmd = configuration.ShowConfiguration(self.app, None)
|
|
|
|
parsed_args = self.check_parser(cmd, arglist, verifylist)
|
|
|
|
|
|
|
|
columns, data = cmd.take_action(parsed_args)
|
|
|
|
|
2016-01-09 11:39:01 +05:30
|
|
|
self.assertEqual(self.columns, columns)
|
|
|
|
self.assertEqual(self.datalist, data)
|
2015-07-19 12:15:04 -06:00
|
|
|
|
2021-10-09 12:05:43 +09:00
|
|
|
@mock.patch(
|
|
|
|
"keystoneauth1.loading.base.get_plugin_options", return_value=opts
|
|
|
|
)
|
2016-06-20 12:37:22 +02:00
|
|
|
def test_show_unmask(self, m_get_plugin_opts):
|
2015-07-19 12:15:04 -06:00
|
|
|
arglist = ['--unmask']
|
|
|
|
verifylist = [('mask', False)]
|
|
|
|
cmd = configuration.ShowConfiguration(self.app, None)
|
2021-10-09 12:05:43 +09:00
|
|
|
|
2015-07-19 12:15:04 -06:00
|
|
|
parsed_args = self.check_parser(cmd, arglist, verifylist)
|
|
|
|
|
|
|
|
columns, data = cmd.take_action(parsed_args)
|
|
|
|
|
2016-01-09 11:39:01 +05:30
|
|
|
self.assertEqual(self.columns, columns)
|
2015-07-19 12:15:04 -06:00
|
|
|
datalist = (
|
|
|
|
fakes.PASSWORD,
|
|
|
|
fakes.AUTH_TOKEN,
|
|
|
|
fakes.USERNAME,
|
|
|
|
fakes.VERSION,
|
|
|
|
fakes.REGION_NAME,
|
|
|
|
)
|
2016-01-09 11:39:01 +05:30
|
|
|
self.assertEqual(datalist, data)
|
2015-07-19 12:15:04 -06:00
|
|
|
|
2021-10-09 12:05:43 +09:00
|
|
|
@mock.patch(
|
|
|
|
"keystoneauth1.loading.base.get_plugin_options", return_value=opts
|
|
|
|
)
|
|
|
|
def test_show_mask_with_cloud_config(self, m_get_plugin_opts):
|
2015-07-19 12:15:04 -06:00
|
|
|
arglist = ['--mask']
|
|
|
|
verifylist = [('mask', True)]
|
2021-10-09 12:05:43 +09:00
|
|
|
self.app.client_manager.configuration_type = "cloud_config"
|
2015-07-19 12:15:04 -06:00
|
|
|
cmd = configuration.ShowConfiguration(self.app, None)
|
2021-10-09 12:05:43 +09:00
|
|
|
|
2015-07-19 12:15:04 -06:00
|
|
|
parsed_args = self.check_parser(cmd, arglist, verifylist)
|
|
|
|
|
|
|
|
columns, data = cmd.take_action(parsed_args)
|
|
|
|
|
2016-01-09 11:39:01 +05:30
|
|
|
self.assertEqual(self.columns, columns)
|
|
|
|
self.assertEqual(self.datalist, data)
|
2021-10-09 12:05:43 +09:00
|
|
|
|
|
|
|
@mock.patch(
|
|
|
|
"keystoneauth1.loading.base.get_plugin_options", return_value=opts
|
|
|
|
)
|
|
|
|
def test_show_mask_with_global_env(self, m_get_plugin_opts):
|
|
|
|
arglist = ['--mask']
|
|
|
|
verifylist = [('mask', True)]
|
|
|
|
self.app.client_manager.configuration_type = "global_env"
|
|
|
|
column_list = (
|
|
|
|
'identity_api_version',
|
|
|
|
'password',
|
|
|
|
'region',
|
|
|
|
'token',
|
|
|
|
'username',
|
|
|
|
)
|
|
|
|
datalist = (
|
|
|
|
fakes.VERSION,
|
|
|
|
configuration.REDACTED,
|
|
|
|
fakes.REGION_NAME,
|
|
|
|
configuration.REDACTED,
|
|
|
|
fakes.USERNAME,
|
|
|
|
)
|
|
|
|
|
|
|
|
cmd = configuration.ShowConfiguration(self.app, None)
|
|
|
|
|
|
|
|
parsed_args = self.check_parser(cmd, arglist, verifylist)
|
|
|
|
|
|
|
|
columns, data = cmd.take_action(parsed_args)
|
|
|
|
|
|
|
|
self.assertEqual(column_list, columns)
|
|
|
|
self.assertEqual(datalist, data)
|