Skip to content

Instantly share code, notes, and snippets.

@czardoz
Created March 16, 2013 15:14
Show Gist options
  • Save czardoz/5176817 to your computer and use it in GitHub Desktop.
Save czardoz/5176817 to your computer and use it in GitHub Desktop.
HTTPS unittest
import gevent
import gevent.monkey
gevent.monkey.patch_all()
from hive.helpers.streamserver import HiveStreamServer
from hive.helpers.common import create_socket
from hive.capabilities import https
import unittest
import httplib
class HTTPS_Test(unittest.TestCase):
def test_connection(self):
""" Tests if the capability is up, and sending
HTTP 401 (Unauthorized) headers.
"""
sessions = {}
cap = https.https(sessions, {'enabled': 'True', 'port': 8081})
socket = create_socket(("0.0.0.0", 8081))
srv = HiveStreamServer(socket, cap.handle_session,
keyfile='dummy_key.key',
certfile='dummy_cert.crt' )
srv.start()
client = httplib.HTTPSConnection('127.0.0.1', 8081)
client.request("GET", "/")
response = client.getresponse()
self.assertEquals(response.status, 401)
if __name__ == '__main__':
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment