Skip to content

Commit 74538a3

Browse files
Merge pull request #1460 from allmightyspiff/issues1436
Fixes shift+ins when pasteing into a password field for windows users.
2 parents 225a815 + 07df909 commit 74538a3

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

SoftLayer/CLI/environment.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,23 @@ def input(self, prompt, default=None, show_default=True):
6767

6868
def getpass(self, prompt, default=None):
6969
"""Provide a password prompt."""
70-
return click.prompt(prompt, hide_input=True, default=default)
70+
password = click.prompt(prompt, hide_input=True, default=default)
71+
72+
# https://github.com/softlayer/softlayer-python/issues/1436
73+
# click.prompt uses python's getpass() in the background
74+
# https://github.com/python/cpython/blob/3.9/Lib/getpass.py#L97
75+
# In windows, shift+insert actually inputs the below 2 characters
76+
# If we detect those 2 characters, need to manually read from the clipbaord instead
77+
# https://stackoverflow.com/questions/101128/how-do-i-read-text-from-the-clipboard
78+
if password == 'àR':
79+
# tkinter is a built in python gui, but it has clipboard reading functions.
80+
# pylint: disable=import-outside-toplevel
81+
from tkinter import Tk
82+
tk_manager = Tk()
83+
password = tk_manager.clipboard_get()
84+
# keep the window from showing
85+
tk_manager.withdraw()
86+
return password
7187

7288
# Command loading methods
7389
def list_commands(self, *path):

tests/CLI/environment_tests.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import click
99
import mock
10+
# from unittest.mock import MagicMock
1011

1112
from SoftLayer.CLI import environment
1213
from SoftLayer import testing
@@ -55,6 +56,14 @@ def test_getpass(self, prompt_mock):
5556
prompt_mock.assert_called_with('input', default=None, hide_input=True)
5657
self.assertEqual(prompt_mock(), r)
5758

59+
@mock.patch('click.prompt')
60+
@mock.patch('tkinter.Tk')
61+
def test_getpass_issues1436(self, tk, prompt_mock):
62+
prompt_mock.return_value = 'àR'
63+
self.env.getpass('input')
64+
prompt_mock.assert_called_with('input', default=None, hide_input=True)
65+
tk.assert_called_with()
66+
5867
def test_resolve_alias(self):
5968
self.env.aliases = {'aliasname': 'realname'}
6069
r = self.env.resolve_alias('aliasname')

0 commit comments

Comments
 (0)