test-url.py
48 lines
| 1.6 KiB
| text/x-python
|
PythonLexer
/ tests / test-url.py
|
r12592 | #!/usr/bin/env python | ||
def check(a, b): | ||||
if a != b: | ||||
print (a, b) | ||||
|
r12606 | def cert(cn): | ||
return dict(subject=((('commonName', cn),),)) | ||||
|
r12592 | from mercurial.url import _verifycert | ||
# Test non-wildcard certificates | ||||
|
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') | ||||
|
r12592 | |||
# Test wildcard certificates | ||||
|
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') | ||||
|
r12592 | |||
# Avoid some pitfalls | ||||
|
r12606 | check(_verifycert(cert('*.foo'), 'foo'), | ||
'certificate is for *.foo') | ||||
check(_verifycert(cert('*o'), 'foo'), | ||||
'certificate is for *o') | ||||
|
r12592 | |||
import time | ||||
lastyear = time.gmtime().tm_year - 1 | ||||
nextyear = time.gmtime().tm_year + 1 | ||||
|
r12606 | check(_verifycert({'notAfter': 'May 9 00:00:00 %s GMT' % lastyear}, | ||
'example.com'), | ||||
'certificate expired May 9 00:00:00 %s GMT' % lastyear) | ||||
check(_verifycert({'notBefore': 'May 9 00:00:00 %s GMT' % nextyear}, | ||||
'example.com'), | ||||
'certificate not valid before May 9 00:00:00 %s GMT' % nextyear) | ||||
check(_verifycert({'notAfter': 'Sep 29 15:29:48 %s GMT' % nextyear, | ||||
'subject': ()}, | ||||
'example.com'), | ||||
'no commonName found in certificate') | ||||
|
r12592 | check(_verifycert(None, 'example.com'), | ||
|
r12606 | 'no certificate received') | ||