Show More
@@ -4,38 +4,45 b' def check(a, b):' | |||
|
4 | 4 | if a != b: |
|
5 | 5 | print (a, b) |
|
6 | 6 | |
|
7 | def cert(cn): | |
|
8 | return dict(subject=((('commonName', cn),),)) | |
|
9 | ||
|
7 | 10 | from mercurial.url import _verifycert |
|
8 | 11 | |
|
9 | 12 | # Test non-wildcard certificates |
|
10 |
check(_verifycert( |
|
|
13 | check(_verifycert(cert('example.com'), 'example.com'), | |
|
11 | 14 | None) |
|
12 |
check(_verifycert( |
|
|
15 | check(_verifycert(cert('example.com'), 'www.example.com'), | |
|
13 | 16 | 'certificate is for example.com') |
|
14 |
check(_verifycert( |
|
|
17 | check(_verifycert(cert('www.example.com'), 'example.com'), | |
|
15 | 18 | 'certificate is for www.example.com') |
|
16 | 19 | |
|
17 | 20 | # Test wildcard certificates |
|
18 |
check(_verifycert( |
|
|
21 | check(_verifycert(cert('*.example.com'), 'www.example.com'), | |
|
19 | 22 | None) |
|
20 |
check(_verifycert( |
|
|
23 | check(_verifycert(cert('*.example.com'), 'example.com'), | |
|
21 | 24 | 'certificate is for *.example.com') |
|
22 |
check(_verifycert( |
|
|
25 | check(_verifycert(cert('*.example.com'), 'w.w.example.com'), | |
|
23 | 26 | 'certificate is for *.example.com') |
|
24 | 27 | |
|
25 | 28 | # Avoid some pitfalls |
|
26 |
check(_verifycert( |
|
|
29 | check(_verifycert(cert('*.foo'), 'foo'), | |
|
27 | 30 | 'certificate is for *.foo') |
|
28 |
check(_verifycert( |
|
|
31 | check(_verifycert(cert('*o'), 'foo'), | |
|
29 | 32 | 'certificate is for *o') |
|
30 | 33 | |
|
31 | 34 | import time |
|
32 | 35 | lastyear = time.gmtime().tm_year - 1 |
|
33 | 36 | nextyear = time.gmtime().tm_year + 1 |
|
34 |
check(_verifycert({'notAfter': 'May 9 00:00:00 %s GMT' % lastyear}, |
|
|
37 | check(_verifycert({'notAfter': 'May 9 00:00:00 %s GMT' % lastyear}, | |
|
38 | 'example.com'), | |
|
35 | 39 | 'certificate expired May 9 00:00:00 %s GMT' % lastyear) |
|
36 |
check(_verifycert({'notBefore': 'May 9 00:00:00 %s GMT' % nextyear}, |
|
|
40 | check(_verifycert({'notBefore': 'May 9 00:00:00 %s GMT' % nextyear}, | |
|
41 | 'example.com'), | |
|
37 | 42 | 'certificate not valid before May 9 00:00:00 %s GMT' % nextyear) |
|
38 |
check(_verifycert({'notAfter': 'Sep 29 15:29:48 %s GMT' % nextyear, |
|
|
43 | check(_verifycert({'notAfter': 'Sep 29 15:29:48 %s GMT' % nextyear, | |
|
44 | 'subject': ()}, | |
|
45 | 'example.com'), | |
|
39 | 46 | 'no commonName found in certificate') |
|
40 | 47 | check(_verifycert(None, 'example.com'), |
|
41 | 48 | 'no certificate received') |
General Comments 0
You need to be logged in to leave comments.
Login now