Skip to content

Commit

Permalink
Add additional hosts to hard-coded service URL presubmit check
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
reillyi authored and Commit bot committed Nov 16, 2015
1 parent f12a8fd commit 3896573
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
3 changes: 2 additions & 1 deletion PRESUBMIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,8 @@ def FilterFile(affected_file):
_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)
Expand Down
29 changes: 29 additions & 0 deletions PRESUBMIT_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,35 @@ def testCheckAndroidCrLogUsage(self):
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()

0 comments on commit 3896573

Please sign in to comment.