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

Side by Side Diff: tools/origin_trials/validate_subdomain_origin/test_validate.py

Issue 2456053004: Validate origins when generating subdomain tokens (Closed)
Patch Set: Fix Windows compile error Created 4 years, 1 month 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
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright (c) 2016 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """Tests for the validate_subdomain_origin utility
7
8 usage: test_validate.py [-h] [--utility-path UTILITY_PATH]
9
10 """
11 import argparse
12 import os
13 import subprocess
14 import sys
15
16 script_dir = os.path.dirname(os.path.realpath(__file__))
17
18 STATUS_VALID = 0
19 STATUS_INVALID_ORIGIN = 1
20 STATUS_IN_PUBLIC_SUFFIX_LIST = 2
21 STATUS_ERROR = 3
22
23 TestOrigins = {
24 'https//': STATUS_INVALID_ORIGIN,
25 'https://example.com:xx': STATUS_INVALID_ORIGIN,
26 'https://google.com': STATUS_VALID,
27 'google.com': STATUS_VALID,
28 'http://10.0.0.1': STATUS_VALID,
29 '10.0.0.1': STATUS_VALID,
30 'https://com': STATUS_IN_PUBLIC_SUFFIX_LIST,
31 'https://com:443': STATUS_IN_PUBLIC_SUFFIX_LIST,
32 'com': STATUS_IN_PUBLIC_SUFFIX_LIST,
33 'co.uk': STATUS_IN_PUBLIC_SUFFIX_LIST,
34 'github.io': STATUS_IN_PUBLIC_SUFFIX_LIST,
35 'githubusercontent.com': STATUS_IN_PUBLIC_SUFFIX_LIST,
36 'https://adsf': STATUS_VALID,
37 'adsf': STATUS_VALID,
38 }
39
40 # Default utility path, relative to script_dir.
41 # - Assumes utility is compiled to standard output directory, e.g.
42 # <chromium dir>/src/out/Default
43 DEFAULT_UTILITY_PATH = '../../../out/Default/validate_subdomain_origin'
44
45 def main():
46 default_utility_path = os.path.join(script_dir, DEFAULT_UTILITY_PATH)
47
48 parser = argparse.ArgumentParser(
49 description="Test the validate_subdomain_origin utility")
50 parser.add_argument("--utility-path",
51 help="Path to the compiled utility",
52 default=default_utility_path)
53
54 args = parser.parse_args()
55
56 utility_path = os.path.expanduser(args.utility_path)
57 if not os.path.exists(utility_path):
58 print "ERROR"
59 print "Utility not found at: %s" % utility_path
60 print
61 sys.exit(1)
62
63 print "Using compiled utility found at: %s" % utility_path
64 print
65
66 failed_tests = 0
67
68 # Test handling of number of arguments
69 no_args_rc = subprocess.call(utility_path)
70 if no_args_rc != STATUS_ERROR:
71 failed_tests += 1
72 print "Test failed for no arguments: expected %d, actual %d" % (
73 STATUS_ERROR, no_args_rc)
74
75 too_many_args_rc = subprocess.call([utility_path, "first", "second"])
76 if too_many_args_rc != STATUS_ERROR:
77 failed_tests += 1
78 print "Test failed for 2 arguments: expected %d, actual %d" % (
79 STATUS_ERROR, too_many_args_rc)
80
81 # Test validation of various origins, and formats
82 for origin, expected_result in TestOrigins.items():
83 rc = subprocess.call([utility_path, origin])
84 if rc != expected_result:
85 failed_tests += 1
86 print "Test failed for '%s': expected %d, actual %d" % (
87 origin, expected_result, rc)
88 print
89 continue
90
91 if failed_tests > 0:
92 print "Failed %d tests" % failed_tests
93 print
94 sys.exit(1)
95
96 print "All tests passed"
97
98 if __name__ == "__main__":
99 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698