Mercurial > hg
annotate tests/test-url.py @ 39703:2fb88fa2b337
journal: do not pass in repolookuperror string to template (BC)
This doesn't look like data, but a warning message.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Mon, 03 Sep 2018 07:53:50 +0900 |
parents | d088810c496e |
children | 2372284d9457 |
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'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
23 b'certificate is for example.com') |
12606
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'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
25 b'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'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
31 b'certificate is for *.example.com') |
12606
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'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
33 b'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'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
45 b'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'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
53 b'certificate is for *.foo') |
29452
26a5d605b868
sslutil: synchronize hostname matching logic with CPython
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29451
diff
changeset
|
54 check(_verifycert(cert('*o'), 'foo'), None) |
12592
f2937d6492c5
url: verify correctness of https server certificates (issue2407)
Mads Kiilerich <mads@kiilerich.com>
parents:
diff
changeset
|
55 |
12742
6ab4a7d3c179
url: validity (notBefore/notAfter) is checked by OpenSSL (issue2407)
Mads Kiilerich <mads@kiilerich.com>
parents:
12738
diff
changeset
|
56 check(_verifycert({'subject': ()}, |
12606
5c8353692123
test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents:
12592
diff
changeset
|
57 'example.com'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
58 b'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
|
59 check(_verifycert(None, 'example.com'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
60 b'no certificate received') |
13248
00411a4fa1bb
url: fix UnicodeDecodeError on certificate verification error
Yuya Nishihara <yuya@tcha.org>
parents:
12865
diff
changeset
|
61 |
14666
27b080aa880a
sslutil: fall back to commonName when no dNSName in subjectAltName (issue2798)
Nicolas Bareil <nico@chdir.org>
parents:
14313
diff
changeset
|
62 # 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
|
63 check(_verifycert(cert(u'\u4f8b.jp'), 'example.jp'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
64 b'IDN in certificate not supported') |
14666
27b080aa880a
sslutil: fall back to commonName when no dNSName in subjectAltName (issue2798)
Nicolas Bareil <nico@chdir.org>
parents:
14313
diff
changeset
|
65 |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
66 # 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
|
67 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
|
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'), 'www.example.com'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
70 b'certificate is for example.com') |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
71 check(_verifycert(cert('example.com'), '.example.com'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
72 b'certificate is for example.com') |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
73 check(_verifycert(cert('example.com'), 'example.org'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
74 b'certificate is for example.com') |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
75 check(_verifycert(cert('example.com'), 'exampleXcom'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
76 b'certificate is for example.com') |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
77 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
|
78 check(_verifycert(cert('*.a.com'), 'bar.foo.a.com'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
79 b'certificate is for *.a.com') |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
80 check(_verifycert(cert('*.a.com'), 'a.com'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
81 b'certificate is for *.a.com') |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
82 check(_verifycert(cert('*.a.com'), 'Xa.com'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
83 b'certificate is for *.a.com') |
29452
26a5d605b868
sslutil: synchronize hostname matching logic with CPython
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29451
diff
changeset
|
84 check(_verifycert(cert('*.a.com'), '.a.com'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
85 b'certificate is for *.a.com') |
29451
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 |
29452
26a5d605b868
sslutil: synchronize hostname matching logic with CPython
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29451
diff
changeset
|
88 check(_verifycert(cert('f*.com'), 'foo.com'), None) |
26a5d605b868
sslutil: synchronize hostname matching logic with CPython
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29451
diff
changeset
|
89 check(_verifycert(cert('f*.com'), 'f.com'), None) |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
90 check(_verifycert(cert('f*.com'), 'bar.com'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
91 b'certificate is for f*.com') |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
92 check(_verifycert(cert('f*.com'), 'foo.a.com'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
93 b'certificate is for f*.com') |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
94 check(_verifycert(cert('f*.com'), 'bar.foo.com'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
95 b'certificate is for f*.com') |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
96 |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
97 # 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
|
98 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
|
99 'null.python.org\x00example.org'), None) |
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 'example.org'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
102 b'certificate is for null.python.org\x00example.org') |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
103 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
|
104 'null.python.org'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
105 b'certificate is for null.python.org\x00example.org') |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
106 |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
107 # error cases with wildcards |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
108 check(_verifycert(cert('*.*.a.com'), 'bar.foo.a.com'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
109 b'certificate is for *.*.a.com') |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
110 check(_verifycert(cert('*.*.a.com'), 'a.com'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
111 b'certificate is for *.*.a.com') |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
112 check(_verifycert(cert('*.*.a.com'), 'Xa.com'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
113 b'certificate is for *.*.a.com') |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
114 check(_verifycert(cert('*.*.a.com'), '.a.com'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
115 b'certificate is for *.*.a.com') |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
116 |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
117 check(_verifycert(cert('a.*.com'), 'a.foo.com'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
118 b'certificate is for a.*.com') |
29451
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..com'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
120 b'certificate is for a.*.com') |
29451
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'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
122 b'certificate is for a.*.com') |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
123 |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
124 # 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
|
125 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
|
126 check(_verifycert(cert(idna), idna), None) |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
127 check(_verifycert(cert('x*.python.org'), idna), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
128 b'certificate is for x*.python.org') |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
129 check(_verifycert(cert('xn--p*.python.org'), idna), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
130 b'certificate is for xn--p*.python.org') |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
131 |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
132 # 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
|
133 # are supported. |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
134 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
|
135 check(_verifycert(cert(idna), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
136 u'www.pythön.org'.encode('idna').decode('ascii')), |
29452
26a5d605b868
sslutil: synchronize hostname matching logic with CPython
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29451
diff
changeset
|
137 None) |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
138 check(_verifycert(cert(idna), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
139 u'www1.pythön.org'.encode('idna').decode('ascii')), |
29452
26a5d605b868
sslutil: synchronize hostname matching logic with CPython
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29451
diff
changeset
|
140 None) |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
141 check(_verifycert(cert(idna), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
142 u'ftp.pythön.org'.encode('idna').decode('ascii')), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
143 b'certificate is for www*.xn--pythn-mua.org') |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
144 check(_verifycert(cert(idna), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
145 u'pythön.org'.encode('idna').decode('ascii')), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
146 b'certificate is for www*.xn--pythn-mua.org') |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
147 |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
148 c = { |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
149 '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
|
150 'subject': (((u'commonName', u'linuxfrz.org'),),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
151 'subjectAltName': ( |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
152 ('DNS', 'linuxfr.org'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
153 ('DNS', 'linuxfr.com'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
154 ('othername', '<unsupported>'), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
155 ) |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
156 } |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
157 check(_verifycert(c, 'linuxfr.org'), None) |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
158 check(_verifycert(c, 'linuxfr.com'), None) |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
159 # Not a "DNS" entry |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
160 check(_verifycert(c, '<unsupported>'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
161 b'certificate is for linuxfr.org, linuxfr.com') |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
162 # 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
|
163 check(_verifycert(c, 'linuxfrz.org'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
164 b'certificate is for linuxfr.org, linuxfr.com') |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
165 |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
166 # A pristine real-world example |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
167 c = { |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
168 '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
|
169 'subject': ( |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
170 ((u'countryName', u'US'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
171 ((u'stateOrProvinceName', u'California'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
172 ((u'localityName', u'Mountain View'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
173 ((u'organizationName', u'Google Inc'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
174 ((u'commonName', u'mail.google.com'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
175 ), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
176 } |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
177 check(_verifycert(c, 'mail.google.com'), None) |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
178 check(_verifycert(c, 'gmail.com'), b'certificate is for mail.google.com') |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
179 |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
180 # Only commonName is considered |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
181 check(_verifycert(c, 'California'), b'certificate is for mail.google.com') |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
182 |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
183 # Neither commonName nor subjectAltName |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
184 c = { |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
185 '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
|
186 'subject': ( |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
187 ((u'countryName', u'US'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
188 ((u'stateOrProvinceName', u'California'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
189 ((u'localityName', u'Mountain View'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
190 ((u'organizationName', u'Google Inc'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
191 ), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
192 } |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
193 check(_verifycert(c, 'mail.google.com'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
194 b'no commonName or subjectAltName found in certificate') |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
195 |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
196 # 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
|
197 c = { |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
198 '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
|
199 'subject': ( |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
200 ((u'countryName', u'US'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
201 ((u'stateOrProvinceName', u'California'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
202 ((u'localityName', u'Mountain View'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
203 ((u'commonName', u'mail.google.com'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
204 ), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
205 'subjectAltName': (('othername', 'blabla'),), |
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 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
|
208 |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
209 # 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
|
210 c = { |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
211 '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
|
212 'subject': ( |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
213 ((u'countryName', u'US'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
214 ((u'stateOrProvinceName', u'California'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
215 ((u'localityName', u'Mountain View'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
216 ((u'organizationName', u'Google Inc'),), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
217 ), |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
218 'subjectAltName': (('othername', 'blabla'),), |
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 check(_verifycert(c, 'google.com'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
221 b'no commonName or subjectAltName found in certificate') |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
222 |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
223 # Empty cert / no cert |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
224 check(_verifycert(None, 'example.com'), b'no certificate received') |
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
225 check(_verifycert({}, 'example.com'), b'no certificate received') |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
226 |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
227 # 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
|
228 # wildcard per fragment. |
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
229 check(_verifycert({'subject': (((u'commonName', u'a*b.com'),),)}, |
29452
26a5d605b868
sslutil: synchronize hostname matching logic with CPython
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29451
diff
changeset
|
230 'axxb.com'), None) |
29451
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.co*'),),)}, |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
232 'axxb.com'), b'certificate is for a*b.co*') |
29451
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*.com'),),)}, |
29452
26a5d605b868
sslutil: synchronize hostname matching logic with CPython
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29451
diff
changeset
|
234 'axxbxxc.com'), |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
235 b'too many wildcards in certificate DNS name: a*b*.com') |
29451
676f4d0e3a7b
tests: import CPython's hostname matching tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28914
diff
changeset
|
236 |
13770 | 237 def test_url(): |
238 """ | |
37874
0dcd03637d36
tests: fix error case in test-url.py's doctest
Augie Fackler <augie@google.com>
parents:
29452
diff
changeset
|
239 >>> from mercurial import error, pycompat |
37955
d088810c496e
tests: fix deprecation warning in test-url.py
Augie Fackler <augie@google.com>
parents:
37875
diff
changeset
|
240 >>> from mercurial.util import url |
d088810c496e
tests: fix deprecation warning in test-url.py
Augie Fackler <augie@google.com>
parents:
37875
diff
changeset
|
241 >>> from mercurial.utils.stringutil import forcebytestr |
13770 | 242 |
243 This tests for edge cases in url.URL's parsing algorithm. Most of | |
244 these aren't useful for documentation purposes, so they aren't | |
245 part of the class's doc tests. | |
246 | |
247 Query strings and fragments: | |
248 | |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
249 >>> url(b'http://host/a?b#c') |
13770 | 250 <url scheme: 'http', host: 'host', path: 'a', query: 'b', fragment: 'c'> |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
251 >>> url(b'http://host/a?') |
13770 | 252 <url scheme: 'http', host: 'host', path: 'a'> |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
253 >>> url(b'http://host/a#b#c') |
13770 | 254 <url scheme: 'http', host: 'host', path: 'a', fragment: 'b#c'> |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
255 >>> url(b'http://host/a#b?c') |
13770 | 256 <url scheme: 'http', host: 'host', path: 'a', fragment: 'b?c'> |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
257 >>> url(b'http://host/?a#b') |
13770 | 258 <url scheme: 'http', host: 'host', path: '', query: 'a', fragment: 'b'> |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
259 >>> url(b'http://host/?a#b', parsequery=False) |
13770 | 260 <url scheme: 'http', host: 'host', path: '?a', fragment: 'b'> |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
261 >>> url(b'http://host/?a#b', parsefragment=False) |
13770 | 262 <url scheme: 'http', host: 'host', path: '', query: 'a#b'> |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
263 >>> url(b'http://host/?a#b', parsequery=False, parsefragment=False) |
13770 | 264 <url scheme: 'http', host: 'host', path: '?a#b'> |
265 | |
266 IPv6 addresses: | |
267 | |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
268 >>> url(b'ldap://[2001:db8::7]/c=GB?objectClass?one') |
13770 | 269 <url scheme: 'ldap', host: '[2001:db8::7]', path: 'c=GB', |
270 query: 'objectClass?one'> | |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
271 >>> url(b'ldap://joe:xxx@[2001:db8::7]:80/c=GB?objectClass?one') |
13770 | 272 <url scheme: 'ldap', user: 'joe', passwd: 'xxx', host: '[2001:db8::7]', |
273 port: '80', path: 'c=GB', query: 'objectClass?one'> | |
274 | |
275 Missing scheme, host, etc.: | |
276 | |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
277 >>> url(b'://192.0.2.16:80/') |
13770 | 278 <url path: '://192.0.2.16:80/'> |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
279 >>> url(b'https://mercurial-scm.org') |
26421
4b0fc75f9403
urls: bulk-change primary website URLs
Matt Mackall <mpm@selenic.com>
parents:
20685
diff
changeset
|
280 <url scheme: 'https', host: 'mercurial-scm.org'> |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
281 >>> url(b'/foo') |
13770 | 282 <url path: '/foo'> |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
283 >>> url(b'bundle:/foo') |
13770 | 284 <url scheme: 'bundle', path: '/foo'> |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
285 >>> url(b'a?b#c') |
13770 | 286 <url path: 'a?b', fragment: 'c'> |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
287 >>> url(b'http://x.com?arg=/foo') |
13770 | 288 <url scheme: 'http', host: 'x.com', query: 'arg=/foo'> |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
289 >>> url(b'http://joe:xxx@/foo') |
13770 | 290 <url scheme: 'http', user: 'joe', passwd: 'xxx', path: 'foo'> |
291 | |
292 Just a scheme and a path: | |
293 | |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
294 >>> url(b'mailto:John.Doe@example.com') |
13770 | 295 <url scheme: 'mailto', path: 'John.Doe@example.com'> |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
296 >>> url(b'a:b:c:d') |
13808 | 297 <url path: 'a:b:c:d'> |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
298 >>> url(b'aa:bb:cc:dd') |
13808 | 299 <url scheme: 'aa', path: 'bb:cc:dd'> |
13770 | 300 |
301 SSH examples: | |
302 | |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
303 >>> url(b'ssh://joe@host//home/joe') |
13770 | 304 <url scheme: 'ssh', user: 'joe', host: 'host', path: '/home/joe'> |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
305 >>> url(b'ssh://joe:xxx@host/src') |
13770 | 306 <url scheme: 'ssh', user: 'joe', passwd: 'xxx', host: 'host', path: 'src'> |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
307 >>> url(b'ssh://joe:xxx@host') |
13770 | 308 <url scheme: 'ssh', user: 'joe', passwd: 'xxx', host: 'host'> |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
309 >>> url(b'ssh://joe@host') |
13770 | 310 <url scheme: 'ssh', user: 'joe', host: 'host'> |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
311 >>> url(b'ssh://host') |
13770 | 312 <url scheme: 'ssh', host: 'host'> |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
313 >>> url(b'ssh://') |
13770 | 314 <url scheme: 'ssh'> |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
315 >>> url(b'ssh:') |
13770 | 316 <url scheme: 'ssh'> |
317 | |
318 Non-numeric port: | |
319 | |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
320 >>> url(b'http://example.com:dd') |
13770 | 321 <url scheme: 'http', host: 'example.com', port: 'dd'> |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
322 >>> url(b'ssh://joe:xxx@host:ssh/foo') |
13770 | 323 <url scheme: 'ssh', user: 'joe', passwd: 'xxx', host: 'host', port: 'ssh', |
324 path: 'foo'> | |
325 | |
326 Bad authentication credentials: | |
327 | |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
328 >>> url(b'http://joe@joeville:123@4:@host/a?b#c') |
13770 | 329 <url scheme: 'http', user: 'joe@joeville', passwd: '123@4:', |
330 host: 'host', path: 'a', query: 'b', fragment: 'c'> | |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
331 >>> url(b'http://!*#?/@!*#?/:@host/a?b#c') |
13770 | 332 <url scheme: 'http', host: '!*', fragment: '?/@!*#?/:@host/a?b#c'> |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
333 >>> url(b'http://!*#?@!*#?:@host/a?b#c') |
13770 | 334 <url scheme: 'http', host: '!*', fragment: '?@!*#?:@host/a?b#c'> |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
335 >>> url(b'http://!*@:!*@@host/a?b#c') |
13770 | 336 <url scheme: 'http', user: '!*@', passwd: '!*@', host: 'host', |
337 path: 'a', query: 'b', fragment: 'c'> | |
338 | |
339 File paths: | |
340 | |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
341 >>> url(b'a/b/c/d.g.f') |
13770 | 342 <url path: 'a/b/c/d.g.f'> |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
343 >>> url(b'/x///z/y/') |
13770 | 344 <url path: '/x///z/y/'> |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
345 >>> url(b'/foo:bar') |
13848
b2798c1defff
url: be stricter about detecting schemes
Brodie Rao <brodie@bitheap.org>
parents:
13827
diff
changeset
|
346 <url path: '/foo:bar'> |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
347 >>> url(b'\\\\foo:bar') |
13848
b2798c1defff
url: be stricter about detecting schemes
Brodie Rao <brodie@bitheap.org>
parents:
13827
diff
changeset
|
348 <url path: '\\\\foo:bar'> |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
349 >>> url(b'./foo:bar') |
13848
b2798c1defff
url: be stricter about detecting schemes
Brodie Rao <brodie@bitheap.org>
parents:
13827
diff
changeset
|
350 <url path: './foo:bar'> |
13770 | 351 |
13817
7f18bab2c0b0
url: abort on file:// URLs with non-localhost hosts
Brodie Rao <brodie@bitheap.org>
parents:
13808
diff
changeset
|
352 Non-localhost file URL: |
7f18bab2c0b0
url: abort on file:// URLs with non-localhost hosts
Brodie Rao <brodie@bitheap.org>
parents:
13808
diff
changeset
|
353 |
37874
0dcd03637d36
tests: fix error case in test-url.py's doctest
Augie Fackler <augie@google.com>
parents:
29452
diff
changeset
|
354 >>> try: |
0dcd03637d36
tests: fix error case in test-url.py's doctest
Augie Fackler <augie@google.com>
parents:
29452
diff
changeset
|
355 ... u = url(b'file://mercurial-scm.org/foo') |
0dcd03637d36
tests: fix error case in test-url.py's doctest
Augie Fackler <augie@google.com>
parents:
29452
diff
changeset
|
356 ... except error.Abort as e: |
0dcd03637d36
tests: fix error case in test-url.py's doctest
Augie Fackler <augie@google.com>
parents:
29452
diff
changeset
|
357 ... forcebytestr(e) |
0dcd03637d36
tests: fix error case in test-url.py's doctest
Augie Fackler <augie@google.com>
parents:
29452
diff
changeset
|
358 'file:// URLs can only refer to localhost' |
13817
7f18bab2c0b0
url: abort on file:// URLs with non-localhost hosts
Brodie Rao <brodie@bitheap.org>
parents:
13808
diff
changeset
|
359 |
13770 | 360 Empty URL: |
361 | |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
362 >>> u = url(b'') |
13770 | 363 >>> u |
364 <url path: ''> | |
365 >>> str(u) | |
366 '' | |
367 | |
368 Empty path with query string: | |
369 | |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
370 >>> str(url(b'http://foo/?bar')) |
13770 | 371 'http://foo/?bar' |
372 | |
373 Invalid path: | |
374 | |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
375 >>> u = url(b'http://foo/bar') |
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
376 >>> u.path = b'bar' |
13770 | 377 >>> str(u) |
378 'http://foo/bar' | |
379 | |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
380 >>> u = url(b'file:/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
|
381 >>> u |
a389dd285282
util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14204
diff
changeset
|
382 <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
|
383 >>> str(u) |
a389dd285282
util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14204
diff
changeset
|
384 'file:///foo/bar/baz' |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
385 >>> pycompat.bytestr(u.localpath()) |
15018
e89f62dcd723
url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents:
14666
diff
changeset
|
386 '/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
|
387 |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
388 >>> u = url(b'file:///foo/bar/baz') |
13770 | 389 >>> u |
390 <url scheme: 'file', path: '/foo/bar/baz'> | |
391 >>> str(u) | |
14313
a389dd285282
util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14204
diff
changeset
|
392 'file:///foo/bar/baz' |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
393 >>> pycompat.bytestr(u.localpath()) |
15018
e89f62dcd723
url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents:
14666
diff
changeset
|
394 '/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
|
395 |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
396 >>> u = url(b'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
|
397 >>> u |
e89f62dcd723
url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents:
14666
diff
changeset
|
398 <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
|
399 >>> str(u) |
15611 | 400 'file:///f:oo/bar/baz' |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
401 >>> pycompat.bytestr(u.localpath()) |
15018
e89f62dcd723
url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents:
14666
diff
changeset
|
402 '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
|
403 |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
404 >>> u = url(b'file://localhost/f:oo/bar/baz') |
15496
396e83d635a6
url: handle file://localhost/c:/foo "correctly"
Mads Kiilerich <mads@kiilerich.com>
parents:
15398
diff
changeset
|
405 >>> u |
396e83d635a6
url: handle file://localhost/c:/foo "correctly"
Mads Kiilerich <mads@kiilerich.com>
parents:
15398
diff
changeset
|
406 <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
|
407 >>> str(u) |
15513 | 408 'file://localhost/f:oo/bar/baz' |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
409 >>> pycompat.bytestr(u.localpath()) |
15496
396e83d635a6
url: handle file://localhost/c:/foo "correctly"
Mads Kiilerich <mads@kiilerich.com>
parents:
15398
diff
changeset
|
410 'f:oo/bar/baz' |
396e83d635a6
url: handle file://localhost/c:/foo "correctly"
Mads Kiilerich <mads@kiilerich.com>
parents:
15398
diff
changeset
|
411 |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
412 >>> u = url(b'file: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
|
413 >>> u |
a389dd285282
util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14204
diff
changeset
|
414 <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
|
415 >>> str(u) |
a389dd285282
util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
14204
diff
changeset
|
416 'file:foo/bar/baz' |
37875
078c3eec2d5c
tests: port test-url.py to Python 3
Augie Fackler <augie@google.com>
parents:
37874
diff
changeset
|
417 >>> pycompat.bytestr(u.localpath()) |
15018
e89f62dcd723
url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents:
14666
diff
changeset
|
418 'foo/bar/baz' |
13770 | 419 """ |
420 | |
15398
474279be5add
tests: fix readline escape characters in heredoctest.py/test-url.py
Brodie Rao <brodie@bitheap.org>
parents:
15018
diff
changeset
|
421 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
|
422 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
|
423 |
13770 | 424 doctest.testmod(optionflags=doctest.NORMALIZE_WHITESPACE) |