diff options
author | pkaras <piotr.karas@nokia.com> | 2018-10-22 12:22:35 +0200 |
---|---|---|
committer | pkaras <piotr.karas@nokia.com> | 2018-10-22 14:20:44 +0200 |
commit | c7abba816ad7d702a9e01e9286e7661cb13fe11f (patch) | |
tree | 29d437a78d978867b504519033fad63b38c95d08 /tests/dcaegen2/prh-testcases/resources/simulator | |
parent | 1344ef2dd571923b5fa40f7c0863477df59d651b (diff) |
tests for ssl connection for PRH, AAI and DmaaP
Change-Id: I503a0749f22336b35b2633d372a3ef59d6bf71c8
Issue-ID: DCAEGEN2-880
Signed-off-by: piotr.karas <piotr.karas@nokia.com>
Diffstat (limited to 'tests/dcaegen2/prh-testcases/resources/simulator')
4 files changed, 57 insertions, 43 deletions
diff --git a/tests/dcaegen2/prh-testcases/resources/simulator/AAI.py b/tests/dcaegen2/prh-testcases/resources/simulator/AAI.py index b6c9c0f9..76823b0d 100644 --- a/tests/dcaegen2/prh-testcases/resources/simulator/AAI.py +++ b/tests/dcaegen2/prh-testcases/resources/simulator/AAI.py @@ -1,6 +1,9 @@ +import _thread +import re +import ssl +import time from http.server import BaseHTTPRequestHandler from http.server import HTTPServer -import _thread, ssl, time, re pnfs = 'Empty' diff --git a/tests/dcaegen2/prh-testcases/resources/simulator/AAI_simulator b/tests/dcaegen2/prh-testcases/resources/simulator/AAI_simulator index b44add60..7364769f 100644 --- a/tests/dcaegen2/prh-testcases/resources/simulator/AAI_simulator +++ b/tests/dcaegen2/prh-testcases/resources/simulator/AAI_simulator @@ -1,12 +1,4 @@ -FROM alpine:3.8 - -RUN apk add --no-cache python3 && \ - python3 -m ensurepip && \ - rm -r /usr/lib/python*/ensurepip && \ - pip3 install --upgrade pip setuptools && \ - if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi && \ - if [[ ! -e /usr/bin/python ]]; then ln -sf /usr/bin/python3 /usr/bin/python; fi && \ - rm -r /root/.cache +FROM python:3-alpine ADD AAI.py / COPY certs/* /certs/ diff --git a/tests/dcaegen2/prh-testcases/resources/simulator/DMaaP.py b/tests/dcaegen2/prh-testcases/resources/simulator/DMaaP.py index 85c36109..3ff951e8 100644 --- a/tests/dcaegen2/prh-testcases/resources/simulator/DMaaP.py +++ b/tests/dcaegen2/prh-testcases/resources/simulator/DMaaP.py @@ -1,13 +1,15 @@ +import _thread +import re +import ssl +import time from http.server import BaseHTTPRequestHandler from http.server import HTTPServer -import re -import sys posted_event_from_prh = b'Empty' received_event_to_get_method = b'Empty' -class DMaaPHandler(BaseHTTPRequestHandler): +class DmaapSetup(BaseHTTPRequestHandler): def do_PUT(self): if re.search('/set_get_event', self.path): @@ -15,25 +17,42 @@ class DMaaPHandler(BaseHTTPRequestHandler): content_length = int(self.headers['Content-Length']) received_event_to_get_method = self.rfile.read(content_length) _header_200_and_json(self) - + + return + + def do_GET(self): + if re.search('/events/pnfReady', self.path): + _header_200_and_json(self) + self.wfile.write(posted_event_from_prh) + return def do_POST(self): + if re.search('/reset', self.path): + global posted_event_from_prh + global received_event_to_get_method + posted_event_from_prh = b'Empty' + received_event_to_get_method = b'Empty' + _header_200_and_json(self) + + return + + +class DMaaPHandler(BaseHTTPRequestHandler): + + def do_POST(self): if re.search('/events/unauthenticated.PNF_READY', self.path): 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) - + return def do_GET(self): if re.search('/events/unauthenticated.VES_PNFREG_OUTPUT/OpenDcae-c12/c12', self.path): _header_200_and_json(self) self.wfile.write(received_event_to_get_method) - elif re.search('/events/pnfReady', self.path): - _header_200_and_json(self) - self.wfile.write(posted_event_from_prh) return @@ -44,21 +63,30 @@ def _header_200_and_json(self): self.end_headers() -def _main_(handler_class=DMaaPHandler, server_class=HTTPServer, protocol="HTTP/1.0"): - - if sys.argv[1:]: - port = int(sys.argv[1]) - else: - port = 2222 - - server_address = ('', port) - +def _main_(handler_class=DMaaPHandler, protocol="HTTP/1.0"): handler_class.protocol_version = protocol - httpd = server_class(server_address, handler_class) - - sa = httpd.socket.getsockname() - print("Serving HTTP on", sa[0], "port", sa[1], "...") - httpd.serve_forever() + _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)) + 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__': diff --git a/tests/dcaegen2/prh-testcases/resources/simulator/DMaaP_simulator b/tests/dcaegen2/prh-testcases/resources/simulator/DMaaP_simulator index 9cf21dc9..40e1af09 100644 --- a/tests/dcaegen2/prh-testcases/resources/simulator/DMaaP_simulator +++ b/tests/dcaegen2/prh-testcases/resources/simulator/DMaaP_simulator @@ -1,15 +1,6 @@ -FROM alpine:3.8 - -RUN apk add --no-cache python3 && \ - python3 -m ensurepip && \ - rm -r /usr/lib/python*/ensurepip && \ - pip3 install --upgrade pip setuptools && \ - if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi && \ - if [[ ! -e /usr/bin/python ]]; then ln -sf /usr/bin/python3 /usr/bin/python; fi && \ - rm -r /root/.cache +FROM python:3-alpine ADD DMaaP.py / - -EXPOSE 2222 +COPY certs/* /certs/ CMD [ "python", "./DMaaP.py" ] |