Chromium Code Reviews

Unified Diff: tests/gclient_test.py

Issue 562953002: Rough verification code to ensure deps hosts \in allowed_hosts. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: final Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
« gclient.py ('K') | « gclient.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/gclient_test.py
diff --git a/tests/gclient_test.py b/tests/gclient_test.py
index c246efc4978c84395a241978593bb92a7564f9f5..86d505803e5f33378699e8bd0b0f9b5f92d4fe3e 100755
--- a/tests/gclient_test.py
+++ b/tests/gclient_test.py
@@ -907,6 +907,97 @@ class GclientTest(trial_dir.TestCase):
],
self._get_processed())
+ def testDepsFromNotAllowedHostsUnspecified(self):
+ """Verifies gclient works fine with DEPS without allowed_hosts."""
+ write(
+ '.gclient',
+ 'solutions = [\n'
+ ' { "name": "foo", "url": "svn://example.com/foo",\n'
+ ' "deps_file" : ".DEPS.git",\n'
+ ' },\n'
+ ']')
+ write(
+ os.path.join('foo', 'DEPS'),
+ 'deps = {\n'
+ ' "bar": "/bar",\n'
+ '}')
+ options, _ = gclient.OptionParser().parse_args([])
+ obj = gclient.GClient.LoadCurrentConfig(options)
+ obj.RunOnDeps('None', [])
+ dep = obj.dependencies[0]
+ self.assertEquals([], dep.findDepsFromNotAllowedHosts())
+ self.assertEquals(frozenset(), dep.allowed_hosts)
+ self._get_processed()
+
+ def testDepsFromNotAllowedHostsOK(self):
+ """Verifies gclient works fine with DEPS with proper allowed_hosts."""
+ write(
+ '.gclient',
+ 'solutions = [\n'
+ ' { "name": "foo", "url": "svn://example.com/foo",\n'
+ ' "deps_file" : ".DEPS.git",\n'
+ ' },\n'
+ ']')
+ write(
+ os.path.join('foo', '.DEPS.git'),
+ 'allowed_hosts = ["example.com"]\n'
+ 'deps = {\n'
+ ' "bar": "svn://example.com/bar",\n'
+ '}')
+ options, _ = gclient.OptionParser().parse_args([])
+ obj = gclient.GClient.LoadCurrentConfig(options)
+ obj.RunOnDeps('None', [])
+ dep = obj.dependencies[0]
+ self.assertEquals([], dep.findDepsFromNotAllowedHosts())
+ self.assertEquals(frozenset(['example.com']), dep.allowed_hosts)
+ self._get_processed()
+
+ def testDepsFromNotAllowedHostsBad(self):
+ """Verifies gclient works fine with DEPS with proper allowed_hosts."""
+ write(
+ '.gclient',
+ 'solutions = [\n'
+ ' { "name": "foo", "url": "svn://example.com/foo",\n'
+ ' "deps_file" : ".DEPS.git",\n'
+ ' },\n'
+ ']')
+ write(
+ os.path.join('foo', '.DEPS.git'),
+ 'allowed_hosts = ["other.com"]\n'
+ 'deps = {\n'
+ ' "bar": "svn://example.com/bar",\n'
+ '}')
+ options, _ = gclient.OptionParser().parse_args([])
+ obj = gclient.GClient.LoadCurrentConfig(options)
+ obj.RunOnDeps('None', [])
+ dep = obj.dependencies[0]
+ self.assertEquals(frozenset(['other.com']), dep.allowed_hosts)
+ self.assertEquals([dep.dependencies[0]], dep.findDepsFromNotAllowedHosts())
+ self._get_processed()
+
+ def testDepsParseFailureWithEmptyAllowedHosts(self):
+ """Verifies gclient fails with defined but empty allowed_hosts."""
+ write(
+ '.gclient',
+ 'solutions = [\n'
+ ' { "name": "foo", "url": "svn://example.com/foo",\n'
+ ' "deps_file" : ".DEPS.git",\n'
+ ' },\n'
+ ']')
+ write(
+ os.path.join('foo', 'DEPS'),
+ 'allowed_hosts = []'
iannucci 2014/09/18 20:54:41 should test a non-iterable as well (like None).
tandrii(chromium) 2014/09/18 21:45:58 Done.
+ 'deps = {\n'
+ ' "bar": "/bar",\n'
+ '}')
+ options, _ = gclient.OptionParser().parse_args([])
+ obj = gclient.GClient.LoadCurrentConfig(options)
+ try:
+ obj.RunOnDeps('None', [])
+ except gclient_utils.Error, e:
+ self.assertIn('allowed_hosts', str(e))
+ self._get_processed()
+
if __name__ == '__main__':
sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout)
« gclient.py ('K') | « gclient.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine