diff options
author | Dan Albert <danalbert@google.com> | 2015-01-12 12:25:31 -0800 |
---|---|---|
committer | Dan Albert <danalbert@google.com> | 2015-01-12 13:48:46 -0800 |
commit | ad248b7c005661e6565f6be12b3a25713f5d8aec (patch) | |
tree | c36a70ccd04c3d7803451518e06e78eb2022ac02 | |
parent | 780ea47482854e1b58931bea928bf93bcaf6e3aa (diff) | |
download | bionic-ad248b7c005661e6565f6be12b3a25713f5d8aec.zip bionic-ad248b7c005661e6565f6be12b3a25713f5d8aec.tar.gz bionic-ad248b7c005661e6565f6be12b3a25713f5d8aec.tar.bz2 |
Guard against @google.com.example.com.
Begin adding some unit tests. Testing the Jenkins interface will
probably be difficult, but testing that we can properly handle
messages from Gerrit is easy enough.
Change-Id: Id7e8e175e0f064fd10715febe40040a65564c701
-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() |