def authenticate(self): if self.authenticated: return if self.dryrun: log("Skipping log in for dry run...") self.authenticated = True return (username, password) = Credentials(self.bug_server_host, git_prefix="bugzilla").read_credentials() log("Logging in as %s..." % username) self.browser.open(self.bug_server_url + "index.cgi?GoAheadAndLogIn=1") self.browser.select_form(name="login") self.browser['Bugzilla_login'] = username self.browser['Bugzilla_password'] = password 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): # FIXME: We could add the ability to try again on failure. raise Exception("Bugzilla login failed: %s" % match.group(1)) self.authenticated = True
def test_git_config_calls(self): executive_mock = Mock() credentials = Credentials("example.com", executive=executive_mock) credentials._read_git_config("foo") executive_mock.run_command.assert_called_with( ["git", "config", "--get", "foo"], error_handler=Executive.ignore_error) credentials = Credentials("example.com", git_prefix="test_prefix", executive=executive_mock) credentials._read_git_config("foo") executive_mock.run_command.assert_called_with( ["git", "config", "--get", "test_prefix.foo"], error_handler=Executive.ignore_error)
def test_git_config_calls(self): executive_mock = Mock() credentials = Credentials("example.com", executive=executive_mock) credentials._read_git_config("foo") executive_mock.run_command.assert_called_with(["git", "config", "--get", "foo"], error_handler=Executive.ignore_error) credentials = Credentials("example.com", git_prefix="test_prefix", executive=executive_mock) credentials._read_git_config("foo") executive_mock.run_command.assert_called_with(["git", "config", "--get", "test_prefix.foo"], error_handler=Executive.ignore_error)
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)
def test_security_output_parse_entry_not_found(self): credentials = Credentials("foo.example.com") self.assertEqual( credentials._parse_security_tool_output( Credentials.keychain_entry_not_found), [None, None])
def test_security_output_parse(self): credentials = Credentials("bugs.webkit.org") self.assertEqual( credentials._parse_security_tool_output( self.example_security_output), ["*****@*****.**", "SECRETSAUCE"])
def test_security_output_parse_entry_not_found(self): credentials = Credentials("foo.example.com") self.assertEqual(credentials._parse_security_tool_output(Credentials.keychain_entry_not_found), [None, None])
def test_security_output_parse(self): credentials = Credentials("bugs.webkit.org") self.assertEqual(credentials._parse_security_tool_output(self.example_security_output), ["*****@*****.**", "SECRETSAUCE"])