diff --git a/tests/libraries/test_requests.py b/tests/libraries/test_requests.py new file mode 100644 index 0000000000..4407e5dcb8 --- /dev/null +++ b/tests/libraries/test_requests.py @@ -0,0 +1,65 @@ +# ----------------------------------------------------------------------------- +# Copyright (c) 2014, PyInstaller Development Team. +# +# Distributed under the terms of the GNU General Public License with exception +# for distributing bootloader. +# +# The full license is in the file COPYING.txt, distributed with this software. +# ----------------------------------------------------------------------------- + +import BaseHTTPServer +import SimpleHTTPServer + +import os +import ssl +import sys +import threading +import time + +import requests + +""" +Note: to re-create the test_requests_server.pem file use the +following commands. + +cd /path/to/pyinstaller.git/tests/libraries +openssl req -new -x509 -keyout test_requests_server.pem \ + -out test_requests_server.pem -days 365 \ + -nodes -config test_requests_openssl.conf +""" + + +SERVER_PORT = 8443 +SERVER_CERT = os.path.join( + os.path.dirname(sys.executable), + u"test_requests_server.pem") + + +def ssl_server(): + # SSL server copied from here: + # http://www.piware.de/2011/01/creating-an-https-server-in-python/ + httpd = BaseHTTPServer.HTTPServer( + ('localhost', SERVER_PORT), + SimpleHTTPServer.SimpleHTTPRequestHandler) + httpd.socket = ssl.wrap_socket( + httpd.socket, certfile=SERVER_CERT, server_side=True) + httpd.serve_forever() + + +def main(): + # Start the SSL server + thread = threading.Thread(target=ssl_server) + thread.daemon = True + thread.start() + + # Wait a bit for the server to start + time.sleep(1) + + # Use requests to get a page from the server + requests.get( + u"https://localhost:{}".format(SERVER_PORT), + verify=SERVER_CERT) + # requests.get("https://github.com") + +if __name__ == '__main__': + main() diff --git a/tests/libraries/test_requests.spec b/tests/libraries/test_requests.spec new file mode 100644 index 0000000000..7e0a3e2673 --- /dev/null +++ b/tests/libraries/test_requests.spec @@ -0,0 +1,36 @@ +# -*- mode: python -*- +#----------------------------------------------------------------------------- +# Copyright (c) 2013, PyInstaller Development Team. +# +# Distributed under the terms of the GNU General Public License with exception +# for distributing bootloader. +# +# The full license is in the file COPYING.txt, distributed with this software. +#----------------------------------------------------------------------------- + + +__testname__ = 'test_requests' + +a = Analysis([__testname__ + '.py'], + pathex=[]) +pyz = PYZ(a.pure) + +TOC_custom = [('test_requests_server.pem','test_requests_server.pem','DATA')] + +exe = EXE(pyz, + a.scripts, + exclude_binaries=1, + name=__testname__ + '.exe', + debug=True, + strip=False, + upx=True, + console=True ) + +coll = COLLECT( exe, + a.binaries, + a.zipfiles, + a.datas, + TOC_custom, + strip=False, + upx=True, + name=__testname__) diff --git a/tests/libraries/test_requests_openssl.conf b/tests/libraries/test_requests_openssl.conf new file mode 100644 index 0000000000..9ed844abc2 --- /dev/null +++ b/tests/libraries/test_requests_openssl.conf @@ -0,0 +1,10 @@ +[ req ] +distinguished_name = req_distinguished_name +x509_extensions = v3_ca +[ alternate_names ] +DNS.1 = localhost +[ req_distinguished_name ] + commonName = Common Name + commonName_default = localhost +[ v3_ca ] + subjectAltName = @alternate_names diff --git a/tests/libraries/test_requests_server.pem b/tests/libraries/test_requests_server.pem new file mode 100644 index 0000000000..4899709972 --- /dev/null +++ b/tests/libraries/test_requests_server.pem @@ -0,0 +1,18 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIBOgIBAAJBALni+6hwnJKQg12wz22L5r3Wm5tz4aeC/3OnziiEUY/4IFv+N651 +DVoCI3LFDUA1lMp7UjR+omyrZtZvWmZfqa8CAwEAAQJABtGQsakP1UB/0Rv/P+F1 +4VjR9G3XxTFE9ZUeNtZDt6guY2PplKR/JqleAQvPSXaEwRyMhPwZYbmzNGmpmurc +gQIhAOMMJQuvl0cqEWvPq+88H92wkdAQYPK8NSoCQe+VxZifAiEA0ZcqABAb/F+X +nxm/NHTFZjV15oDonZrV+pSeFLW3hPECIGHjF4mtP3x3/6DKnSb8dgSfHo5ksVeV +mxosdP71RIajAiB1EVg2XMkk+Ef6aCkypZ607luCerJzhc7LfkOmEbIGIQIhANnJ +Cfpcqkonyl/2ZgEyhIFugFtQo+TKAOoautt2lhgW +-----END RSA PRIVATE KEY----- +-----BEGIN CERTIFICATE----- +MIIBODCB46ADAgECAgkA87ahT46HZfgwDQYJKoZIhvcNAQEFBQAwFDESMBAGA1UE +AwwJbG9jYWxob3N0MB4XDTE1MDExNTIxMTgwNVoXDTE2MDExNTIxMTgwNVowFDES +MBAGA1UEAwwJbG9jYWxob3N0MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALni+6hw +nJKQg12wz22L5r3Wm5tz4aeC/3OnziiEUY/4IFv+N651DVoCI3LFDUA1lMp7UjR+ +omyrZtZvWmZfqa8CAwEAAaMYMBYwFAYDVR0RBA0wC4IJbG9jYWxob3N0MA0GCSqG +SIb3DQEBBQUAA0EAtuRhYAM7E/CAvAipC29BgoGoihyJWljsVaSjfuneOMNMiNQb +aaU7A6Vi4QsE5+rExs/o5ysn4JrQMF4cDCR0lw== +-----END CERTIFICATE----- diff --git a/tests/runtests.py b/tests/runtests.py index d6450bfaef..fd6956d2eb 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -143,6 +143,7 @@ def __init__(self): 'libraries/test_pytz': ['pytz'], 'libraries/test_PyQt4-QtWebKit': ['PyQt4'], 'libraries/test_PyQt4-uic': ['PyQt4'], + 'libraries/test_requests': ['requests'], 'libraries/test_sysconfig': ['sysconfig'], 'libraries/test_scapy1': ['scapy'], 'libraries/test_scapy2': ['scapy'], @@ -266,6 +267,7 @@ def check(self, test_name): 'interactive/test_onefile_win32_uac_admin', 'libraries/test_Image', 'libraries/test_PIL', + 'libraries/test_requests', 'multipackage/test_multipackage1', 'multipackage/test_multipackage2', 'multipackage/test_multipackage3',