[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

eric at webkit.org eric at webkit.org
Wed Dec 22 14:58:42 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 9a6c8c0dbaa9227301ddff7b1635d49e3731f862
Author: eric at webkit.org <eric at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Oct 26 20:19:48 2010 +0000

    2010-10-26  Eric Seidel  <eric at webkit.org>
    
            Reviewed by Tony Chang.
    
            Teach webkit-patch how to read credentials from the environment
            https://bugs.webkit.org/show_bug.cgi?id=48275
    
            This makes it possible for svn users to have their bugzilla credentials
            stored in their environment instead of typing them every time.
    
            We need this for making it easy to run the win-ews bot (which currently
            uses svn instead of git).
    
            * Scripts/webkitpy/common/net/credentials.py:
            * Scripts/webkitpy/common/net/credentials_unittest.py:
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@70562 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKitTools/ChangeLog b/WebKitTools/ChangeLog
index aeb6eed..223ce57 100644
--- a/WebKitTools/ChangeLog
+++ b/WebKitTools/ChangeLog
@@ -1,3 +1,19 @@
+2010-10-26  Eric Seidel  <eric at webkit.org>
+
+        Reviewed by Tony Chang.
+
+        Teach webkit-patch how to read credentials from the environment
+        https://bugs.webkit.org/show_bug.cgi?id=48275
+
+        This makes it possible for svn users to have their bugzilla credentials
+        stored in their environment instead of typing them every time.
+
+        We need this for making it easy to run the win-ews bot (which currently
+        uses svn instead of git).
+
+        * Scripts/webkitpy/common/net/credentials.py:
+        * Scripts/webkitpy/common/net/credentials_unittest.py:
+
 2010-10-26  Kenichi Ishibashi  <bashi at google.com>
 
         Reviewed by Kent Tamura.
diff --git a/WebKitTools/Scripts/webkitpy/common/net/bugzilla.py b/WebKitTools/Scripts/webkitpy/common/net/bugzilla.py
index 94519a7..b098895 100644
--- a/WebKitTools/Scripts/webkitpy/common/net/bugzilla.py
+++ b/WebKitTools/Scripts/webkitpy/common/net/bugzilla.py
@@ -591,11 +591,12 @@ class Bugzilla(object):
             self.authenticated = True
             return
 
+        credentials = Credentials(self.bug_server_host, git_prefix="bugzilla")
+
         attempts = 0
         while not self.authenticated:
             attempts += 1
-            (username, password) = Credentials(
-                self.bug_server_host, git_prefix="bugzilla").read_credentials()
+            username, password = credentials.read_credentials()
 
             log("Logging in as %s..." % username)
             self.browser.open(self.bug_server_url +
diff --git a/WebKitTools/Scripts/webkitpy/common/net/credentials.py b/WebKitTools/Scripts/webkitpy/common/net/credentials.py
index 1c3e6c0..64096d8 100644
--- a/WebKitTools/Scripts/webkitpy/common/net/credentials.py
+++ b/WebKitTools/Scripts/webkitpy/common/net/credentials.py
@@ -48,6 +48,7 @@ except ImportError:
 
 
 class Credentials(object):
+    _environ_prefix = "webkit_bugzilla_"
 
     def __init__(self, host, git_prefix=None, executive=None, cwd=os.getcwd(),
                  keyring=keyring):
@@ -58,8 +59,17 @@ class Credentials(object):
         self._keyring = keyring
 
     def _credentials_from_git(self):
-        return [Git.read_git_config(self.git_prefix + "username"),
-                Git.read_git_config(self.git_prefix + "password")]
+        if not Git.in_working_directory(self.cwd):
+            return (None, None)
+        try:
+            return (Git.read_git_config(self.git_prefix + "username"),
+                    Git.read_git_config(self.git_prefix + "password"))
+        except OSError, e:
+            # Catch and ignore OSError exceptions such as "no such file
+            # or directory" (OSError errno 2), which imply that the Git
+            # command cannot be found/is not installed.
+            pass
+        return (None, None)
 
     def _keychain_value_with_label(self, label, source_text):
         match = re.search("%s\"(?P<value>.+)\"" % label,
@@ -110,21 +120,28 @@ class Credentials(object):
         else:
             return [None, None]
 
-    def read_credentials(self):
-        username = None
-        password = None
+    def _read_environ(self, key):
+        environ_key = self._environ_prefix + key
+        return os.environ.get(environ_key.upper())
 
-        try:
-            if Git.in_working_directory(self.cwd):
-                (username, password) = self._credentials_from_git()
-        except OSError, e:
-            # Catch and ignore OSError exceptions such as "no such file 
-            # or directory" (OSError errno 2), which imply that the Git
-            # command cannot be found/is not installed.
-            pass
+    def _credentials_from_environment(self):
+        return (self._read_environ("username"), self._read_environ("password"))
+
+    def _offer_to_store_credentials_in_keyring(self, username, password):
+        if not self._keyring:
+            return
+        if not User().confirm("Store password in system keyring?", User.DEFAULT_NO):
+            return
+        self._keyring.set_password(self.host, username, password)
 
+    def read_credentials(self):
+        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.
+        if not username or not password:
+            username, password = self._credentials_from_git()
         if not username or not password:
-            (username, password) = self._credentials_from_keychain(username)
+            username, password = self._credentials_from_keychain(username)
 
         if username and not password and self._keyring:
             password = self._keyring.get_password(self.host, username)
@@ -132,13 +149,7 @@ class Credentials(object):
         if not username:
             username = User.prompt("%s login: " % self.host)
         if not password:
-            password = getpass.getpass("%s password for %s: " % (self.host,
-                                                                 username))
+            password = getpass.getpass("%s password for %s: " % (self.host, username))
+            self._offer_to_store_credentials_in_keyring(username, password)
 
-            if self._keyring:
-                store_password = User().confirm(
-                    "Store password in system keyring?", User.DEFAULT_NO)
-                if store_password:
-                    self._keyring.set_password(self.host, username, password)
-
-        return [username, password]
+        return (username, password)
diff --git a/WebKitTools/Scripts/webkitpy/common/net/credentials_unittest.py b/WebKitTools/Scripts/webkitpy/common/net/credentials_unittest.py
index d30291b..3e04223 100644
--- a/WebKitTools/Scripts/webkitpy/common/net/credentials_unittest.py
+++ b/WebKitTools/Scripts/webkitpy/common/net/credentials_unittest.py
@@ -34,6 +34,21 @@ from webkitpy.common.system.executive import Executive
 from webkitpy.common.system.outputcapture import OutputCapture
 from webkitpy.thirdparty.mock import Mock
 
+
+# FIXME: Other unit tests probably want this class.
+class _TemporaryDirectory(object):
+    def __init__(self, **kwargs):
+        self._kwargs = kwargs
+        self._directory_path = None
+
+    def __enter__(self):
+        self._directory_path = tempfile.mkdtemp(**self._kwargs)
+        return self._directory_path
+
+    def __exit__(self, type, value, traceback):
+        os.rmdir(self._directory_path)
+
+
 class CredentialsTest(unittest.TestCase):
     example_security_output = """keychain: "/Users/test/Library/Keychains/login.keychain"
 class: "inet"
@@ -101,40 +116,59 @@ password: "SECRETSAUCE"
         self._assert_security_call()
         self._assert_security_call(username="foo")
 
+    def test_credentials_from_environment(self):
+        executive_mock = Mock()
+        credentials = Credentials("example.com", executive=executive_mock)
+
+        saved_environ = os.environ.copy()
+        os.environ['WEBKIT_BUGZILLA_USERNAME'] = "foo"
+        os.environ['WEBKIT_BUGZILLA_PASSWORD'] = "bar"
+        username, password = credentials._credentials_from_environment()
+        self.assertEquals(username, "foo")
+        self.assertEquals(password, "bar")
+        os.environ = saved_environ
+
     def test_read_credentials_without_git_repo(self):
+        # FIXME: This should share more code with test_keyring_without_git_repo
         class FakeCredentials(Credentials):
             def _is_mac_os_x(self):
                 return True
+
             def _credentials_from_keychain(self, username):
-                return ["test at webkit.org", "SECRETSAUCE"]
+                return ("test at webkit.org", "SECRETSAUCE")
+
+            def _credentials_from_environment(self):
+                return (None, None)
+
+        with _TemporaryDirectory(suffix="not_a_git_repo") as temp_dir_path:
+            credentials = FakeCredentials("bugs.webkit.org", cwd=temp_dir_path)
+            # 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(), ("test at webkit.org", "SECRETSAUCE"))
 
-        temp_dir_path = tempfile.mkdtemp(suffix="not_a_git_repo")
-        credentials = FakeCredentials("bugs.webkit.org", cwd=temp_dir_path)
-        self.assertEqual(credentials.read_credentials(), ["test at webkit.org", "SECRETSAUCE"])
-        os.rmdir(temp_dir_path)
 
     def test_keyring_without_git_repo(self):
+        # FIXME: This should share more code with test_read_credentials_without_git_repo
         class MockKeyring(object):
             def get_password(self, host, username):
                 return "NOMNOMNOM"
 
         class FakeCredentials(Credentials):
-            def __init__(self, cwd):
-                Credentials.__init__(self, "fake.hostname", cwd=cwd,
-                                     keyring=MockKeyring())
-
             def _is_mac_os_x(self):
                 return True
 
             def _credentials_from_keychain(self, username):
                 return ("test at webkit.org", None)
 
-        temp_dir_path = tempfile.mkdtemp(suffix="not_a_git_repo")
-        credentials = FakeCredentials(temp_dir_path)
-        try:
-            self.assertEqual(credentials.read_credentials(), ["test at webkit.org", "NOMNOMNOM"])
-        finally:
-            os.rmdir(temp_dir_path)
+            def _credentials_from_environment(self):
+                return (None, None)
+
+        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(), ("test at webkit.org", "NOMNOMNOM"))
+
 
 if __name__ == '__main__':
     unittest.main()

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list