Fix authentication issue

Fix authentication issue if password is provided from tty prompt.
Set options.os_password to user input from prompt, as it gets
used to create auth object otherwise it will give authentication error.

Change-Id: I0246473f2165f1464d731e0ae9b4afa0b61dcbcc
Closes-Bug: #1575656
This commit is contained in:
Abhijeet Malawade 2016-04-27 04:40:17 +05:30
parent 8d79acda0f
commit 24deab1090
2 changed files with 13 additions and 1 deletions
cinderclient

@ -573,6 +573,9 @@ class OpenStackCinderShell(object):
# Check for Ctl-D
try:
os_password = getpass.getpass('OS Password: ')
# Initialize options.os_password with password
# input from tty. It is used in _get_keystone_session.
options.os_password = os_password
except EOFError:
pass
# No password because we didn't have a tty or the

@ -142,6 +142,7 @@ class ShellTest(utils.TestCase):
for count in range(1, 4):
self.list_volumes_on_service(count)
@mock.patch('keystoneclient.auth.identity.v2.Password')
@mock.patch('keystoneclient.adapter.Adapter.get_token',
side_effect=ks_exc.ConnectionRefused())
@mock.patch('keystoneclient.discover.Discover',
@ -149,11 +150,19 @@ class ShellTest(utils.TestCase):
@mock.patch('sys.stdin', side_effect=mock.MagicMock)
@mock.patch('getpass.getpass', return_value='password')
def test_password_prompted(self, mock_getpass, mock_stdin, mock_discover,
mock_token):
mock_token, mock_password):
self.make_env(exclude='OS_PASSWORD')
_shell = shell.OpenStackCinderShell()
self.assertRaises(ks_exc.ConnectionRefused, _shell.main, ['list'])
mock_getpass.assert_called_with('OS Password: ')
# Verify that Password() is called with value of param 'password'
# equal to mock_getpass.return_value.
mock_password.assert_called_with(
self.FAKE_ENV['OS_AUTH_URL'],
password=mock_getpass.return_value,
tenant_id='',
tenant_name=self.FAKE_ENV['OS_TENANT_NAME'],
username=self.FAKE_ENV['OS_USERNAME'])
@mock.patch.object(requests, "request")
@mock.patch.object(pkg_resources, "iter_entry_points")