Skip to content

Commit cc1ead7

Browse files
committed
Removed test-specific functionality from CryptedFileKeyring - instead have the test runner patch the behavior.
1 parent 8dd2419 commit cc1ead7

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

keyring/backend.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -456,12 +456,6 @@ def supported(self):
456456
status = -1
457457
return status
458458

459-
def _getpass(self, *args, **kwargs):
460-
"""Wrap getpass.getpass(), so that we can override it when testing.
461-
"""
462-
463-
return getpass.getpass(*args, **kwargs)
464-
465459
@properties.NonDataProperty
466460
def keyring_key(self):
467461
# _unlock or _init_file will set the key or raise an exception
@@ -470,9 +464,9 @@ def keyring_key(self):
470464

471465
def _get_new_password(self):
472466
while True:
473-
password = self._getpass(
467+
password = getpass.getpass(
474468
"Please set a password for your new keyring: ")
475-
confirm = self._getpass('Please confirm the password: ')
469+
confirm = getpass.getpass('Please confirm the password: ')
476470
if password != confirm:
477471
sys.stderr.write("Error: Your passwords didn't match\n")
478472
continue
@@ -515,7 +509,7 @@ def _unlock(self):
515509
Unlock this keyring by getting the password for the keyring from the
516510
user.
517511
"""
518-
self.keyring_key = self._getpass(
512+
self.keyring_key = getpass.getpass(
519513
'Please enter password for encrypted keyring: ')
520514
try:
521515
ref_pw = self.get_password('keyring-setting', 'password reference')
@@ -590,7 +584,7 @@ def __convert_0_9_1(self, keyring_password):
590584
IV = head[self.block_size:]
591585

592586
if keyring_password is None:
593-
keyring_password = self._getpass(
587+
keyring_password = getpass.getpass(
594588
"Please input your password for the keyring: ")
595589

596590
cipher = self._create_cipher(keyring_password, salt, IV)
@@ -640,7 +634,7 @@ def __convert_0_9_0(self, keyring_password):
640634
import crypt
641635

642636
if keyring_password is None:
643-
keyring_password = self._getpass(
637+
keyring_password = getpass.getpass(
644638
"Please input your password for the keyring: ")
645639

646640
hashed = crypt.crypt(keyring_password, keyring_password)

keyring/tests/test_backend.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import sys
1414
import tempfile
1515
import types
16+
import getpass
1617

1718
try:
1819
# Python < 2.7 annd Python >= 3.0 < 3.1
@@ -364,7 +365,13 @@ class CryptedFileKeyringTestCase(FileKeyringTests, unittest.TestCase):
364365

365366
def setUp(self):
366367
super(self.__class__, self).setUp()
367-
self.keyring._getpass = lambda *args, **kwargs: "abcdef"
368+
# patch the getpass module to bypass user input
369+
self.getpass_orig = getpass.getpass
370+
getpass.getpass = lambda *args, **kwargs: "abcdef"
371+
372+
def tearDown(self):
373+
getpass.getpass = self.getpass_orig
374+
del self.getpass_orig
368375

369376
def init_keyring(self):
370377
return keyring.backend.CryptedFileKeyring()

0 commit comments

Comments
 (0)