Jason R. Coombs avatar Jason R. Coombs committed b018bb9

Removed test-specific functionality from CryptedFileKeyring - instead have the test runner patch the behavior.

Comments (0)

Files changed (2)

keyring/backend.py

             status = -1
         return status
 
-    def _getpass(self, *args, **kwargs):
-        """Wrap getpass.getpass(), so that we can override it when testing.
-        """
-
-        return getpass.getpass(*args, **kwargs)
-
     @properties.NonDataProperty
     def keyring_key(self):
         # _unlock or _init_file will set the key or raise an exception
 
     def _get_new_password(self):
         while True:
-            password = self._getpass(
+            password = getpass.getpass(
                 "Please set a password for your new keyring: ")
-            confirm = self._getpass('Please confirm the password: ')
+            confirm = getpass.getpass('Please confirm the password: ')
             if password != confirm:
                 sys.stderr.write("Error: Your passwords didn't match\n")
                 continue
         Unlock this keyring by getting the password for the keyring from the
         user.
         """
-        self.keyring_key = self._getpass(
+        self.keyring_key = getpass.getpass(
             'Please enter password for encrypted keyring: ')
         try:
             ref_pw = self.get_password('keyring-setting', 'password reference')
         IV = head[self.block_size:]
 
         if keyring_password is None:
-            keyring_password = self._getpass(
+            keyring_password = getpass.getpass(
                 "Please input your password for the keyring: ")
 
         cipher = self._create_cipher(keyring_password, salt, IV)
         import crypt
 
         if keyring_password is None:
-            keyring_password = self._getpass(
+            keyring_password = getpass.getpass(
                 "Please input your password for the keyring: ")
 
         hashed = crypt.crypt(keyring_password, keyring_password)

keyring/tests/test_backend.py

 import sys
 import tempfile
 import types
+import getpass
 
 try:
     # Python < 2.7 annd Python >= 3.0 < 3.1
 
     def setUp(self):
         super(self.__class__, self).setUp()
-        self.keyring._getpass = lambda *args, **kwargs: "abcdef"
+        # patch the getpass module to bypass user input
+        self.getpass_orig = getpass.getpass
+        getpass.getpass = lambda *args, **kwargs: "abcdef"
+
+    def tearDown(self):
+        getpass.getpass = self.getpass_orig
+        del self.getpass_orig
 
     def init_keyring(self):
         return keyring.backend.CryptedFileKeyring()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.