Adds tty password entry for glanceclient
Added functionality from keystoneclient to fallback to the tty for password entry if no password is given via the environment or the --os-password option. Change-Id: I096e81b61d7f499cbda300abdc14430928d18491 Closes-Bug: 1357549
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
import argparse
|
||||
import os
|
||||
|
||||
import fixtures
|
||||
import mock
|
||||
|
||||
from glanceclient import exc
|
||||
@@ -65,6 +66,11 @@ class ShellTest(utils.TestCase):
|
||||
# expected auth plugin to invoke
|
||||
auth_plugin = 'keystoneclient.auth.identity.v2.Password'
|
||||
|
||||
# Patch os.environ to avoid required auth info
|
||||
def make_env(self, exclude=None, fake_env=FAKE_V2_ENV):
|
||||
env = dict((k, v) for k, v in fake_env.items() if k != exclude)
|
||||
self.useFixture(fixtures.MonkeyPatch('os.environ', env))
|
||||
|
||||
def setUp(self):
|
||||
super(ShellTest, self).setUp()
|
||||
global _old_env
|
||||
@@ -224,6 +230,27 @@ class ShellTest(utils.TestCase):
|
||||
glance_shell.main(args.split())
|
||||
self._assert_auth_plugin_args(mock_auth_plugin)
|
||||
|
||||
@mock.patch('sys.stdin', side_effect=mock.MagicMock)
|
||||
@mock.patch('getpass.getpass', return_value='password')
|
||||
def test_password_prompted_with_v2(self, mock_getpass, mock_stdin):
|
||||
glance_shell = openstack_shell.OpenStackImagesShell()
|
||||
self.make_env(exclude='OS_PASSWORD')
|
||||
# We will get a Connection Refused because there is no keystone.
|
||||
self.assertRaises(ks_exc.ConnectionRefused,
|
||||
glance_shell.main, ['image-list'])
|
||||
# Make sure we are actually prompted.
|
||||
mock_getpass.assert_called_with('OS Password: ')
|
||||
|
||||
@mock.patch('sys.stdin', side_effect=mock.MagicMock)
|
||||
@mock.patch('getpass.getpass', side_effect=EOFError)
|
||||
def test_password_prompted_ctrlD_with_v2(self, mock_getpass, mock_stdin):
|
||||
glance_shell = openstack_shell.OpenStackImagesShell()
|
||||
self.make_env(exclude='OS_PASSWORD')
|
||||
# We should get Command Error because we mock Ctl-D.
|
||||
self.assertRaises(exc.CommandError, glance_shell.main, ['image-list'])
|
||||
# Make sure we are actually prompted.
|
||||
mock_getpass.assert_called_with('OS Password: ')
|
||||
|
||||
|
||||
class ShellTestWithKeystoneV3Auth(ShellTest):
|
||||
# auth environment to use
|
||||
|
||||
Reference in New Issue
Block a user