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