diff options
author | reillyi <reillyi@amazon.com> | 2015-11-16 10:27:33 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-16 18:28:18 +0000 |
commit | 3896573612b050f3e065b1188098f68bdae0b696 (patch) | |
tree | b497bfd998683dfe4ff96f4aa0c72d1ea4f60cce | |
parent | f12a8fd20f4f1b14a75f6f944dc2a1cd5aa847a7 (diff) | |
download | chromium_src-3896573612b050f3e065b1188098f68bdae0b696.zip chromium_src-3896573612b050f3e065b1188098f68bdae0b696.tar.gz chromium_src-3896573612b050f3e065b1188098f68bdae0b696.tar.bz2 |
Add additional hosts to hard-coded service URL presubmit check
This adds additional domains to the root PRESUBMIT check,
"_CheckHardcodedGoogleHostsInLowerLayers", based on hostnames
currently used in Chromium.
Previously, this check only validated that "google.com" was not
hard-coded, but did not catch other common hostnames:
- gstatic.com
- googleapis.com
- googlezip.net
- googledrive.com
- appspot.com
Note that this check is non-blocking, only prompting the user
with a warning before continuing the submit operation.
BUG=164568
TEST=PRESUBMIT_test.py
Review URL: https://codereview.chromium.org/1403673003
Cr-Commit-Position: refs/heads/master@{#359869}
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | PRESUBMIT.py | 3 | ||||
-rwxr-xr-x | PRESUBMIT_test.py | 29 |
3 files changed, 32 insertions, 1 deletions
@@ -237,6 +237,7 @@ Ian Scott <ian.scott@arteris.com> Ibrar Ahmed <ibrar.ahmad@gmail.com> Ilia K <ki.stfu@gmail.com> Ion Rosca <rosca@adobe.com> +Isaac Reilly <reillyi@amazon.com> Ivan Sham <ivansham@amazon.com> J. Ryan Stinnett <jryans@chromium.org> Jacob Mandelson <jacob@mandelson.org> diff --git a/PRESUBMIT.py b/PRESUBMIT.py index b8ec42b..6e481fe 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -900,7 +900,8 @@ def _CheckHardcodedGoogleHostsInLowerLayers(input_api, output_api): _TEST_CODE_EXCLUDED_PATHS + input_api.DEFAULT_BLACK_LIST)) - base_pattern = '"[^"]*google\.com[^"]*"' + base_pattern = ('"[^"]*(google|googleapis|googlezip|googledrive|appspot)' + '\.(com|net)[^"]*"') comment_pattern = input_api.re.compile('//.*%s' % base_pattern) pattern = input_api.re.compile(base_pattern) problems = [] # items are (filename, line_number, line) diff --git a/PRESUBMIT_test.py b/PRESUBMIT_test.py index 5aed7ee..e488c94 100755 --- a/PRESUBMIT_test.py +++ b/PRESUBMIT_test.py @@ -986,6 +986,35 @@ class LogUsageTest(unittest.TestCase): self.assertTrue('HasDottedTag.java' in msgs[4].items) self.assertTrue('HasOldTag.java' in msgs[4].items) +class HardcodedGoogleHostsTest(unittest.TestCase): + + def testWarnOnAssignedLiterals(self): + input_api = MockInputApi() + input_api.files = [ + MockFile('content/file.cc', + ['char* host = "https://www.google.com";']), + MockFile('content/file.cc', + ['char* host = "https://www.googleapis.com";']), + MockFile('content/file.cc', + ['char* host = "https://clients1.google.com";']), + ] + + warnings = PRESUBMIT._CheckHardcodedGoogleHostsInLowerLayers( + input_api, MockOutputApi()) + self.assertEqual(1, len(warnings)) + self.assertEqual(3, len(warnings[0].items)) + + def testAllowInComment(self): + input_api = MockInputApi() + input_api.files = [ + MockFile('content/file.cc', + ['char* host = "https://www.aol.com"; // google.com']) + ] + + warnings = PRESUBMIT._CheckHardcodedGoogleHostsInLowerLayers( + input_api, MockOutputApi()) + self.assertEqual(0, len(warnings)) + if __name__ == '__main__': unittest.main() |