Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1248)

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: Fixed docs + iannucci suggestions. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « 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..22de31a98047890177296723480e0deb1b5e259e 100755
--- a/tests/gclient_test.py
+++ b/tests/gclient_test.py
@@ -907,6 +907,124 @@ 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 = []\n'
+ 'deps = {\n'
+ ' "bar": "/bar",\n'
+ '}')
+ options, _ = gclient.OptionParser().parse_args([])
+ obj = gclient.GClient.LoadCurrentConfig(options)
+ try:
+ obj.RunOnDeps('None', [])
+ self.assertFalse("unreachable code")
+ except gclient_utils.Error, e:
+ self.assertIn('allowed_hosts must be', str(e))
+ finally:
+ self._get_processed()
+
+ def testDepsParseFailureWithNonIterableAllowedHosts(self):
+ """Verifies gclient fails with defined but non-iterable 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 = None\n'
+ 'deps = {\n'
+ ' "bar": "/bar",\n'
+ '}')
+ options, _ = gclient.OptionParser().parse_args([])
+ obj = gclient.GClient.LoadCurrentConfig(options)
+ try:
+ obj.RunOnDeps('None', [])
+ self.assertFalse("unreachable code")
+ except gclient_utils.Error, e:
+ self.assertIn('allowed_hosts must be', str(e))
+ finally:
+ self._get_processed()
+
if __name__ == '__main__':
sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout)
« no previous file with comments | « gclient.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698