summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGary Wu <gary.i.wu@huawei.com>2018-10-23 14:41:11 +0000
committerGerrit Code Review <gerrit@onap.org>2018-10-23 14:41:11 +0000
commit37e3c0b51e55f84d4f9838c42b7433f2554632ee (patch)
treed81e3feead4508a1dae42047e69530faf5c2da01
parent5d59d1bf48fa2f0fbd433e8b25a207d62ddf8d22 (diff)
parente416584e6f4acdc0ea3351add5d4bc08a5476af3 (diff)
Merge "tests for ssl connection for PRH, AAI and DmaaP"
-rw-r--r--tests/dcaegen2/prh-testcases/resources/simulator/AAI.py38
-rw-r--r--tests/dcaegen2/prh-testcases/resources/simulator/AAI_simulator2
-rw-r--r--tests/dcaegen2/prh-testcases/resources/simulator/DMaaP.py43
-rw-r--r--tests/dcaegen2/prh-testcases/resources/simulator/DMaaP_simulator2
-rw-r--r--tests/dcaegen2/prh-testcases/resources/simulator/httpServerLib.py34
5 files changed, 52 insertions, 67 deletions
diff --git a/tests/dcaegen2/prh-testcases/resources/simulator/AAI.py b/tests/dcaegen2/prh-testcases/resources/simulator/AAI.py
index 76823b0d..416e7f45 100644
--- a/tests/dcaegen2/prh-testcases/resources/simulator/AAI.py
+++ b/tests/dcaegen2/prh-testcases/resources/simulator/AAI.py
@@ -1,9 +1,7 @@
-import _thread
import re
-import ssl
import time
from http.server import BaseHTTPRequestHandler
-from http.server import HTTPServer
+import httpServerLib
pnfs = 'Empty'
@@ -15,7 +13,7 @@ class AAISetup(BaseHTTPRequestHandler):
global pnfs
content_length = int(self.headers['Content-Length'])
pnfs = self.rfile.read(content_length)
- _header_200_and_json(self)
+ httpServerLib.header_200_and_json(self)
return
@@ -23,10 +21,11 @@ class AAISetup(BaseHTTPRequestHandler):
if re.search('/reset', self.path):
global pnfs
pnfs = 'Empty'
- _header_200_and_json(self)
+ httpServerLib.header_200_and_json(self)
return
+
class AAIHandler(BaseHTTPRequestHandler):
def do_PATCH(self):
@@ -41,37 +40,14 @@ class AAIHandler(BaseHTTPRequestHandler):
return
-def _header_200_and_json(self):
- self.send_response(200)
- self.send_header('Content-Type', 'application/json')
- self.end_headers()
-
-
def _main_(handler_class=AAIHandler, protocol="HTTP/1.0"):
handler_class.protocol_version = protocol
- _thread.start_new_thread(_init_http_endpoints, (3333, AAIHandler))
- _thread.start_new_thread(_init_https_endpoints, (3334, AAIHandler))
- _thread.start_new_thread(_init_http_endpoints, (3335, AAISetup))
+ httpServerLib.start_http_endpoint(3333, AAIHandler)
+ httpServerLib.start_https_endpoint(3334, AAIHandler)
+ httpServerLib.start_http_endpoint(3335, AAISetup)
while 1:
time.sleep(10)
-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, server_class=HTTPServer):
- server = server_class(('', port), handler_class)
- server.socket = ssl.wrap_socket(server.socket,
- keyfile="certs/server.key", certfile="certs/server.crt",
- ca_certs="certs/client.crt", server_side=True)
- sa = server.socket.getsockname()
- print("Serving HTTPS on", sa[0], "port", sa[1], "for", handler_class, "...")
- server.serve_forever()
-
-
if __name__ == '__main__':
_main_()
diff --git a/tests/dcaegen2/prh-testcases/resources/simulator/AAI_simulator b/tests/dcaegen2/prh-testcases/resources/simulator/AAI_simulator
index 7364769f..a906bc58 100644
--- a/tests/dcaegen2/prh-testcases/resources/simulator/AAI_simulator
+++ b/tests/dcaegen2/prh-testcases/resources/simulator/AAI_simulator
@@ -1,6 +1,6 @@
FROM python:3-alpine
-ADD AAI.py /
+ADD AAI.py httpServerLib.py /
COPY certs/* /certs/
CMD [ "python", "./AAI.py" ]
diff --git a/tests/dcaegen2/prh-testcases/resources/simulator/DMaaP.py b/tests/dcaegen2/prh-testcases/resources/simulator/DMaaP.py
index 3ff951e8..bb37ddd0 100644
--- a/tests/dcaegen2/prh-testcases/resources/simulator/DMaaP.py
+++ b/tests/dcaegen2/prh-testcases/resources/simulator/DMaaP.py
@@ -1,9 +1,7 @@
-import _thread
import re
-import ssl
import time
from http.server import BaseHTTPRequestHandler
-from http.server import HTTPServer
+import httpServerLib
posted_event_from_prh = b'Empty'
received_event_to_get_method = b'Empty'
@@ -16,13 +14,13 @@ class DmaapSetup(BaseHTTPRequestHandler):
global received_event_to_get_method
content_length = int(self.headers['Content-Length'])
received_event_to_get_method = self.rfile.read(content_length)
- _header_200_and_json(self)
+ httpServerLib.header_200_and_json(self)
return
def do_GET(self):
if re.search('/events/pnfReady', self.path):
- _header_200_and_json(self)
+ httpServerLib.header_200_and_json(self)
self.wfile.write(posted_event_from_prh)
return
@@ -33,7 +31,7 @@ class DmaapSetup(BaseHTTPRequestHandler):
global received_event_to_get_method
posted_event_from_prh = b'Empty'
received_event_to_get_method = b'Empty'
- _header_200_and_json(self)
+ httpServerLib.header_200_and_json(self)
return
@@ -45,49 +43,26 @@ class DMaaPHandler(BaseHTTPRequestHandler):
global posted_event_from_prh
content_length = int(self.headers['Content-Length'])
posted_event_from_prh = self.rfile.read(content_length)
- _header_200_and_json(self)
+ httpServerLib.header_200_and_json(self)
return
def do_GET(self):
if re.search('/events/unauthenticated.VES_PNFREG_OUTPUT/OpenDcae-c12/c12', self.path):
- _header_200_and_json(self)
+ httpServerLib.header_200_and_json(self)
self.wfile.write(received_event_to_get_method)
return
-def _header_200_and_json(self):
- self.send_response(200)
- self.send_header('Content-Type', 'application/json')
- self.end_headers()
-
-
def _main_(handler_class=DMaaPHandler, protocol="HTTP/1.0"):
handler_class.protocol_version = protocol
- _thread.start_new_thread(_init_http_endpoints, (2222, DMaaPHandler))
- _thread.start_new_thread(_init_https_endpoints, (2223, DMaaPHandler))
- _thread.start_new_thread(_init_http_endpoints, (2224, DmaapSetup))
+ httpServerLib.start_http_endpoint(2222, DMaaPHandler)
+ httpServerLib.start_https_endpoint(2223, DMaaPHandler)
+ httpServerLib.start_http_endpoint(2224, DmaapSetup)
while 1:
time.sleep(10)
-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, server_class=HTTPServer):
- server = server_class(('', port), handler_class)
- server.socket = ssl.wrap_socket(server.socket,
- keyfile="certs/server.key", certfile="certs/server.crt",
- ca_certs="certs/client.crt", server_side=True)
- sa = server.socket.getsockname()
- print("Serving HTTPS on", sa[0], "port", sa[1], "for", handler_class, "...")
- server.serve_forever()
-
-
if __name__ == '__main__':
_main_()
diff --git a/tests/dcaegen2/prh-testcases/resources/simulator/DMaaP_simulator b/tests/dcaegen2/prh-testcases/resources/simulator/DMaaP_simulator
index 40e1af09..8139fc33 100644
--- a/tests/dcaegen2/prh-testcases/resources/simulator/DMaaP_simulator
+++ b/tests/dcaegen2/prh-testcases/resources/simulator/DMaaP_simulator
@@ -1,6 +1,6 @@
FROM python:3-alpine
-ADD DMaaP.py /
+ADD DMaaP.py httpServerLib.py /
COPY certs/* /certs/
CMD [ "python", "./DMaaP.py" ]
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()