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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « gclient.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Unit tests for gclient.py. 6 """Unit tests for gclient.py.
7 7
8 See gclient_smoketest.py for integration tests. 8 See gclient_smoketest.py for integration tests.
9 """ 9 """
10 10
(...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 options, _ = gclient.OptionParser().parse_args([]) 900 options, _ = gclient.OptionParser().parse_args([])
901 obj = gclient.GClient.LoadCurrentConfig(options) 901 obj = gclient.GClient.LoadCurrentConfig(options)
902 obj.RunOnDeps('None', []) 902 obj.RunOnDeps('None', [])
903 self.assertEquals( 903 self.assertEquals(
904 [ 904 [
905 'svn://example.com/foo', 905 'svn://example.com/foo',
906 'svn://example.com/foo/bar', 906 'svn://example.com/foo/bar',
907 ], 907 ],
908 self._get_processed()) 908 self._get_processed())
909 909
910 def testDepsFromNotAllowedHostsUnspecified(self):
911 """Verifies gclient works fine with DEPS without allowed_hosts."""
912 write(
913 '.gclient',
914 'solutions = [\n'
915 ' { "name": "foo", "url": "svn://example.com/foo",\n'
916 ' "deps_file" : ".DEPS.git",\n'
917 ' },\n'
918 ']')
919 write(
920 os.path.join('foo', 'DEPS'),
921 'deps = {\n'
922 ' "bar": "/bar",\n'
923 '}')
924 options, _ = gclient.OptionParser().parse_args([])
925 obj = gclient.GClient.LoadCurrentConfig(options)
926 obj.RunOnDeps('None', [])
927 dep = obj.dependencies[0]
928 self.assertEquals([], dep.findDepsFromNotAllowedHosts())
929 self.assertEquals(frozenset(), dep.allowed_hosts)
930 self._get_processed()
931
932 def testDepsFromNotAllowedHostsOK(self):
933 """Verifies gclient works fine with DEPS with proper allowed_hosts."""
934 write(
935 '.gclient',
936 'solutions = [\n'
937 ' { "name": "foo", "url": "svn://example.com/foo",\n'
938 ' "deps_file" : ".DEPS.git",\n'
939 ' },\n'
940 ']')
941 write(
942 os.path.join('foo', '.DEPS.git'),
943 'allowed_hosts = ["example.com"]\n'
944 'deps = {\n'
945 ' "bar": "svn://example.com/bar",\n'
946 '}')
947 options, _ = gclient.OptionParser().parse_args([])
948 obj = gclient.GClient.LoadCurrentConfig(options)
949 obj.RunOnDeps('None', [])
950 dep = obj.dependencies[0]
951 self.assertEquals([], dep.findDepsFromNotAllowedHosts())
952 self.assertEquals(frozenset(['example.com']), dep.allowed_hosts)
953 self._get_processed()
954
955 def testDepsFromNotAllowedHostsBad(self):
956 """Verifies gclient works fine with DEPS with proper allowed_hosts."""
957 write(
958 '.gclient',
959 'solutions = [\n'
960 ' { "name": "foo", "url": "svn://example.com/foo",\n'
961 ' "deps_file" : ".DEPS.git",\n'
962 ' },\n'
963 ']')
964 write(
965 os.path.join('foo', '.DEPS.git'),
966 'allowed_hosts = ["other.com"]\n'
967 'deps = {\n'
968 ' "bar": "svn://example.com/bar",\n'
969 '}')
970 options, _ = gclient.OptionParser().parse_args([])
971 obj = gclient.GClient.LoadCurrentConfig(options)
972 obj.RunOnDeps('None', [])
973 dep = obj.dependencies[0]
974 self.assertEquals(frozenset(['other.com']), dep.allowed_hosts)
975 self.assertEquals([dep.dependencies[0]], dep.findDepsFromNotAllowedHosts())
976 self._get_processed()
977
978 def testDepsParseFailureWithEmptyAllowedHosts(self):
979 """Verifies gclient fails with defined but empty allowed_hosts."""
980 write(
981 '.gclient',
982 'solutions = [\n'
983 ' { "name": "foo", "url": "svn://example.com/foo",\n'
984 ' "deps_file" : ".DEPS.git",\n'
985 ' },\n'
986 ']')
987 write(
988 os.path.join('foo', 'DEPS'),
989 'allowed_hosts = []\n'
990 'deps = {\n'
991 ' "bar": "/bar",\n'
992 '}')
993 options, _ = gclient.OptionParser().parse_args([])
994 obj = gclient.GClient.LoadCurrentConfig(options)
995 try:
996 obj.RunOnDeps('None', [])
997 self.assertFalse("unreachable code")
998 except gclient_utils.Error, e:
999 self.assertIn('allowed_hosts must be', str(e))
1000 finally:
1001 self._get_processed()
1002
1003 def testDepsParseFailureWithNonIterableAllowedHosts(self):
1004 """Verifies gclient fails with defined but non-iterable allowed_hosts."""
1005 write(
1006 '.gclient',
1007 'solutions = [\n'
1008 ' { "name": "foo", "url": "svn://example.com/foo",\n'
1009 ' "deps_file" : ".DEPS.git",\n'
1010 ' },\n'
1011 ']')
1012 write(
1013 os.path.join('foo', 'DEPS'),
1014 'allowed_hosts = None\n'
1015 'deps = {\n'
1016 ' "bar": "/bar",\n'
1017 '}')
1018 options, _ = gclient.OptionParser().parse_args([])
1019 obj = gclient.GClient.LoadCurrentConfig(options)
1020 try:
1021 obj.RunOnDeps('None', [])
1022 self.assertFalse("unreachable code")
1023 except gclient_utils.Error, e:
1024 self.assertIn('allowed_hosts must be', str(e))
1025 finally:
1026 self._get_processed()
1027
910 1028
911 if __name__ == '__main__': 1029 if __name__ == '__main__':
912 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout) 1030 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout)
913 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout, include_zero=True) 1031 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout, include_zero=True)
914 sys.stderr = gclient_utils.MakeFileAutoFlush(sys.stderr) 1032 sys.stderr = gclient_utils.MakeFileAutoFlush(sys.stderr)
915 sys.stderr = gclient_utils.MakeFileAnnotated(sys.stderr, include_zero=True) 1033 sys.stderr = gclient_utils.MakeFileAnnotated(sys.stderr, include_zero=True)
916 logging.basicConfig( 1034 logging.basicConfig(
917 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ 1035 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][
918 min(sys.argv.count('-v'), 3)], 1036 min(sys.argv.count('-v'), 3)],
919 format='%(relativeCreated)4d %(levelname)5s %(module)13s(' 1037 format='%(relativeCreated)4d %(levelname)5s %(module)13s('
920 '%(lineno)d) %(message)s') 1038 '%(lineno)d) %(message)s')
921 unittest.main() 1039 unittest.main()
OLDNEW
« 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