summaryrefslogtreecommitdiff
path: root/openstackclient/tests/test_shell_integ.py
diff options
context:
space:
mode:
authorDean Troyer <dtroyer@gmail.com>2016-08-29 11:07:49 -0500
committerDean Troyer <dtroyer@gmail.com>2016-08-29 11:58:49 -0500
commitbec206fa0a0214d856259661c5e32086f33d2f62 (patch)
treeb03c9dfe24b8bde7f0667e572b09625f3249b8b0 /openstackclient/tests/test_shell_integ.py
parenta08b62523fa634d5a61d85d1e9f3b89ab2d4a14e (diff)
downloadpython-openstackclient-bec206fa0a0214d856259661c5e32086f33d2f62.tar.gz
Fix auth prompt brokenness
We start by fixing this in the already-present OSC_Config class so OSC can move forward. This change needs to get ported down into os-client-config in the near future, maybe even soon enough to make the client library freeze this week. * Add the pw-func argument to the OSC_Config (or OpenStackConfig) __init__() * When looping through the auth options from the KSA plugin look for any that have a prompt defined and do not have a value already, so ask for one. Closes-bug: #1617384 Change-Id: Ic86d56b8a6844516292fb74513712b486fec4442
Diffstat (limited to 'openstackclient/tests/test_shell_integ.py')
-rw-r--r--openstackclient/tests/test_shell_integ.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/openstackclient/tests/test_shell_integ.py b/openstackclient/tests/test_shell_integ.py
index bc5f1ae5..d50113b2 100644
--- a/openstackclient/tests/test_shell_integ.py
+++ b/openstackclient/tests/test_shell_integ.py
@@ -354,6 +354,64 @@ class TestShellCliV3Integ(TestShellInteg):
self.assertFalse(self.requests_mock.request_history[0].verify)
+class TestShellCliV3Prompt(TestShellInteg):
+
+ def setUp(self):
+ super(TestShellCliV3Prompt, self).setUp()
+ env = {
+ "OS_AUTH_URL": V3_AUTH_URL,
+ "OS_PROJECT_DOMAIN_ID": test_shell.DEFAULT_PROJECT_DOMAIN_ID,
+ "OS_USER_DOMAIN_ID": test_shell.DEFAULT_USER_DOMAIN_ID,
+ "OS_USERNAME": test_shell.DEFAULT_USERNAME,
+ "OS_IDENTITY_API_VERSION": "3",
+ }
+ self.useFixture(osc_lib_utils.EnvFixture(copy.deepcopy(env)))
+
+ self.token = ksa_fixture.V3Token(
+ project_domain_id=test_shell.DEFAULT_PROJECT_DOMAIN_ID,
+ user_domain_id=test_shell.DEFAULT_USER_DOMAIN_ID,
+ user_name=test_shell.DEFAULT_USERNAME,
+ )
+
+ # Set up the v3 auth routes
+ self.requests_mock.register_uri(
+ 'GET',
+ V3_AUTH_URL,
+ json=V3_VERSION_RESP,
+ status_code=200,
+ )
+ self.requests_mock.register_uri(
+ 'POST',
+ V3_AUTH_URL + 'auth/tokens',
+ json=self.token,
+ status_code=200,
+ )
+
+ @mock.patch("osc_lib.shell.prompt_for_password")
+ def test_shell_callback(self, mock_prompt):
+ mock_prompt.return_value = "qaz"
+ _shell = shell.OpenStackShell()
+ _shell.run("configuration show".split())
+
+ # Check general calls
+ self.assertEqual(len(self.requests_mock.request_history), 2)
+
+ # Check password callback set correctly
+ self.assertEqual(
+ mock_prompt,
+ _shell.cloud._openstack_config._pw_callback
+ )
+
+ # Check auth request
+ auth_req = self.requests_mock.request_history[1].json()
+
+ # Check returned password from prompt function
+ self.assertEqual(
+ "qaz",
+ auth_req['auth']['identity']['password']['user']['password'],
+ )
+
+
class TestShellCliPrecedence(TestShellInteg):
"""Validate option precedence rules without clouds.yaml