Mercurial > public > mercurial-scm > hg-stable
annotate tests/test-url.py @ 29451:676f4d0e3a7b stable
tests: import CPython's hostname matching tests
CPython has a more comprehensive test suite for it's built-in hostname
matching functionality. This patch adds its tests so we can improve
our hostname matching functionality.
Many of the tests have different results from CPython. These will be
addressed in a subsequent commit.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sun, 26 Jun 2016 19:16:54 -0700 |
parents | 63fe5ddb8715 |
children | 26a5d605b868 |
rev | line source |
---|---|
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
1 # coding=utf-8 |
28914
63fe5ddb8715
tests: make test-url use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28677
diff
changeset
|
2 from __future__ import absolute_import, print_function |
63fe5ddb8715
tests: make test-url use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28677
diff
changeset
|
3 |
63fe5ddb8715
tests: make test-url use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28677
diff
changeset
|
4 import doctest |
15398
474279be5add
tests: fix readline escape characters in heredoctest.py/test-url.py
Brodie Rao <brodie@bitheap.org>
parents:
15018
diff
changeset
|
5 import os |
12592
f2937d6492c5
url: verify correctness of https server certificates (issue2407)
Mads Kiilerich <mads@kiilerich.com>
parents:
diff
changeset
|
6 |
f2937d6492c5
url: verify correctness of https server certificates (issue2407)
Mads Kiilerich <mads@kiilerich.com>
parents:
diff
changeset
|
7 def check(a, b): |
f2937d6492c5
url: verify correctness of https server certificates (issue2407)
Mads Kiilerich <mads@kiilerich.com>
parents:
diff
changeset
|
8 if a != b: |
28677
2903558a6991
py3: make test-url use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
26421
diff
changeset
|
9 print((a, b)) |
12592
f2937d6492c5
url: verify correctness of https server certificates (issue2407)
Mads Kiilerich <mads@kiilerich.com>
parents:
diff
changeset
|
10 |
12606
5c8353692123
test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents:
12592
diff
changeset
|
11 def cert(cn): |
20685
56b1f39dd0c1
test-url: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
15611
diff
changeset
|
12 return {'subject': ((('commonName', cn),),)} |
12606
5c8353692123
test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents:
12592
diff
changeset
|
13 |
28914
63fe5ddb8715
tests: make test-url use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28677
diff
changeset
|
14 from mercurial import ( |
63fe5ddb8715
tests: make test-url use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28677
diff
changeset
|
15 sslutil, |
63fe5ddb8715
tests: make test-url use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28677
diff
changeset
|
16 ) |
12592
f2937d6492c5
url: verify correctness of https server certificates (issue2407)
Mads Kiilerich <mads@kiilerich.com>
parents:
diff
changeset
|
17 |
28914
63fe5ddb8715
tests: make test-url use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents:
28677
diff
changeset
|
18 _verifycert = sslutil._verifycert |
12724
66e7ba85585b
test-url: remove trailing whitespace
Augie Fackler <durin42@gmail.com>
parents:
12606
diff
changeset
|
19 # Test non-wildcard certificates |
12606
5c8353692123
test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents:
12592
diff
changeset
|
20 check(_verifycert(cert('example.com'), 'example.com'), |
5c8353692123
test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents:
12592
diff
changeset
|
21 None) |
5c8353692123
test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents:
12592
diff
changeset
|
22 check(_verifycert(cert('example.com'), 'www.example.com'), |
5c8353692123
test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents:
12592
diff
changeset
|
23 'certificate is for example.com') |
5c8353692123
test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents:
12592
diff
changeset
|
24 check(_verifycert(cert('www.example.com'), 'example.com'), |
5c8353692123
test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents:
12592
diff
changeset
|
25 'certificate is for www.example.com') |
12592
f2937d6492c5
url: verify correctness of https server certificates (issue2407)
Mads Kiilerich <mads@kiilerich.com>
parents:
diff
changeset
|
26 |
f2937d6492c5
url: verify correctness of https server certificates (issue2407)
Mads Kiilerich <mads@kiilerich.com>
parents:
diff
changeset
|
27 # Test wildcard certificates |
12606
5c8353692123
test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents:
12592
diff
changeset
|
28 check(_verifycert(cert('*.example.com'), 'www.example.com'), |
5c8353692123
test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents:
12592
diff
changeset
|
29 None) |
5c8353692123
test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents:
12592
diff
changeset
|
30 check(_verifycert(cert('*.example.com'), 'example.com'), |
5c8353692123
test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents:
12592
diff
changeset
|
31 'certificate is for *.example.com') |
5c8353692123
test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents:
12592
diff
changeset
|
32 check(_verifycert(cert('*.example.com'), 'w.w.example.com'), |
5c8353692123
test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents:
12592
diff
changeset
|
33 'certificate is for *.example.com') |
12592
f2937d6492c5
url: verify correctness of https server certificates (issue2407)
Mads Kiilerich <mads@kiilerich.com>
parents:
diff
changeset
|
34 |
13249
75d0c38a0bca
url: check subjectAltName when verifying ssl certificate
Yuya Nishihara <yuya@tcha.org>
parents:
13248
diff
changeset
|
35 # Test subjectAltName |
75d0c38a0bca
url: check subjectAltName when verifying ssl certificate
Yuya Nishihara <yuya@tcha.org>
parents:
13248
diff
changeset
|
36 san_cert = {'subject': ((('commonName', 'example.com'),),), |
75d0c38a0bca
url: check subjectAltName when verifying ssl certificate
Yuya Nishihara <yuya@tcha.org>
parents:
13248
diff
changeset
|
37 'subjectAltName': (('DNS', '*.example.net'), |
75d0c38a0bca
url: check subjectAltName when verifying ssl certificate
Yuya Nishihara <yuya@tcha.org>
parents:
13248
diff
changeset
|
38 ('DNS', 'example.net'))} |
75d0c38a0bca
url: check subjectAltName when verifying ssl certificate
Yuya Nishihara <yuya@tcha.org>
parents:
13248
diff
changeset
|
39 check(_verifycert(san_cert, 'example.net'), |
75d0c38a0bca
url: check subjectAltName when verifying ssl certificate
Yuya Nishihara <yuya@tcha.org>
parents:
13248
diff
changeset
|
40 None) |
75d0c38a0bca
url: check subjectAltName when verifying ssl certificate
Yuya Nishihara <yuya@tcha.org>
parents:
13248
diff
changeset
|
41 check(_verifycert(san_cert, 'foo.example.net'), |
75d0c38a0bca
url: check subjectAltName when verifying ssl certificate
Yuya Nishihara <yuya@tcha.org>
parents:
13248
diff
changeset
|
42 None) |
14666
27b080aa880a
sslutil: fall back to commonName when no dNSName in subjectAltName (issue2798)
Nicolas Bareil <nico@chdir.org>
parents:
14313
diff
changeset
|
43 # no fallback to subject commonName when subjectAltName has DNS |
13249
75d0c38a0bca
url: check subjectAltName when verifying ssl certificate
Yuya Nishihara <yuya@tcha.org>
parents:
13248
diff
changeset
|
44 check(_verifycert(san_cert, 'example.com'), |
75d0c38a0bca
url: check subjectAltName when verifying ssl certificate
Yuya Nishihara <yuya@tcha.org>
parents:
13248
diff
changeset
|
45 'certificate is for *.example.net, example.net') |
14666
27b080aa880a
sslutil: fall back to commonName when no dNSName in subjectAltName (issue2798)
Nicolas Bareil <nico@chdir.org>
parents:
14313
diff
changeset
|
46 # fallback to subject commonName when no DNS in subjectAltName |
27b080aa880a
sslutil: fall back to commonName when no dNSName in subjectAltName (issue2798)
Nicolas Bareil <nico@chdir.org>
parents:
14313
diff
changeset
|
47 san_cert = {'subject': ((('commonName', 'example.com'),),), |
27b080aa880a
sslutil: fall back to commonName when no dNSName in subjectAltName (issue2798)
Nicolas Bareil <nico@chdir.org>
parents:
14313
diff
changeset
|
48 'subjectAltName': (('IP Address', '8.8.8.8'),)} |
27b080aa880a
sslutil: fall back to commonName when no dNSName in subjectAltName (issue2798)
Nicolas Bareil <nico@chdir.org>
parents:
14313
diff
changeset
|
49 check(_verifycert(san_cert, 'example.com'), None) |
13249
75d0c38a0bca
url: check subjectAltName when verifying ssl certificate
Yuya Nishihara <yuya@tcha.org>
parents:
13248
diff
changeset
|
50 |
12592
f2937d6492c5
url: verify correctness of https server certificates (issue2407)
Mads Kiilerich <mads@kiilerich.com>
parents:
diff
changeset
|
51 # Avoid some pitfalls |
12606
5c8353692123
test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents:
12592
diff
changeset
|
52 check(_verifycert(cert('*.foo'), 'foo'), |
5c8353692123
test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents:
12592
diff
changeset
|
53 'certificate is for *.foo') |
5c8353692123
test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents:
12592
diff
changeset
|
54 check(_verifycert(cert('*o'), 'foo'), |
5c8353692123
test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents:
12592
diff
changeset
|
55 'certificate is for *o') |
12592
f2937d6492c5
url: verify correctness of https server certificates (issue2407)
Mads Kiilerich <mads@kiilerich.com>
parents:
diff
changeset
|
56 |
12742
6ab4a7d3c179
url: validity (notBefore/notAfter) is checked by OpenSSL (issue2407)
Mads Kiilerich <mads@kiilerich.com>
parents:
12738
diff
changeset
|
57 check(_verifycert({'subject': ()}, |
12606
5c8353692123
test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents:
12592
diff
changeset
|
58 'example.com'), |
13249
75d0c38a0bca
url: check subjectAltName when verifying ssl certificate
Yuya Nishihara <yuya@tcha.org>
parents:
13248
diff
changeset
|
59 'no commonName or subjectAltName found in certificate') |
12592
f2937d6492c5
url: verify correctness of https server certificates (issue2407)
Mads Kiilerich <mads@kiilerich.com>
parents:
diff
changeset
|
60 check(_verifycert(None, 'example.com'), |
12606
5c8353692123
test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents:
12592
diff
changeset
|
61 'no certificate received') |
13248
00411a4fa1bb
url: fix UnicodeDecodeError on certificate verification error
Yuya Nishihara <yuya@tcha.org>
parents:
12865
diff
changeset
|
62 |
14666
27b080aa880a
sslutil: fall back to commonName when no dNSName in subjectAltName (issue2798)
Nicolas Bareil <nico@chdir.org>
parents:
14313
diff
changeset
|
63 # Unicode (IDN) certname isn't supported |
27b080aa880a
sslutil: fall back to commonName when no dNSName in subjectAltName (issue2798)
Nicolas Bareil <nico@chdir.org>
parents:
14313
diff
changeset
|
64 check(_verifycert(cert(u'\u4f8b.jp'), 'example.jp'), |
27b080aa880a
sslutil: fall back to commonName when no dNSName in subjectAltName (issue2798)
Nicolas Bareil <nico@chdir.org>
parents:
14313
diff
changeset
|
65 'IDN in certificate not supported') |
27b080aa880a
sslutil: fall back to commonName when no dNSName in subjectAltName (issue2798)
Nicolas Bareil <nico@chdir.org>
parents:
14313
diff
changeset
|
66 |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
67 # The following tests are from CPython's test_ssl.py. |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
68 check(_verifycert(cert('example.com'), 'example.com'), None) |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
69 check(_verifycert(cert('example.com'), 'ExAmple.cOm'), None) |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
70 check(_verifycert(cert('example.com'), 'www.example.com'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
71 'certificate is for example.com') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
72 check(_verifycert(cert('example.com'), '.example.com'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
73 'certificate is for example.com') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
74 check(_verifycert(cert('example.com'), 'example.org'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
75 'certificate is for example.com') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
76 check(_verifycert(cert('example.com'), 'exampleXcom'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
77 'certificate is for example.com') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
78 check(_verifycert(cert('*.a.com'), 'foo.a.com'), None) |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
79 check(_verifycert(cert('*.a.com'), 'bar.foo.a.com'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
80 'certificate is for *.a.com') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
81 check(_verifycert(cert('*.a.com'), 'a.com'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
82 'certificate is for *.a.com') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
83 check(_verifycert(cert('*.a.com'), 'Xa.com'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
84 'certificate is for *.a.com') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
85 check(_verifycert(cert('*.a.com'), '.a.com'), None) |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
86 |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
87 # only match one left-most wildcard |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
88 check(_verifycert(cert('f*.com'), 'foo.com'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
89 'certificate is for f*.com') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
90 check(_verifycert(cert('f*.com'), 'f.com'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
91 'certificate is for f*.com') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
92 check(_verifycert(cert('f*.com'), 'bar.com'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
93 'certificate is for f*.com') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
94 check(_verifycert(cert('f*.com'), 'foo.a.com'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
95 'certificate is for f*.com') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
96 check(_verifycert(cert('f*.com'), 'bar.foo.com'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
97 'certificate is for f*.com') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
98 |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
99 # NULL bytes are bad, CVE-2013-4073 |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
100 check(_verifycert(cert('null.python.org\x00example.org'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
101 'null.python.org\x00example.org'), None) |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
102 check(_verifycert(cert('null.python.org\x00example.org'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
103 'example.org'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
104 'certificate is for null.python.org\x00example.org') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
105 check(_verifycert(cert('null.python.org\x00example.org'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
106 'null.python.org'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
107 'certificate is for null.python.org\x00example.org') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
108 |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
109 # error cases with wildcards |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
110 check(_verifycert(cert('*.*.a.com'), 'bar.foo.a.com'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
111 'certificate is for *.*.a.com') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
112 check(_verifycert(cert('*.*.a.com'), 'a.com'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
113 'certificate is for *.*.a.com') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
114 check(_verifycert(cert('*.*.a.com'), 'Xa.com'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
115 'certificate is for *.*.a.com') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
116 check(_verifycert(cert('*.*.a.com'), '.a.com'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
117 'certificate is for *.*.a.com') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
118 |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
119 check(_verifycert(cert('a.*.com'), 'a.foo.com'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
120 'certificate is for a.*.com') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
121 check(_verifycert(cert('a.*.com'), 'a..com'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
122 'certificate is for a.*.com') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
123 check(_verifycert(cert('a.*.com'), 'a.com'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
124 'certificate is for a.*.com') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
125 |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
126 # wildcard doesn't match IDNA prefix 'xn--' |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
127 idna = u'püthon.python.org'.encode('idna').decode('ascii') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
128 check(_verifycert(cert(idna), idna), None) |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
129 check(_verifycert(cert('x*.python.org'), idna), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
130 'certificate is for x*.python.org') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
131 check(_verifycert(cert('xn--p*.python.org'), idna), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
132 'certificate is for xn--p*.python.org') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
133 |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
134 # wildcard in first fragment and IDNA A-labels in sequent fragments |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
135 # are supported. |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
136 idna = u'www*.pythön.org'.encode('idna').decode('ascii') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
137 check(_verifycert(cert(idna), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
138 u'www.pythön.org'.encode('idna').decode('ascii')), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
139 'certificate is for www*.xn--pythn-mua.org') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
140 check(_verifycert(cert(idna), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
141 u'www1.pythön.org'.encode('idna').decode('ascii')), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
142 'certificate is for www*.xn--pythn-mua.org') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
143 check(_verifycert(cert(idna), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
144 u'ftp.pythön.org'.encode('idna').decode('ascii')), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
145 'certificate is for www*.xn--pythn-mua.org') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
146 check(_verifycert(cert(idna), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
147 u'pythön.org'.encode('idna').decode('ascii')), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
148 'certificate is for www*.xn--pythn-mua.org') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
149 |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
150 c = { |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
151 'notAfter': 'Jun 26 21:41:46 2011 GMT', |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
152 'subject': (((u'commonName', u'linuxfrz.org'),),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
153 'subjectAltName': ( |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
154 ('DNS', 'linuxfr.org'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
155 ('DNS', 'linuxfr.com'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
156 ('othername', '<unsupported>'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
157 ) |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
158 } |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
159 check(_verifycert(c, 'linuxfr.org'), None) |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
160 check(_verifycert(c, 'linuxfr.com'), None) |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
161 # Not a "DNS" entry |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
162 check(_verifycert(c, '<unsupported>'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
163 'certificate is for linuxfr.org, linuxfr.com') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
164 # When there is a subjectAltName, commonName isn't used |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
165 check(_verifycert(c, 'linuxfrz.org'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
166 'certificate is for linuxfr.org, linuxfr.com') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
167 |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
168 # A pristine real-world example |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
169 c = { |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
170 'notAfter': 'Dec 18 23:59:59 2011 GMT', |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
171 'subject': ( |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
172 ((u'countryName', u'US'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
173 ((u'stateOrProvinceName', u'California'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
174 ((u'localityName', u'Mountain View'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
175 ((u'organizationName', u'Google Inc'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
176 ((u'commonName', u'mail.google.com'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
177 ), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
178 } |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
179 check(_verifycert(c, 'mail.google.com'), None) |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
180 check(_verifycert(c, 'gmail.com'), 'certificate is for mail.google.com') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
181 |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
182 # Only commonName is considered |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
183 check(_verifycert(c, 'California'), 'certificate is for mail.google.com') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
184 |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
185 # Neither commonName nor subjectAltName |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
186 c = { |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
187 'notAfter': 'Dec 18 23:59:59 2011 GMT', |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
188 'subject': ( |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
189 ((u'countryName', u'US'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
190 ((u'stateOrProvinceName', u'California'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
191 ((u'localityName', u'Mountain View'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
192 ((u'organizationName', u'Google Inc'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
193 ), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
194 } |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
195 check(_verifycert(c, 'mail.google.com'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
196 'no commonName or subjectAltName found in certificate') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
197 |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
198 # No DNS entry in subjectAltName but a commonName |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
199 c = { |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
200 'notAfter': 'Dec 18 23:59:59 2099 GMT', |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
201 'subject': ( |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
202 ((u'countryName', u'US'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
203 ((u'stateOrProvinceName', u'California'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
204 ((u'localityName', u'Mountain View'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
205 ((u'commonName', u'mail.google.com'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
206 ), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
207 'subjectAltName': (('othername', 'blabla'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
208 } |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
209 check(_verifycert(c, 'mail.google.com'), None) |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
210 |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
211 # No DNS entry subjectAltName and no commonName |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
212 c = { |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
213 'notAfter': 'Dec 18 23:59:59 2099 GMT', |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
214 'subject': ( |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
215 ((u'countryName', u'US'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
216 ((u'stateOrProvinceName', u'California'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
217 ((u'localityName', u'Mountain View'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
218 ((u'organizationName', u'Google Inc'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
219 ), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
220 'subjectAltName': (('othername', 'blabla'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
221 } |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
222 check(_verifycert(c, 'google.com'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
223 'no commonName or subjectAltName found in certificate') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
224 |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
225 # Empty cert / no cert |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
226 check(_verifycert(None, 'example.com'), 'no certificate received') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
227 check(_verifycert({}, 'example.com'), 'no certificate received') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
228 |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
229 # avoid denials of service by refusing more than one |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
230 # wildcard per fragment. |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
231 check(_verifycert({'subject': (((u'commonName', u'a*b.com'),),)}, |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
232 'axxb.com'), 'certificate is for a*b.com') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
233 check(_verifycert({'subject': (((u'commonName', u'a*b.co*'),),)}, |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
234 'axxb.com'), 'certificate is for a*b.co*') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
235 check(_verifycert({'subject': (((u'commonName', u'a*b*.com'),),)}, |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
236 'axxbxxc.com'), 'certificate is for a*b*.com') |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
237 |
13770 | 238 def test_url(): |
239 """ | |
14076
924c82157d46
url: move URL parsing functions into util to improve startup time
Brodie Rao <brodie@bitheap.org>
parents:
13848
diff
changeset
|
240 >>> from mercurial.util import url |
13770 | 241 |
242 This tests for edge cases in url.URL's parsing algorithm. Most of | |
243 these aren't useful for documentation purposes, so they aren't | |
244 part of the class's doc tests. | |
245 | |
246 Query strings and fragments: | |
247 | |
248 >>> url('http://host/a?b#c') | |
249 <url scheme: 'http', host: 'host', path: 'a', query: 'b', fragment: 'c'> | |
250 >>> url('http://host/a?') | |
251 <url scheme: 'http', host: 'host', path: 'a'> | |
252 >>> url('http://host/a#b#c') | |
253 <url scheme: 'http', host: 'host', path: 'a', fragment: 'b#c'> | |
254 >>> url('http://host/a#b?c') | |
255 <url scheme: 'http', host: 'host', path: 'a', fragment: 'b?c'> | |
256 >>> url('http://host/?a#b') | |
257 <url scheme: 'http', host: 'host', path: '', query: 'a', fragment: 'b'> | |
13827
f1823b9f073b
url: nuke some newly-introduced underbars in identifiers
Matt Mackall <mpm@selenic.com>
parents:
13817
diff
changeset
|
258 >>> url('http://host/?a#b', parsequery=False) |
13770 | 259 <url scheme: 'http', host: 'host', path: '?a', fragment: 'b'> |
13827
f1823b9f073b
url: nuke some newly-introduced underbars in identifiers
Matt Mackall <mpm@selenic.com>
parents:
13817
diff
changeset
|
260 >>> url('http://host/?a#b', parsefragment=False) |
13770 | 261 <url scheme: 'http', host: 'host', path: '', query: 'a#b'> |
13827
f1823b9f073b
url: nuke some newly-introduced underbars in identifiers
Matt Mackall <mpm@selenic.com>
parents:
13817
diff
changeset
|
262 >>> url('http://host/?a#b', parsequery=False, parsefragment=False) |
13770 | 263 <url scheme: 'http', host: 'host', path: '?a#b'> |
264 | |
265 IPv6 addresses: | |
266 | |
267 >>> url('ldap://[2001:db8::7]/c=GB?objectClass?one') | |
268 <url scheme: 'ldap', host: '[2001:db8::7]', path: 'c=GB', | |
269 query: 'objectClass?one'> | |
270 >>> url('ldap://joe:xxx@[2001:db8::7]:80/c=GB?objectClass?one') | |
271 <url scheme: 'ldap', user: 'joe', passwd: 'xxx', host: '[2001:db8::7]', | |
272 port: '80', path: 'c=GB', query: 'objectClass?one'> | |
273 | |
274 Missing scheme, host, etc.: | |
275 | |
276 >>> url('://192.0.2.16:80/') | |
277 <url path: '://192.0.2.16:80/'> | |
26421
4b0fc75f9403
urls: bulk-change primary website URLs
Matt Mackall <mpm@selenic.com>
parents:
20685
diff
changeset
|
278 >>> url('https://mercurial-scm.org') |
4b0fc75f9403
urls: bulk-change primary website URLs
Matt Mackall <mpm@selenic.com>
parents:
20685
diff
changeset
|
279 <url scheme: 'https', host: 'mercurial-scm.org'> |
13770 | 280 >>> url('/foo') |
281 <url path: '/foo'> | |
282 >>> url('bundle:/foo') | |
283 <url scheme: 'bundle', path: '/foo'> | |
284 >>> url('a?b#c') | |
285 <url path: 'a?b', fragment: 'c'> | |
286 >>> url('http://x.com?arg=/foo') | |
287 <url scheme: 'http', host: 'x.com', query: 'arg=/foo'> | |
288 >>> url('http://joe:xxx@/foo') | |
289 <url scheme: 'http', user: 'joe', passwd: 'xxx', path: 'foo'> | |
290 | |
291 Just a scheme and a path: | |
292 | |
293 >>> url('mailto:John.Doe@example.com') | |
294 <url scheme: 'mailto', path: 'John.Doe@example.com'> | |
295 >>> url('a:b:c:d') | |
13808 | 296 <url path: 'a:b:c:d'> |
297 >>> url('aa:bb:cc:dd') | |
298 <url scheme: 'aa', path: 'bb:cc:dd'> | |
13770 | 299 |
300 SSH examples: | |
301 | |
302 >>> url('ssh://joe@host//home/joe') | |
303 <url scheme: 'ssh', user: 'joe', host: 'host', path: '/home/joe'> | |
304 >>> url('ssh://joe:xxx@host/src') | |
305 <url scheme: 'ssh', user: 'joe', passwd: 'xxx', host: 'host', path: 'src'> | |
306 >>> url('ssh://joe:xxx@host') | |
307 <url scheme: 'ssh', user: 'joe', passwd: 'xxx', host: 'host'> | |
308 >>> url('ssh://joe@host') | |
309 <url scheme: 'ssh', user: 'joe', host: 'host'> | |
310 >>> url('ssh://host') | |
311 <url scheme: 'ssh', host: 'host'> | |
312 >>> url('ssh://') | |
313 <url scheme: 'ssh'> | |
314 >>> url('ssh:') | |
315 <url scheme: 'ssh'> | |
316 | |
317 Non-numeric port: | |
318 | |
319 >>> url('http://example.com:dd') | |
320 <url scheme: 'http', host: 'example.com', port: 'dd'> | |
321 >>> url('ssh://joe:xxx@host:ssh/foo') | |
322 <url scheme: 'ssh', user: 'joe', passwd: 'xxx', host: 'host', port: 'ssh', | |
323 path: 'foo'> | |
324 | |
325 Bad authentication credentials: | |
326 | |
327 >>> url('http://joe@joeville:123@4:@host/a?b#c') | |
328 <url scheme: 'http', user: 'joe@joeville', passwd: '123@4:', | |
329 host: 'host', path: 'a', query: 'b', fragment: 'c'> | |
330 >>> url('http://!*#?/@!*#?/:@host/a?b#c') | |
331 <url scheme: 'http', host: '!*', fragment: '?/@!*#?/:@host/a?b#c'> | |
332 >>> url('http://!*#?@!*#?:@host/a?b#c') | |
333 <url scheme: 'http', host: '!*', fragment: '?@!*#?:@host/a?b#c'> | |
334 >>> url('http://!*@:!*@@host/a?b#c') | |
335 <url scheme: 'http', user: '!*@', passwd: '!*@', host: 'host', | |
336 path: 'a', query: 'b', fragment: 'c'> | |
337 | |
338 File paths: | |
339 | |
340 >>> url('a/b/c/d.g.f') | |
341 <url path: 'a/b/c/d.g.f'> | |
342 >>> url('/x///z/y/') | |
343 <url path: '/x///z/y/'> | |
13848
b2798c1defff
url: be stricter about detecting schemes
Brodie Rao <brodie@bitheap.org>
parents:
13827
diff
changeset
|
344 >>> url('/foo:bar') |
b2798c1defff
url: be stricter about detecting schemes
Brodie Rao <brodie@bitheap.org>
parents:
13827
diff
changeset
|
345 <url path: '/foo:bar'> |
b2798c1defff
url: be stricter about detecting schemes
Brodie Rao <brodie@bitheap.org>
parents:
13827
diff
changeset
|
346 >>> url('\\\\foo:bar') |
b2798c1defff
url: be stricter about detecting schemes
Brodie Rao <brodie@bitheap.org>
parents:
13827
diff
changeset
|
347 <url path: '\\\\foo:bar'> |
b2798c1defff
url: be stricter about detecting schemes
Brodie Rao <brodie@bitheap.org>
parents:
13827
diff
changeset
|
348 >>> url('./foo:bar') |
b2798c1defff
url: be stricter about detecting schemes
Brodie Rao <brodie@bitheap.org>
parents:
13827
diff
changeset
|
349 <url path: './foo:bar'> |
13770 | 350 |
13817
7f18bab2c0b0
url: abort on file:// URLs with non-localhost hosts
Brodie Rao <brodie@bitheap.org>
parents:
13808
diff
changeset
|
351 Non-localhost file URL: |
7f18bab2c0b0
url: abort on file:// URLs with non-localhost hosts
Brodie Rao <brodie@bitheap.org>
parents:
13808
diff
changeset
|
352 |
26421
4b0fc75f9403
urls: bulk-change primary website URLs
Matt Mackall <mpm@selenic.com>
parents:
20685
diff
changeset
|
353 >>> u = url('file://mercurial-scm.org/foo') |
13817
7f18bab2c0b0
url: abort on file:// URLs with non-localhost hosts
Brodie Rao <brodie@bitheap.org>
parents:
13808
diff
changeset
|
354 Traceback (most recent call last): |
7f18bab2c0b0
url: abort on file:// URLs with non-localhost hosts
Brodie Rao <brodie@bitheap.org>
parents:
13808
diff
changeset
|
355 File "<stdin>", line 1, in ? |
7f18bab2c0b0
url: abort on file:// URLs with non-localhost hosts
Brodie Rao <brodie@bitheap.org>
parents:
13808
diff
changeset
|
356 Abort: file:// URLs can only refer to localhost |
7f18bab2c0b0
url: abort on file:// URLs with non-localhost hosts
Brodie Rao <brodie@bitheap.org>
parents:
13808
diff
changeset
|
357 |
13770 | 358 Empty URL: |
359 | |
360 >>> u = url('') | |
361 >>> u | |
362 <url path: ''> | |
363 >>> str(u) | |
364 '' | |
365 | |
366 Empty path with query string: | |
367 | |
368 >>> str(url('http://foo/?bar')) | |
369 'http://foo/?bar' | |
370 | |
371 Invalid path: | |
372 | |
373 >>> u = url('http://foo/bar') | |
374 >>> u.path = 'bar' | |
375 >>> str(u) | |
376 'http://foo/bar' | |
377 | |
14313
a389dd285282
util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14204
diff
changeset
|
378 >>> u = url('file:/foo/bar/baz') |
a389dd285282
util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14204
diff
changeset
|
379 >>> u |
a389dd285282
util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14204
diff
changeset
|
380 <url scheme: 'file', path: '/foo/bar/baz'> |
a389dd285282
util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14204
diff
changeset
|
381 >>> str(u) |
a389dd285282
util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14204
diff
changeset
|
382 'file:///foo/bar/baz' |
15018
e89f62dcd723
url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents:
14666
diff
changeset
|
383 >>> u.localpath() |
e89f62dcd723
url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents:
14666
diff
changeset
|
384 '/foo/bar/baz' |
14313
a389dd285282
util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14204
diff
changeset
|
385 |
13770 | 386 >>> u = url('file:///foo/bar/baz') |
387 >>> u | |
388 <url scheme: 'file', path: '/foo/bar/baz'> | |
389 >>> str(u) | |
14313
a389dd285282
util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14204
diff
changeset
|
390 'file:///foo/bar/baz' |
15018
e89f62dcd723
url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents:
14666
diff
changeset
|
391 >>> u.localpath() |
e89f62dcd723
url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents:
14666
diff
changeset
|
392 '/foo/bar/baz' |
e89f62dcd723
url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents:
14666
diff
changeset
|
393 |
e89f62dcd723
url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents:
14666
diff
changeset
|
394 >>> u = url('file:///f:oo/bar/baz') |
e89f62dcd723
url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents:
14666
diff
changeset
|
395 >>> u |
e89f62dcd723
url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents:
14666
diff
changeset
|
396 <url scheme: 'file', path: 'f:oo/bar/baz'> |
e89f62dcd723
url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents:
14666
diff
changeset
|
397 >>> str(u) |
15611 | 398 'file:///f:oo/bar/baz' |
15018
e89f62dcd723
url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents:
14666
diff
changeset
|
399 >>> u.localpath() |
e89f62dcd723
url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents:
14666
diff
changeset
|
400 'f:oo/bar/baz' |
14313
a389dd285282
util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14204
diff
changeset
|
401 |
15496
396e83d635a6
url: handle file://localhost/c:/foo "correctly"
Mads Kiilerich <mads@kiilerich.com>
parents:
15398
diff
changeset
|
402 >>> u = url('file://localhost/f:oo/bar/baz') |
396e83d635a6
url: handle file://localhost/c:/foo "correctly"
Mads Kiilerich <mads@kiilerich.com>
parents:
15398
diff
changeset
|
403 >>> u |
396e83d635a6
url: handle file://localhost/c:/foo "correctly"
Mads Kiilerich <mads@kiilerich.com>
parents:
15398
diff
changeset
|
404 <url scheme: 'file', host: 'localhost', path: 'f:oo/bar/baz'> |
396e83d635a6
url: handle file://localhost/c:/foo "correctly"
Mads Kiilerich <mads@kiilerich.com>
parents:
15398
diff
changeset
|
405 >>> str(u) |
15513 | 406 'file://localhost/f:oo/bar/baz' |
15496
396e83d635a6
url: handle file://localhost/c:/foo "correctly"
Mads Kiilerich <mads@kiilerich.com>
parents:
15398
diff
changeset
|
407 >>> u.localpath() |
396e83d635a6
url: handle file://localhost/c:/foo "correctly"
Mads Kiilerich <mads@kiilerich.com>
parents:
15398
diff
changeset
|
408 'f:oo/bar/baz' |
396e83d635a6
url: handle file://localhost/c:/foo "correctly"
Mads Kiilerich <mads@kiilerich.com>
parents:
15398
diff
changeset
|
409 |
14313
a389dd285282
util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14204
diff
changeset
|
410 >>> u = url('file:foo/bar/baz') |
a389dd285282
util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14204
diff
changeset
|
411 >>> u |
a389dd285282
util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14204
diff
changeset
|
412 <url scheme: 'file', path: 'foo/bar/baz'> |
a389dd285282
util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14204
diff
changeset
|
413 >>> str(u) |
a389dd285282
util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14204
diff
changeset
|
414 'file:foo/bar/baz' |
15018
e89f62dcd723
url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents:
14666
diff
changeset
|
415 >>> u.localpath() |
e89f62dcd723
url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents:
14666
diff
changeset
|
416 'foo/bar/baz' |
13770 | 417 """ |
418 | |
15398
474279be5add
tests: fix readline escape characters in heredoctest.py/test-url.py
Brodie Rao <brodie@bitheap.org>
parents:
15018
diff
changeset
|
419 if 'TERM' in os.environ: |
474279be5add
tests: fix readline escape characters in heredoctest.py/test-url.py
Brodie Rao <brodie@bitheap.org>
parents:
15018
diff
changeset
|
420 del os.environ['TERM'] |
474279be5add
tests: fix readline escape characters in heredoctest.py/test-url.py
Brodie Rao <brodie@bitheap.org>
parents:
15018
diff
changeset
|
421 |
13770 | 422 doctest.testmod(optionflags=doctest.NORMALIZE_WHITESPACE) |