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

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

Issue 2456053004: Validate origins when generating subdomain tokens (Closed)
Patch Set: Address comments 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 'http': STATUS_INVALID_ORIGIN,
25 'https': STATUS_INVALID_ORIGIN,
26 'https//': STATUS_INVALID_ORIGIN,
27 'https://example.com:xx': STATUS_INVALID_ORIGIN,
28 'https://google.com': STATUS_VALID,
29 'google.com': STATUS_VALID,
30 'http://10.0.0.1': STATUS_VALID,
31 '10.0.0.1': STATUS_VALID,
32 'https://com': STATUS_IN_PUBLIC_SUFFIX_LIST,
33 'https://com:443': STATUS_IN_PUBLIC_SUFFIX_LIST,
34 'com': STATUS_IN_PUBLIC_SUFFIX_LIST,
35 'co.uk': STATUS_IN_PUBLIC_SUFFIX_LIST,
36 'github.io': STATUS_IN_PUBLIC_SUFFIX_LIST,
37 'githubusercontent.com': STATUS_IN_PUBLIC_SUFFIX_LIST,
38 'https://adsf': STATUS_VALID,
39 'adsf': STATUS_VALID,
40 }
41
42 # Default utility path, relative to script_dir.
43 # - Assumes utility is compiled to standard output directory, e.g.
44 # <chromium dir>/src/out/Default
45 DEFAULT_UTILITY_PATH = '../../../out/Default/validate_subdomain_origin'
46
47 def main():
48 default_utility_path = os.path.join(script_dir, DEFAULT_UTILITY_PATH)
49
50 parser = argparse.ArgumentParser(
51 description="Test the validate_subdomain_origin utility")
52 parser.add_argument("--utility-path",
53 help="Path to the compiled utility",
54 default=default_utility_path)
55
56 args = parser.parse_args()
57
58 if not os.path.exists(args.utility_path):
iclelland 2016/11/03 19:47:55 Can you call os.path.expanduser on this before usi
chasej 2016/11/03 21:13:10 Done.
59 print "ERROR"
60 print "Utility not found at: %s" % args.utility_path
61 print
62 sys.exit(1)
63
64 print "Using compiled utility found at: %s" % args.utility_path
65 print
66
67 failed_tests = 0
68
69 # Test handling of number of arguments
70 no_args_rc = subprocess.call(args.utility_path)
71 if no_args_rc != STATUS_ERROR:
72 failed_tests += 1
73 print "Test failed for no arguments: expected %d, actual %d" % (
74 STATUS_ERROR, no_args_rc)
75
76 too_many_args_rc = subprocess.call([args.utility_path, "first", "second"])
77 if too_many_args_rc != STATUS_ERROR:
78 failed_tests += 1
79 print "Test failed for 2 arguments: expected %d, actual %d" % (
80 STATUS_ERROR, too_many_args_rc)
81
82 # Test validation of various origins, and formats
83 for origin, expected_result in TestOrigins.items():
84 rc = subprocess.call([args.utility_path, origin])
85 if rc != expected_result:
86 failed_tests += 1
87 print "Test failed for '%s': expected %d, actual %d" % (
88 origin, expected_result, rc)
89 print
90 continue
91
92 if failed_tests > 0:
93 print "Failed %d tests" % failed_tests
94 print
95 sys.exit(1)
96
97 print "All tests passed"
98
99 if __name__ == "__main__":
100 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698