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

Side by Side Diff: tools/origin_trials/generate_token_unittest.py

Issue 1578793002: Add experimental framework token generation tool (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a header to satisfy licencecheck.pl, which can't check the LICENCE file. Created 4 years, 9 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 | « tools/origin_trials/generate_token.py ('k') | tools/origin_trials/third_party/ed25519/LICENSE » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 generate_token.py"""
7
8 import argparse
9 import generate_token
10 import unittest
11
12
13 class GenerateTokenTest(unittest.TestCase):
14
15 def test_hostname_validation(self):
16 for hostname, expected_result in [
17 ("", None),
18 (None, None),
19 ("example.com", "example.com"),
20 ("127.0.0.1", "127.0.0.1"),
21 ("localhost", "localhost"),
22 ("example.com.", "example.com"),
23 ("ExAmPlE.coM", "example.com"),
24 (".example.com", None),
25 ("example..com", None),
26 ("example123.com", "example123.com"),
27 ("123example.com", "123example.com"),
28 ("a.com", "a.com"),
29 ("1.com", "1.com"),
30 ("-.com", None),
31 ("aa.com", "aa.com"),
32 ("a1.com", "a1.com"),
33 ("a-.com", None),
34 ("-a.com", None),
35 ("123-example.com", "123-example.com"),
36 ("-123example.com", None),
37 ("123example-.com", None),
38 (("a"*63)+".com", ("a"*63)+".com"),
39 (("a"*64)+".com", None),
40 (".".join([("a"*15)]*16), ".".join([("a"*15)]*16)),
41 (".".join([("a"*15)]*17), None)]:
42 self.assertEqual(generate_token.HostnameFromArg(hostname),
43 expected_result)
44
45 def test_origin_constructed_correctly(self):
46 for origin_arg, expected_result in [
47 ("example.com", "https://example.com:443"),
48 ("https://example.com", "https://example.com:443"),
49 ("https://example.com/", "https://example.com:443"),
50 ("http://example.com", "http://example.com:80"),
51 ("http://127.0.0.1:8000", "http://127.0.0.1:8000"),
52 ("http://user:pass@example.com/path", "http://example.com:80")]:
53 self.assertEqual(generate_token.OriginFromArg(origin_arg),
54 expected_result)
55
56 def test_origin_fails_correctly(self):
57 for invalid_hostname in [
58 "example..com",
59 "gopher://gopher.tc.umn.edu",
60 "https://",
61 "https://example.com:NaN/",
62 "Not even close"]:
63 self.assertRaises(argparse.ArgumentTypeError,
64 generate_token.OriginFromArg,
65 invalid_hostname)
66
67 if __name__ == '__main__':
68 unittest.main()
OLDNEW
« no previous file with comments | « tools/origin_trials/generate_token.py ('k') | tools/origin_trials/third_party/ed25519/LICENSE » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698