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

Unified 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, 10 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/origin_trials/generate_token_unittest.py
diff --git a/tools/origin_trials/generate_token_unittest.py b/tools/origin_trials/generate_token_unittest.py
new file mode 100755
index 0000000000000000000000000000000000000000..06a2cc917be9d3e6174356cc1146f4f1f85b9302
--- /dev/null
+++ b/tools/origin_trials/generate_token_unittest.py
@@ -0,0 +1,68 @@
+#!/usr/bin/env python
+# Copyright (c) 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Tests for generate_token.py"""
+
+import argparse
+import generate_token
+import unittest
+
+
+class GenerateTokenTest(unittest.TestCase):
+
+ def test_hostname_validation(self):
+ for hostname, expected_result in [
+ ("", None),
+ (None, None),
+ ("example.com", "example.com"),
+ ("127.0.0.1", "127.0.0.1"),
+ ("localhost", "localhost"),
+ ("example.com.", "example.com"),
+ ("ExAmPlE.coM", "example.com"),
+ (".example.com", None),
+ ("example..com", None),
+ ("example123.com", "example123.com"),
+ ("123example.com", "123example.com"),
+ ("a.com", "a.com"),
+ ("1.com", "1.com"),
+ ("-.com", None),
+ ("aa.com", "aa.com"),
+ ("a1.com", "a1.com"),
+ ("a-.com", None),
+ ("-a.com", None),
+ ("123-example.com", "123-example.com"),
+ ("-123example.com", None),
+ ("123example-.com", None),
+ (("a"*63)+".com", ("a"*63)+".com"),
+ (("a"*64)+".com", None),
+ (".".join([("a"*15)]*16), ".".join([("a"*15)]*16)),
+ (".".join([("a"*15)]*17), None)]:
+ self.assertEqual(generate_token.HostnameFromArg(hostname),
+ expected_result)
+
+ def test_origin_constructed_correctly(self):
+ for origin_arg, expected_result in [
+ ("example.com", "https://example.com:443"),
+ ("https://example.com", "https://example.com:443"),
+ ("https://example.com/", "https://example.com:443"),
+ ("http://example.com", "http://example.com:80"),
+ ("http://127.0.0.1:8000", "http://127.0.0.1:8000"),
+ ("http://user:pass@example.com/path", "http://example.com:80")]:
+ self.assertEqual(generate_token.OriginFromArg(origin_arg),
+ expected_result)
+
+ def test_origin_fails_correctly(self):
+ for invalid_hostname in [
+ "example..com",
+ "gopher://gopher.tc.umn.edu",
+ "https://",
+ "https://example.com:NaN/",
+ "Not even close"]:
+ self.assertRaises(argparse.ArgumentTypeError,
+ generate_token.OriginFromArg,
+ invalid_hostname)
+
+if __name__ == '__main__':
+ unittest.main()
« 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