tests/test-url.py
changeset 12742 6ab4a7d3c179
parent 12738 e9733f96b38b
child 12865 4c50552fc9bc
equal deleted inserted replaced
12741:949dfdb3ad2d 12742:6ab4a7d3c179
     1 #!/usr/bin/env python
     1 #!/usr/bin/env python
     2 import sys
     2 import sys
     3 try:
       
     4     import ssl
       
     5 except ImportError:
       
     6     sys.exit(80)
       
     7 
     3 
     8 def check(a, b):
     4 def check(a, b):
     9     if a != b:
     5     if a != b:
    10         print (a, b)
     6         print (a, b)
    11 
     7 
    34 check(_verifycert(cert('*.foo'), 'foo'),
    30 check(_verifycert(cert('*.foo'), 'foo'),
    35       'certificate is for *.foo')
    31       'certificate is for *.foo')
    36 check(_verifycert(cert('*o'), 'foo'),
    32 check(_verifycert(cert('*o'), 'foo'),
    37       'certificate is for *o')
    33       'certificate is for *o')
    38 
    34 
    39 import time
    35 check(_verifycert({'subject': ()},
    40 lastyear = time.gmtime().tm_year - 1
       
    41 nextyear = time.gmtime().tm_year + 1
       
    42 check(_verifycert({'notAfter': 'May  9 00:00:00 %s GMT' % lastyear},
       
    43                   'example.com'),
       
    44       'certificate expired May  9 00:00:00 %s GMT' % lastyear)
       
    45 check(_verifycert({'notBefore': 'May  9 00:00:00 %s GMT' % nextyear},
       
    46                   'example.com'),
       
    47       'certificate not valid before May  9 00:00:00 %s GMT' % nextyear)
       
    48 check(_verifycert({'notAfter': 'Sep 29 15:29:48 %s GMT' % nextyear,
       
    49                    'subject': ()},
       
    50                   'example.com'),
    36                   'example.com'),
    51       'no commonName found in certificate')
    37       'no commonName found in certificate')
    52 check(_verifycert(None, 'example.com'),
    38 check(_verifycert(None, 'example.com'),
    53       'no certificate received')
    39       'no certificate received')