示例#1
0
    def authenticate(self):
        if self.authenticated:
            return

        credentials = Credentials(config_urls.bug_server_host, git_prefix="bugzilla")

        attempts = 0
        while not self.authenticated:
            attempts += 1
            username, password = credentials.read_credentials()

            _log.info("Logging in as %s..." % username)
            self.browser.open(config_urls.bug_server_url +
                              "index.cgi?GoAheadAndLogIn=1")
            self.browser.select_form(name="login")
            self.browser['Bugzilla_login'] = username
            self.browser['Bugzilla_password'] = password
            self.browser.find_control("Bugzilla_restrictlogin").items[0].selected = False
            response = self.browser.submit()

            match = re.search("<title>(.+?)</title>", response.read())
            # If the resulting page has a title, and it contains the word
            # "invalid" assume it's the login failure page.
            if match and re.search("Invalid", match.group(1), re.IGNORECASE):
                errorMessage = "Bugzilla login failed: %s" % match.group(1)
                # raise an exception only if this was the last attempt
                if attempts < 5:
                    _log.error(errorMessage)
                else:
                    raise Exception(errorMessage)
            else:
                self.authenticated = True
                self.username = username
示例#2
0
    def authenticate(self):
        if self.authenticated:
            return

        credentials = Credentials(config_urls.bug_server_host,
                                  git_prefix="bugzilla")

        attempts = 0
        while not self.authenticated:
            attempts += 1
            username, password = credentials.read_credentials()

            _log.info("Logging in as %s..." % username)
            self.browser.open(config_urls.bug_server_url +
                              "index.cgi?GoAheadAndLogIn=1")
            self.browser.select_form(name="login")
            self.browser['Bugzilla_login'] = username
            self.browser['Bugzilla_password'] = password
            self.browser.find_control(
                "Bugzilla_restrictlogin").items[0].selected = False
            response = self.browser.submit()

            match = re.search("<title>(.+?)</title>", response.read())
            # If the resulting page has a title, and it contains the word
            # "invalid" assume it's the login failure page.
            if match and re.search("Invalid", match.group(1), re.IGNORECASE):
                errorMessage = "Bugzilla login failed: %s" % match.group(1)
                # raise an exception only if this was the last attempt
                if attempts < 5:
                    _log.error(errorMessage)
                else:
                    raise Exception(errorMessage)
            else:
                self.authenticated = True
                self.username = username
示例#3
0
    def test_security_output_parse_entry_not_found(self):
        # FIXME: This test won't work if the user has a credential for foo.example.com!
        credentials = Credentials("foo.example.com")
        if not credentials._is_mac_os_x():
            return  # This test does not run on a non-Mac.

        # Note, we ignore the captured output because it is already covered
        # by the test case CredentialsTest._assert_security_call (below).
        with OutputCapture():
            self.assertIsNone(
                credentials._run_security_tool("find-internet-password"))
    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'] = "******"
        os.environ['WEBKIT_BUGZILLA_PASSWORD'] = "******"
        username, password = credentials._credentials_from_environment()
        self.assertEquals(username, "foo")
        self.assertEquals(password, "bar")
        os.environ = saved_environ
    def test_security_output_parse_entry_not_found(self):
        credentials = Credentials("foo.example.com")
        if not credentials._is_mac_os_x():
            return  # This test does not run on a non-Mac.

        # Note, we ignore the captured output because it is already covered
        # by the test case CredentialsTest._assert_security_call (below).
        outputCapture = OutputCapture()
        outputCapture.capture_output()
        self.assertEqual(credentials._run_security_tool(), None)
        outputCapture.restore_output()
示例#6
0
    def test_security_output_parse_entry_not_found(self):
        credentials = Credentials("foo.example.com")
        if not credentials._is_mac_os_x():
            return  # This test does not run on a non-Mac.

        # Note, we ignore the captured output because it is already covered
        # by the test case CredentialsTest._assert_security_call (below).
        outputCapture = OutputCapture()
        outputCapture.capture_output()
        self.assertEqual(credentials._run_security_tool(), None)
        outputCapture.restore_output()
    def test_security_output_parse_entry_not_found(self):
        # FIXME: This test won't work if the user has a credential for foo.example.com!
        credentials = Credentials("foo.example.com")
        if not credentials._is_mac_os_x():
            return  # This test does not run on a non-Mac.

        # Note, we ignore the captured output because it is already covered
        # by the test case CredentialsTest._assert_security_call (below).
        outputCapture = OutputCapture()
        outputCapture.capture_output()
        self.assertIsNone(credentials._run_security_tool("find-internet-password"))
        outputCapture.restore_output()
示例#8
0
    def _assert_security_call(self, username=None):
        executive_mock = Mock()
        credentials = Credentials("example.com", executive=executive_mock)

        expected_stderr = "Reading Keychain for example.com account and password.  Click \"Allow\" to continue...\n"
        OutputCapture().assert_outputs(self,
                                       credentials._run_security_tool,
                                       [username],
                                       expected_stderr=expected_stderr)

        security_args = [
            "/usr/bin/security", "find-internet-password", "-g", "-s",
            "example.com"
        ]
        if username:
            security_args += ["-a", username]
        executive_mock.run_command.assert_called_with(security_args)
示例#9
0
 def __init__(self, *args, **kwargs):
     if 'executive' not in kwargs:
         kwargs['executive'] = MockExecutive()
     Credentials.__init__(self, *args, **kwargs)
 def test_security_output_parse(self):
     credentials = Credentials("bugs.webkit.org")
     self.assertEqual(
         credentials._parse_security_tool_output(self.example_security_output), ["*****@*****.**", "SECRETSAUCE"]
     )
示例#11
0
 def __init__(self, *args, **kwargs):
     if 'executive' not in kwargs:
         kwargs['executive'] = MockExecutive()
     Credentials.__init__(self, *args, **kwargs)
示例#12
0
 def __init__(self, cwd):
     Credentials.__init__(self, "fake.hostname", cwd=cwd,
                          keyring=MockKeyring())
示例#13
0
 def test_security_output_parse(self):
     credentials = Credentials("bugs.webkit.org")
     self.assertEqual(
         credentials._parse_security_tool_output(
             self.example_security_output),
         ["*****@*****.**", "SECRETSAUCE"])