test-url.py
54 lines
| 1.7 KiB
| text/x-python
|
PythonLexer
/ tests / test-url.py
Augie Fackler
|
r12737 | import sys | ||
Mads Kiilerich
|
r12592 | |||
def check(a, b): | ||||
if a != b: | ||||
print (a, b) | ||||
Martin Geisler
|
r12606 | def cert(cn): | ||
return dict(subject=((('commonName', cn),),)) | ||||
Mads Kiilerich
|
r12592 | from mercurial.url import _verifycert | ||
Augie Fackler
|
r12724 | # Test non-wildcard certificates | ||
Martin Geisler
|
r12606 | check(_verifycert(cert('example.com'), 'example.com'), | ||
None) | ||||
check(_verifycert(cert('example.com'), 'www.example.com'), | ||||
'certificate is for example.com') | ||||
check(_verifycert(cert('www.example.com'), 'example.com'), | ||||
'certificate is for www.example.com') | ||||
Mads Kiilerich
|
r12592 | |||
# Test wildcard certificates | ||||
Martin Geisler
|
r12606 | check(_verifycert(cert('*.example.com'), 'www.example.com'), | ||
None) | ||||
check(_verifycert(cert('*.example.com'), 'example.com'), | ||||
'certificate is for *.example.com') | ||||
check(_verifycert(cert('*.example.com'), 'w.w.example.com'), | ||||
'certificate is for *.example.com') | ||||
Mads Kiilerich
|
r12592 | |||
Yuya Nishihara
|
r13249 | # Test subjectAltName | ||
san_cert = {'subject': ((('commonName', 'example.com'),),), | ||||
'subjectAltName': (('DNS', '*.example.net'), | ||||
('DNS', 'example.net'))} | ||||
check(_verifycert(san_cert, 'example.net'), | ||||
None) | ||||
check(_verifycert(san_cert, 'foo.example.net'), | ||||
None) | ||||
# subject is only checked when subjectAltName is empty | ||||
check(_verifycert(san_cert, 'example.com'), | ||||
'certificate is for *.example.net, example.net') | ||||
Mads Kiilerich
|
r12592 | # Avoid some pitfalls | ||
Martin Geisler
|
r12606 | check(_verifycert(cert('*.foo'), 'foo'), | ||
'certificate is for *.foo') | ||||
check(_verifycert(cert('*o'), 'foo'), | ||||
'certificate is for *o') | ||||
Mads Kiilerich
|
r12592 | |||
Mads Kiilerich
|
r12742 | check(_verifycert({'subject': ()}, | ||
Martin Geisler
|
r12606 | 'example.com'), | ||
Yuya Nishihara
|
r13249 | 'no commonName or subjectAltName found in certificate') | ||
Mads Kiilerich
|
r12592 | check(_verifycert(None, 'example.com'), | ||
Martin Geisler
|
r12606 | 'no certificate received') | ||
Yuya Nishihara
|
r13248 | |||
# Unicode (IDN) certname isn't supported | ||||
check(_verifycert(cert(u'\u4f8b.jp'), 'example.jp'), | ||||
'IDN in certificate not supported') | ||||