##// END OF EJS Templates
test-url: skip test when ssl module is unavailable
Augie Fackler -
r12725:24f16c2c default
parent child Browse files
Show More
@@ -1,48 +1,53
1 1 #!/usr/bin/env python
2 import sys
3 try:
4 import ssl
5 except ImportError:
6 sys.exit(80)
2 7
3 8 def check(a, b):
4 9 if a != b:
5 10 print (a, b)
6 11
7 12 def cert(cn):
8 13 return dict(subject=((('commonName', cn),),))
9 14
10 15 from mercurial.url import _verifycert
11 16
12 17 # Test non-wildcard certificates
13 18 check(_verifycert(cert('example.com'), 'example.com'),
14 19 None)
15 20 check(_verifycert(cert('example.com'), 'www.example.com'),
16 21 'certificate is for example.com')
17 22 check(_verifycert(cert('www.example.com'), 'example.com'),
18 23 'certificate is for www.example.com')
19 24
20 25 # Test wildcard certificates
21 26 check(_verifycert(cert('*.example.com'), 'www.example.com'),
22 27 None)
23 28 check(_verifycert(cert('*.example.com'), 'example.com'),
24 29 'certificate is for *.example.com')
25 30 check(_verifycert(cert('*.example.com'), 'w.w.example.com'),
26 31 'certificate is for *.example.com')
27 32
28 33 # Avoid some pitfalls
29 34 check(_verifycert(cert('*.foo'), 'foo'),
30 35 'certificate is for *.foo')
31 36 check(_verifycert(cert('*o'), 'foo'),
32 37 'certificate is for *o')
33 38
34 39 import time
35 40 lastyear = time.gmtime().tm_year - 1
36 41 nextyear = time.gmtime().tm_year + 1
37 42 check(_verifycert({'notAfter': 'May 9 00:00:00 %s GMT' % lastyear},
38 43 'example.com'),
39 44 'certificate expired May 9 00:00:00 %s GMT' % lastyear)
40 45 check(_verifycert({'notBefore': 'May 9 00:00:00 %s GMT' % nextyear},
41 46 'example.com'),
42 47 'certificate not valid before May 9 00:00:00 %s GMT' % nextyear)
43 48 check(_verifycert({'notAfter': 'Sep 29 15:29:48 %s GMT' % nextyear,
44 49 'subject': ()},
45 50 'example.com'),
46 51 'no commonName found in certificate')
47 52 check(_verifycert(None, 'example.com'),
48 53 'no certificate received')
General Comments 0
You need to be logged in to leave comments. Login now