diff options
author | Dan Albert <danalbert@google.com> | 2015-01-12 21:49:05 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-01-12 21:49:05 +0000 |
commit | 8d50e16aa96291612c95f89b49ecfacf556241a6 (patch) | |
tree | c36a70ccd04c3d7803451518e06e78eb2022ac02 /tools | |
parent | 780ea47482854e1b58931bea928bf93bcaf6e3aa (diff) | |
parent | ad248b7c005661e6565f6be12b3a25713f5d8aec (diff) | |
download | bionic-8d50e16aa96291612c95f89b49ecfacf556241a6.zip bionic-8d50e16aa96291612c95f89b49ecfacf556241a6.tar.gz bionic-8d50e16aa96291612c95f89b49ecfacf556241a6.tar.bz2 |
Merge "Guard against @google.com.example.com."
Diffstat (limited to 'tools')
-rw-r--r-- | tools/bionicbb/gmail_listener.py | 11 | ||||
-rw-r--r-- | tools/bionicbb/test_gmail_listener.py | 21 |
2 files changed, 30 insertions, 2 deletions
diff --git a/tools/bionicbb/gmail_listener.py b/tools/bionicbb/gmail_listener.py index 455d270..2f19454 100644 --- a/tools/bionicbb/gmail_listener.py +++ b/tools/bionicbb/gmail_listener.py @@ -51,6 +51,13 @@ def get_headers(msg): return headers +def should_skip_message(gerrit_info): + match = re.search(r'<(\S+)>$', gerrit_info['Owner']) + if match: + return not match.group(1).endswith('@google.com') + raise RuntimeError('Gerrit info missing Gerrit-Owner info.') + + def build_service(): from apiclient.discovery import build from oauth2client.client import flow_from_clientsecrets @@ -200,7 +207,7 @@ def build_project(gerrit_info, dry_run): def handle_change(gerrit_info, _, dry_run): - if '@google.com' not in gerrit_info['Owner']: + if should_skip_message(gerrit_info): return True return build_project(gerrit_info, dry_run) handle_newchange = handle_change @@ -233,7 +240,7 @@ def handle_comment(gerrit_info, body, dry_run): drop_rejection(gerrit_info, dry_run) # TODO(danalbert): Needs to be based on the account that made the comment. - if '@google.com' not in gerrit_info['Owner']: + if should_skip_message(gerrit_info): return True command_map = { diff --git a/tools/bionicbb/test_gmail_listener.py b/tools/bionicbb/test_gmail_listener.py new file mode 100644 index 0000000..feb7961 --- /dev/null +++ b/tools/bionicbb/test_gmail_listener.py @@ -0,0 +1,21 @@ +import gmail_listener +import unittest + + +class TestGerritParsers(unittest.TestCase): + def test_should_skip_message(self): + info = gmail_listener.get_gerrit_info( + 'Gerrit-Owner: Some Googler <somegoogler@google.com>\n') + self.assertFalse(gmail_listener.should_skip_message(info)) + + info = gmail_listener.get_gerrit_info( + 'Gerrit-Owner: Fake Googler <fakegoogler@google.com.foo.com>\n') + self.assertTrue(gmail_listener.should_skip_message(info)) + + info = gmail_listener.get_gerrit_info( + 'Gerrit-Owner: John Doe <johndoe@example.com>\n') + self.assertTrue(gmail_listener.should_skip_message(info)) + + +if __name__ == '__main__': + unittest.main() |