Commits

Oliver Tonnhofer committed 69bfa15

fixed HTTPS tests (from default branch 6515d9774077..8e9e69508910)

Comments (0)

Files changed (1)

mapproxy/test/unit/test_client.py

 
 from __future__ import with_statement
 
+import os
 import time
 import sys
 
 
 from nose.tools import eq_
 from nose.plugins.skip import SkipTest
+from nose.plugins.attrib import attr
 
 TESTSERVER_ADDRESS = ('127.0.0.1', 56413)
 TESTSERVER_URL = 'http://%s:%s' % TESTSERVER_ADDRESS
         else:
             assert False, 'expected HTTPClientError'
     
+    @attr('online')
     def test_https_no_ssl_module_error(self):
         from mapproxy.client import http
         old_ssl = http.ssl
         try:
             http.ssl = None
             try:
-                self.client = HTTPClient('https://trac.osgeo.org/')
+                self.client = HTTPClient('https://www.google.com/')
             except ImportError:
                 pass
             else:
         finally:
             http.ssl = old_ssl
     
+    @attr('online')
     def test_https_no_ssl_module_insecure(self):
         from mapproxy.client import http
         old_ssl = http.ssl
         try:
             http.ssl = None
-            self.client = HTTPClient('https://trac.osgeo.org/', insecure=True)
-            self.client.open('https://trac.osgeo.org/')
+            self.client = HTTPClient('https://www.google.com/', insecure=True)
+            self.client.open('https://www.google.com/')
         finally:
             http.ssl = old_ssl
     
+    @attr('online')
     def test_https_valid_cert(self):
         try:
             import ssl; ssl
         except ImportError:
             raise SkipTest()
         
-        with TempFile() as tmp:
-            with open(tmp, 'w') as f:
-                f.write(OSGEO_CERT)
-            self.client = HTTPClient('https://trac.osgeo.org/', ssl_ca_certs=tmp)
-            self.client.open('https://trac.osgeo.org/')
+        cert_file = '/etc/ssl/certs/ca-certificates.crt'
+        if os.path.exists(cert_file):
+            self.client = HTTPClient('https://www.google.com/', ssl_ca_certs=cert_file)
+            self.client.open('https://www.google.com/')
+        else:
+            with TempFile() as tmp:
+                with open(tmp, 'w') as f:
+                    f.write(GOOGLE_ROOT_CERT)
+                self.client = HTTPClient('https://www.google.com/', ssl_ca_certs=tmp)
+                self.client.open('https://www.google.com/')
     
+    @attr('online')
     def test_https_invalid_cert(self):
         try:
             import ssl; ssl
             raise SkipTest()
         
         with TempFile() as tmp:
-            self.client = HTTPClient('https://trac.osgeo.org/', ssl_ca_certs=tmp)
+            self.client = HTTPClient('https://www.google.com/', ssl_ca_certs=tmp)
             try:
-                self.client.open('https://trac.osgeo.org/')
+                self.client.open('https://www.google.com/')
             except HTTPClientError, e:
                 assert_re(e.args[0], r'Could not verify connection to URL')
         
 
         mapproxy.client.http._max_set_timeout = old_timeout
 
-        
-OSGEO_CERT = """
+# Equifax Secure Certificate Authority
+# Expires: 2018-08-22
+GOOGLE_ROOT_CERT = """
 -----BEGIN CERTIFICATE-----
-MIIE2DCCBEGgAwIBAgIEN0rSQzANBgkqhkiG9w0BAQUFADCBwzELMAkGA1UEBhMC
-VVMxFDASBgNVBAoTC0VudHJ1c3QubmV0MTswOQYDVQQLEzJ3d3cuZW50cnVzdC5u
-ZXQvQ1BTIGluY29ycC4gYnkgcmVmLiAobGltaXRzIGxpYWIuKTElMCMGA1UECxMc
-KGMpIDE5OTkgRW50cnVzdC5uZXQgTGltaXRlZDE6MDgGA1UEAxMxRW50cnVzdC5u
-ZXQgU2VjdXJlIFNlcnZlciBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw05OTA1
-MjUxNjA5NDBaFw0xOTA1MjUxNjM5NDBaMIHDMQswCQYDVQQGEwJVUzEUMBIGA1UE
-ChMLRW50cnVzdC5uZXQxOzA5BgNVBAsTMnd3dy5lbnRydXN0Lm5ldC9DUFMgaW5j
-b3JwLiBieSByZWYuIChsaW1pdHMgbGlhYi4pMSUwIwYDVQQLExwoYykgMTk5OSBF
-bnRydXN0Lm5ldCBMaW1pdGVkMTowOAYDVQQDEzFFbnRydXN0Lm5ldCBTZWN1cmUg
-U2VydmVyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIGdMA0GCSqGSIb3DQEBAQUA
-A4GLADCBhwKBgQDNKIM0VBuJ8w+vN5Ex/68xYMmo6LIQaO2f55M28Qpku0f1BBc/
-I0dNxScZgSY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