Title: [124140] trunk/Tools
Revision
124140
Author
[email protected]
Date
2012-07-30 18:45:44 -0700 (Mon, 30 Jul 2012)

Log Message

webkit-patch: system keyring is not used to read my password
https://bugs.webkit.org/show_bug.cgi?id=92532

Patch by Arnaud Renevier <[email protected]> on 2012-07-30
Reviewed by Dirk Pranke.

In case no username can be fetched from environment, git or keychain,
prompt for username, and try to get password from keyring associated
with that username.

* Scripts/webkitpy/common/net/credentials.py:
(Credentials.read_credentials):
* Scripts/webkitpy/common/net/credentials_unittest.py:
(test_keyring_without_git_repo_nor_keychain):
(test_keyring_without_git_repo_nor_keychain.MockKeyring):
(test_keyring_without_git_repo_nor_keychain.MockKeyring.get_password):
(test_keyring_without_git_repo_nor_keychain.FakeCredentials):
(test_keyring_without_git_repo_nor_keychain.FakeCredentials._credentials_from_keychain):
(test_keyring_without_git_repo_nor_keychain.FakeCredentials._credentials_from_environment):
(test_keyring_without_git_repo_nor_keychain.FakeUser):
(test_keyring_without_git_repo_nor_keychain.FakeUser.prompt):
(test_keyring_without_git_repo_nor_keychain.FakeUser.prompt_password):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (124139 => 124140)


--- trunk/Tools/ChangeLog	2012-07-31 01:40:34 UTC (rev 124139)
+++ trunk/Tools/ChangeLog	2012-07-31 01:45:44 UTC (rev 124140)
@@ -1,3 +1,27 @@
+2012-07-30  Arnaud Renevier  <[email protected]>
+
+        webkit-patch: system keyring is not used to read my password
+        https://bugs.webkit.org/show_bug.cgi?id=92532
+
+        Reviewed by Dirk Pranke.
+
+        In case no username can be fetched from environment, git or keychain,
+        prompt for username, and try to get password from keyring associated
+        with that username.
+
+        * Scripts/webkitpy/common/net/credentials.py:
+        (Credentials.read_credentials):
+        * Scripts/webkitpy/common/net/credentials_unittest.py:
+        (test_keyring_without_git_repo_nor_keychain):
+        (test_keyring_without_git_repo_nor_keychain.MockKeyring):
+        (test_keyring_without_git_repo_nor_keychain.MockKeyring.get_password):
+        (test_keyring_without_git_repo_nor_keychain.FakeCredentials):
+        (test_keyring_without_git_repo_nor_keychain.FakeCredentials._credentials_from_keychain):
+        (test_keyring_without_git_repo_nor_keychain.FakeCredentials._credentials_from_environment):
+        (test_keyring_without_git_repo_nor_keychain.FakeUser):
+        (test_keyring_without_git_repo_nor_keychain.FakeUser.prompt):
+        (test_keyring_without_git_repo_nor_keychain.FakeUser.prompt_password):
+
 2012-07-30  Dirk Pranke  <[email protected]>
 
         nrwt: move the code that identifies the chunk of tests to run into finder

Modified: trunk/Tools/Scripts/webkitpy/common/net/credentials.py (124139 => 124140)


--- trunk/Tools/Scripts/webkitpy/common/net/credentials.py	2012-07-31 01:40:34 UTC (rev 124139)
+++ trunk/Tools/Scripts/webkitpy/common/net/credentials.py	2012-07-31 01:45:44 UTC (rev 124140)
@@ -133,7 +133,7 @@
             return
         self._keyring.set_password(self.host, username, password)
 
-    def read_credentials(self):
+    def read_credentials(self, user=User):
         username, password = self._credentials_from_environment()
         # FIXME: We don't currently support pulling the username from one
         # source and the password from a separate source.
@@ -142,13 +142,14 @@
         if not username or not password:
             username, password = self._credentials_from_keychain(username)
 
+        if not username:
+            username = user.prompt("%s login: " % self.host)
+
         if username and not password and self._keyring:
             password = self._keyring.get_password(self.host, username)
 
-        if not username:
-            username = User.prompt("%s login: " % self.host)
         if not password:
-            password = User.prompt_password("%s password for %s: " % (self.host, username))
+            password = user.prompt_password("%s password for %s: " % (self.host, username))
             self._offer_to_store_credentials_in_keyring(username, password)
 
         return (username, password)

Modified: trunk/Tools/Scripts/webkitpy/common/net/credentials_unittest.py (124139 => 124140)


--- trunk/Tools/Scripts/webkitpy/common/net/credentials_unittest.py	2012-07-31 01:40:34 UTC (rev 124139)
+++ trunk/Tools/Scripts/webkitpy/common/net/credentials_unittest.py	2012-07-31 01:45:44 UTC (rev 124140)
@@ -32,6 +32,7 @@
 from webkitpy.common.net.credentials import Credentials
 from webkitpy.common.system.executive import Executive
 from webkitpy.common.system.outputcapture import OutputCapture
+from webkitpy.common.system.user_mock import MockUser
 from webkitpy.thirdparty.mock import Mock
 from webkitpy.tool.mocktool import MockOptions
 from webkitpy.common.system.executive_mock import MockExecutive
@@ -179,6 +180,33 @@
             # credential source could be affected by the user's environment.
             self.assertEqual(credentials.read_credentials(), ("[email protected]", "NOMNOMNOM"))
 
+    def test_keyring_without_git_repo_nor_keychain(self):
+        class MockKeyring(object):
+            def get_password(self, host, username):
+                return "NOMNOMNOM"
 
+        class FakeCredentials(MockedCredentials):
+            def _credentials_from_keychain(self, username):
+                return (None, None)
+
+            def _credentials_from_environment(self):
+                return (None, None)
+
+        class FakeUser(MockUser):
+            @classmethod
+            def prompt(cls, message, repeat=1, raw_input=raw_input):
+                return "[email protected]"
+
+            @classmethod
+            def prompt_password(cls, message, repeat=1, raw_input=raw_input):
+                raise AssertionError("should not prompt for password")
+
+        with _TemporaryDirectory(suffix="not_a_git_repo") as temp_dir_path:
+            credentials = FakeCredentials("fake.hostname", cwd=temp_dir_path, keyring=MockKeyring())
+            # FIXME: Using read_credentials here seems too broad as higher-priority
+            # credential source could be affected by the user's environment.
+            self.assertEqual(credentials.read_credentials(FakeUser), ("[email protected]", "NOMNOMNOM"))
+
+
 if __name__ == '__main__':
     unittest.main()
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to