 Chromium Code Reviews
 Chromium Code Reviews 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
    
  
    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| OLD | NEW | 
|---|---|
| 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 Loading... | |
| 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 = []' | |
| 
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.
 | |
| 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 except gclient_utils.Error, e: | |
| 998 self.assertIn('allowed_hosts', str(e)) | |
| 999 self._get_processed() | |
| 1000 | |
| 910 | 1001 | 
| 911 if __name__ == '__main__': | 1002 if __name__ == '__main__': | 
| 912 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout) | 1003 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout) | 
| 913 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout, include_zero=True) | 1004 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout, include_zero=True) | 
| 914 sys.stderr = gclient_utils.MakeFileAutoFlush(sys.stderr) | 1005 sys.stderr = gclient_utils.MakeFileAutoFlush(sys.stderr) | 
| 915 sys.stderr = gclient_utils.MakeFileAnnotated(sys.stderr, include_zero=True) | 1006 sys.stderr = gclient_utils.MakeFileAnnotated(sys.stderr, include_zero=True) | 
| 916 logging.basicConfig( | 1007 logging.basicConfig( | 
| 917 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ | 1008 level=[logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG][ | 
| 918 min(sys.argv.count('-v'), 3)], | 1009 min(sys.argv.count('-v'), 3)], | 
| 919 format='%(relativeCreated)4d %(levelname)5s %(module)13s(' | 1010 format='%(relativeCreated)4d %(levelname)5s %(module)13s(' | 
| 920 '%(lineno)d) %(message)s') | 1011 '%(lineno)d) %(message)s') | 
| 921 unittest.main() | 1012 unittest.main() | 
| OLD | NEW |