summaryrefslogtreecommitdiffstats
path: root/tests/dcaegen2/prh-testcases/resources/simulator/httpServerLib.py
diff options
context:
space:
mode:
authorpkaras <piotr.karas@nokia.com>2018-10-23 09:06:37 +0200
committerpkaras <piotr.karas@nokia.com>2018-10-23 09:26:15 +0200
commite416584e6f4acdc0ea3351add5d4bc08a5476af3 (patch)
tree47cb6807d0a16b94268ec610f55377ba3479a93c /tests/dcaegen2/prh-testcases/resources/simulator/httpServerLib.py
parentc7abba816ad7d702a9e01e9286e7661cb13fe11f (diff)
tests for ssl connection for PRH, AAI and DmaaP
Change-Id: If1e73dee9d517832852ae618d73e45da29052828 Issue-ID: DCAEGEN2-886 Signed-off-by: piotr.karas <piotr.karas@nokia.com>
Diffstat (limited to 'tests/dcaegen2/prh-testcases/resources/simulator/httpServerLib.py')
-rw-r--r--tests/dcaegen2/prh-testcases/resources/simulator/httpServerLib.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/dcaegen2/prh-testcases/resources/simulator/httpServerLib.py b/tests/dcaegen2/prh-testcases/resources/simulator/httpServerLib.py
new file mode 100644
index 00000000..dcfdb7ca
--- /dev/null
+++ b/tests/dcaegen2/prh-testcases/resources/simulator/httpServerLib.py
@@ -0,0 +1,34 @@
+import _thread
+import ssl
+from http.server import HTTPServer
+
+
+def header_200_and_json(self):
+ self.send_response(200)
+ self.send_header('Content-Type', 'application/json')
+ self.end_headers()
+
+
+def start_http_endpoint(port, handler_class):
+ _thread.start_new_thread(init_http_endpoints, (port, handler_class))
+
+
+def start_https_endpoint(port, handler_class, keyfile="certs/server.key",
+ certfile="certs/server.crt", ca_certs="certs/client.crt"):
+ _thread.start_new_thread(init_https_endpoints, (port, handler_class, keyfile, certfile, ca_certs))
+
+
+def init_http_endpoints(port, handler_class, server_class=HTTPServer):
+ server = server_class(('', port), handler_class)
+ sa = server.socket.getsockname()
+ print("Serving HTTP on", sa[0], "port", sa[1], "for", handler_class, "...")
+ server.serve_forever()
+
+
+def init_https_endpoints(port, handler_class, keyfile, certfile, ca_certs, server_class=HTTPServer):
+ server = server_class(('', port), handler_class)
+ server.socket = ssl.wrap_socket(server.socket, keyfile=keyfile, certfile=certfile,
+ ca_certs=ca_certs, server_side=True)
+ sa = server.socket.getsockname()
+ print("Serving HTTPS on", sa[0], "port", sa[1], "for", handler_class, "...")
+ server.serve_forever()