From 673558028fa7cd77d4c16c52113167b2d4d8021d Mon Sep 17 00:00:00 2001 From: ecaiyanlinux Date: Mon, 11 May 2020 12:53:23 +0200 Subject: [PATCH] Update mrstub with nginx Support http/https for mrstub http port 3905 https port 3906 Add timeout for mr AGENT_READ_URL Issue-ID: NONRTRIC-208 Change-Id: I222906b705f273b2e582ad8ce80fa88b2e582824 Signed-off-by: Chengkai Yan --- test/auto-test/.gitignore | 2 + test/mrstub/Dockerfile | 31 ++- test/mrstub/app/main.py | 295 +++++++++++++++++++++++++++ test/mrstub/app/nginx.conf | 100 +++++++++ test/mrstub/app/requirements.txt | 2 + test/mrstub/{ => app}/start.sh | 8 +- test/mrstub/basic_test.sh | 8 +- test/mrstub/{nginx_wsgi_flask => }/cert/pass | 0 test/mrstub/frontend.js | 117 ----------- test/mrstub/mr.py | 276 ------------------------- test/mrstub/nginx_wsgi_flask/Dockerfile | 25 --- test/mrstub/nginx_wsgi_flask/app/main.py | 276 ------------------------- test/mrstub/nginx_wsgi_flask/app/nginx.conf | 58 ------ test/mrstub/nginx_wsgi_flask/app/prestart.sh | 22 -- test/mrstub/nginx_wsgi_flask/app/uwsgi.ini | 21 -- test/mrstub/nginx_wsgi_flask/basic_test.sh | 135 ------------ test/mrstub/nginx_wsgi_flask/cert/cert.crt | 16 -- test/mrstub/nginx_wsgi_flask/cert/key.crt | 30 --- test/mrstub/nginx_wsgi_flask/start-mr.sh | 21 -- test/mrstub/package.json | 65 ------ test/mrstub/requirements.txt | 5 - test/simulator-group/mr/cert/pass | 1 + 22 files changed, 422 insertions(+), 1092 deletions(-) create mode 100644 test/mrstub/app/main.py create mode 100644 test/mrstub/app/nginx.conf create mode 100644 test/mrstub/app/requirements.txt rename test/mrstub/{ => app}/start.sh (91%) rename test/mrstub/{nginx_wsgi_flask => }/cert/pass (100%) delete mode 100644 test/mrstub/frontend.js delete mode 100644 test/mrstub/mr.py delete mode 100644 test/mrstub/nginx_wsgi_flask/Dockerfile delete mode 100644 test/mrstub/nginx_wsgi_flask/app/main.py delete mode 100644 test/mrstub/nginx_wsgi_flask/app/nginx.conf delete mode 100644 test/mrstub/nginx_wsgi_flask/app/prestart.sh delete mode 100644 test/mrstub/nginx_wsgi_flask/app/uwsgi.ini delete mode 100755 test/mrstub/nginx_wsgi_flask/basic_test.sh delete mode 100644 test/mrstub/nginx_wsgi_flask/cert/cert.crt delete mode 100644 test/mrstub/nginx_wsgi_flask/cert/key.crt delete mode 100755 test/mrstub/nginx_wsgi_flask/start-mr.sh delete mode 100644 test/mrstub/package.json delete mode 100644 test/mrstub/requirements.txt create mode 100644 test/simulator-group/mr/cert/pass diff --git a/test/auto-test/.gitignore b/test/auto-test/.gitignore index 602c2fb7..7f08b380 100644 --- a/test/auto-test/.gitignore +++ b/test/auto-test/.gitignore @@ -9,3 +9,5 @@ logs .consul* .ext.consul* .dockererr +.sdnc-reply.json +.sndc.payload.json diff --git a/test/mrstub/Dockerfile b/test/mrstub/Dockerfile index ea867adc..9a15bc39 100644 --- a/test/mrstub/Dockerfile +++ b/test/mrstub/Dockerfile @@ -15,27 +15,22 @@ # ============LICENSE_END================================================= # -#Dockerfile to create an image with both python3.8 and nodejs 14 -FROM python:3.8 +FROM python:3.8-slim-buster -WORKDIR /usr/src/app +COPY app/ /usr/src/app/ -#Install python modules -COPY requirements.txt requirements.txt -RUN pip install -r requirements.txt +WORKDIR /usr/src/app/ + +RUN chmod +x start.sh -#Install nodejs and packages -RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - -RUN apt-get install -y nodejs -COPY package.json package.json -RUN npm install express -RUN npm install express-http-proxy +#install nginx +RUN apt-get update +RUN apt-get install -y nginx=1.14.* -#Copy apps and start script -COPY mr.py mr.py -COPY frontend.js frontend.js -COPY start.sh start.sh +#install curl +RUN apt-get install -y curl -RUN chmod +x ./start.sh +#start mrstub +RUN pip install -r requirements.txt -CMD ["./start.sh"] \ No newline at end of file +CMD [ "./start.sh" ] \ No newline at end of file diff --git a/test/mrstub/app/main.py b/test/mrstub/app/main.py new file mode 100644 index 00000000..5bb09885 --- /dev/null +++ b/test/mrstub/app/main.py @@ -0,0 +1,295 @@ + +# ============LICENSE_START=============================================== +# Copyright (C) 2020 Nordix Foundation. All rights reserved. +# ======================================================================== +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END================================================= +# + +from flask import Flask, request +from time import sleep +import time +import datetime +import json +from flask import Flask +from flask import Response +import traceback +from threading import RLock + +app = Flask(__name__) +lock = RLock() +# list of messages to/from Dmaap +msg_requests=[] +msg_responses={} + +# Server info +HOST_IP = "::" +HOST_PORT = 2222 + +# Metrics vars +cntr_msg_requests_submitted=0 +cntr_msg_requests_fetched=0 +cntr_msg_responses_submitted=0 +cntr_msg_responses_fetched=0 + +# Request and response constants +AGENT_WRITE_URL="/events/A1-POLICY-AGENT-WRITE" +AGENT_READ_URL="/events/A1-POLICY-AGENT-READ/users/policy-agent" +APP_WRITE_URL="/send-request" +APP_READ_URL="/receive-response" +MIME_TEXT="text/plain" +MIME_JSON="application/json" +CAUGHT_EXCEPTION="Caught exception: " +SERVER_ERROR="Server error :" + +#I'm alive function +@app.route('/', + methods=['GET']) +def index(): + return 'OK', 200 + + +# Helper function to create a Dmaap request message +# args : +# response: json formatted string of a complete Dmaap message +def create_message(operation, correlation_id, payload, url): + if (payload is None): + payload="{}" + time_stamp=datetime.datetime.utcnow() + msg = '{\"apiVersion\":\"1.0\",\"operation\":\"'+operation+'\",\"correlationId\":\"'+correlation_id+'\",\"originatorId\": \"849e6c6b420\",' + msg = msg + '\"payload\":'+payload+',\"requestId\":\"23343221\", \"target\":\"policy-agent\", \"timestamp\":\"'+str(time_stamp)+'\", \"type\":\"request\",\"url\":\"'+url+'\"}' + return msg + + +### MR-stub interface, for MR control + +# Send a message to MR +# URI and parameters (GET): /send-request?operation=&url= +# response: (http 200) o4 400 for parameter error or 500 for other errors +@app.route(APP_WRITE_URL, + methods=['PUT','POST']) +def sendrequest(): + global msg_requests + global cntr_msg_requests_submitted + with lock: + print("APP_WRITE_URL lock") + try: + oper=request.args.get('operation') + if (oper is None): + print(APP_WRITE_URL+" parameter 'operation' missing") + return Response('Parameter operation missing in request', status=400, mimetype=MIME_TEXT) + + url=request.args.get('url') + if (url is None): + print(APP_WRITE_URL+" parameter 'url' missing") + return Response('Parameter url missing in request', status=400, mimetype=MIME_TEXT) + + if (oper != "GET" and oper != "PUT" and oper != "POST" and oper != "DELETE"): + print(APP_WRITE_URL+" parameter 'operation' need to be: DEL|PUT|POST|DELETE") + return Response('Parameter operation does not contain DEL|PUT|POST|DELETE in request', status=400, mimetype=MIME_TEXT) + + print(APP_WRITE_URL+" operation="+oper+" url="+url) + correlation_id=str(time.time_ns()) + payload=None + if (oper == "PUT") and (request.json is not None): + payload=json.dumps(request.json) + + msg=create_message(oper, correlation_id, payload, url) + print(msg) + print(APP_WRITE_URL+" MSG(correlationid = "+correlation_id+"): " + json.dumps(json.loads(msg), indent=2)) + msg_requests.append(msg) + cntr_msg_requests_submitted += 1 + return Response(correlation_id, status=200, mimetype=MIME_TEXT) + except Exception as e: + print(APP_WRITE_URL+"-"+CAUGHT_EXCEPTION+" "+str(e) + " "+traceback.format_exc()) + return Response(SERVER_ERROR+" "+str(e), status=500, mimetype=MIME_TEXT) + +# Receive a message response for MR for the included correlation id +# URI and parameter, (GET): /receive-response?correlationid= +# response: 200 or empty 204 or other errors 500 +@app.route(APP_READ_URL, + methods=['GET']) +def receiveresponse(): + global msg_responses + global cntr_msg_responses_fetched + with lock: + print("APP_READ_URL lock") + try: + id=request.args.get('correlationid') + if (id is None): + print(APP_READ_URL+" parameter 'correclationid' missing") + return Response('Parameter correlationid missing in json', status=500, mimetype=MIME_TEXT) + + if (id in msg_responses): + answer=msg_responses[id] + del msg_responses[id] + print(APP_READ_URL+" response (correlationid="+id+"): " + answer) + cntr_msg_responses_fetched += 1 + return Response(answer, status=200, mimetype=MIME_JSON) + + print(APP_READ_URL+" - no messages (correlationid="+id+"): ") + return Response('', status=204, mimetype=MIME_JSON) + except Exception as e: + print(APP_READ_URL+"-"+CAUGHT_EXCEPTION+" "+str(e) + " "+traceback.format_exc()) + return Response(SERVER_ERROR+" "+str(e), status=500, mimetype=MIME_TEXT) + +### Dmaap interface ### + +# Read messages stream. URI according to agent configuration. +# URI, (GET): /events/A1-POLICY-AGENT-READ/users/policy-agent +# response: 200 , or 500 for other errors +@app.route(AGENT_READ_URL, + methods=['GET']) +def events_read(): + global msg_requests + global cntr_msg_requests_fetched + + limit=request.args.get('limit') + if (limit is None): + limit=4096 + else: + limit=int(limit) + if (limit<0): + limit=0 + if (limit>4096): + limit=4096 + print("Limting number of returned messages to: "+str(limit)) + + timeout=request.args.get('timeout') + if (timeout is None): + timeout=10000 + else: + timeout=min(int(timeout),60000) + + startTime=int(round(time.time() * 1000)) + currentTime=int(round(time.time() * 1000)) + + while(currentTime0): + try: + msgs='' + cntr=0 + while(cntr0): + if (len(msgs)>1): + msgs=msgs+',' + msgs=msgs+msg_requests.pop(0) + cntr_msg_requests_fetched += 1 + cntr=cntr+1 + msgs='['+msgs+']' + print(AGENT_READ_URL+" MSGs: "+json.dumps(json.loads(msgs), indent=2)) + return Response(msgs, status=200, mimetype=MIME_JSON) + except Exception as e: + print(AGENT_READ_URL+"-"+CAUGHT_EXCEPTION+" "+str(e) + " "+traceback.format_exc()) + return Response(SERVER_ERROR+" "+str(e), status=500, mimetype=MIME_TEXT) + sleep(0.025) # sleep 25 milliseconds + currentTime=int(round(time.time() * 1000)) + + print("timeout: "+str(timeout)+", startTime: "+str(startTime)+", currentTime: "+str(currentTime)) + return Response("[]", status=200, mimetype=MIME_JSON) + +# Write messages stream. URI according to agent configuration. +# URI and payload, (PUT or POST): /events/A1-POLICY-AGENT-WRITE +# response: OK 200 or 400 for missing json parameters, 500 for other errors +@app.route(AGENT_WRITE_URL, + methods=['PUT','POST']) +def events_write(): + global msg_responses + global cntr_msg_responses_submitted + with lock: + print("AGENT_WRITE_URL lock") + try: + answer=request.json + print(AGENT_WRITE_URL+ " json=" + json.dumps(answer, indent=2)) + for item in answer: + id=item['correlationId'] + if (id is None): + print(AGENT_WRITE_URL+" parameter 'correlatonid' missing") + return Response('Parameter missing in json', status=400, mimetype=MIME_TEXT) + msg=item['message'] + if (msg is None): + print(AGENT_WRITE_URL+" parameter 'msgs' missing") + return Response('Parameter >message> missing in json', status=400, mimetype=MIME_TEXT) + status=item['status'] + if (status is None): + print(AGENT_WRITE_URL+" parameter 'status' missing") + return Response('Parameter missing in json', status=400, mimetype=MIME_TEXT) + if isinstance(msg, list) or isinstance(msg, dict): + msg_str=json.dumps(msg)+status[0:3] + else: + msg_str=msg+status[0:3] + msg_responses[id]=msg_str + cntr_msg_responses_submitted += 1 + print(AGENT_WRITE_URL+ " msg+status (correlationid="+id+") :" + str(msg_str)) + except Exception as e: + print(AGENT_WRITE_URL+"-"+CAUGHT_EXCEPTION+" "+str(e) + " "+traceback.format_exc()) + return Response('{"message": "' + SERVER_ERROR + ' ' + str(e) + '","status":"500"}', status=200, mimetype=MIME_JSON) + + return Response('{}', status=200, mimetype=MIME_JSON) + + +### Functions for metrics read out ### + +@app.route('/counter/requests_submitted', + methods=['GET']) +def requests_submitted(): + return Response(str(cntr_msg_requests_submitted), status=200, mimetype=MIME_TEXT) + +@app.route('/counter/requests_fetched', + methods=['GET']) +def requests_fetched(): + return Response(str(cntr_msg_requests_fetched), status=200, mimetype=MIME_TEXT) + +@app.route('/counter/responses_submitted', + methods=['GET']) +def responses_submitted(): + return Response(str(cntr_msg_responses_submitted), status=200, mimetype=MIME_TEXT) + +@app.route('/counter/responses_fetched', + methods=['GET']) +def responses_fetched(): + return Response(str(cntr_msg_responses_fetched), status=200, mimetype=MIME_TEXT) + +@app.route('/counter/current_requests', + methods=['GET']) +def current_requests(): + return Response(str(len(msg_requests)), status=200, mimetype=MIME_TEXT) + +@app.route('/counter/current_responses', + methods=['GET']) +def current_responses(): + return Response(str(len(msg_responses)), status=200, mimetype=MIME_TEXT) + +### Admin ### + +# Reset all messsages and counters +@app.route('/reset', + methods=['GET', 'POST', 'PUT']) +def reset(): + global cntr_msg_requests_submitted + global cntr_msg_requests_fetched + global cntr_msg_responses_submitted + global cntr_msg_responses_fetched + global msg_requests + global msg_responses + + cntr_msg_requests_submitted=0 + cntr_msg_requests_fetched=0 + cntr_msg_responses_submitted=0 + cntr_msg_responses_fetched=0 + msg_requests=[] + msg_responses={} + return Response('OK', status=200, mimetype=MIME_TEXT) + +if __name__ == "__main__": + app.run(port=HOST_PORT, host=HOST_IP) \ No newline at end of file diff --git a/test/mrstub/app/nginx.conf b/test/mrstub/app/nginx.conf new file mode 100644 index 00000000..60b1dd9f --- /dev/null +++ b/test/mrstub/app/nginx.conf @@ -0,0 +1,100 @@ +user www-data; +worker_processes auto; +pid /run/nginx.pid; +include /etc/nginx/modules-enabled/*.conf; + +events { + worker_connections 768; + # multi_accept on; +} + +http { + + ## + # Basic Settings + ## + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + # server_tokens off; + + # server_names_hash_bucket_size 64; + # server_name_in_redirect off; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + server { # simple reverse-proxy + listen 3905; + listen [::]:3905; + listen 3906 ssl; + listen [::]:3906 ssl; + server_name localhost; + ssl_certificate /usr/src/app/cert/cert.crt; + ssl_certificate_key /usr/src/app/cert/key.crt; + ssl_password_file /usr/src/app/cert/pass; + + # serve dynamic requests + location / { + proxy_pass http://localhost:2222; + } + } + ## + # SSL Settings + ## + + ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE + ssl_prefer_server_ciphers on; + + ## + # Logging Settings + ## + + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + + ## + # Gzip Settings + ## + + gzip on; + + # gzip_vary on; + # gzip_proxied any; + # gzip_comp_level 6; + # gzip_buffers 16 8k; + # gzip_http_version 1.1; + # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; + + ## + # Virtual Host Configs + ## + + include /etc/nginx/conf.d/*.conf; + include /etc/nginx/sites-enabled/*; +} + + +#mail { +# # See sample authentication script at: +# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript +# +# # auth_http localhost/auth.php; +# # pop3_capabilities "TOP" "USER"; +# # imap_capabilities "IMAP4rev1" "UIDPLUS"; +# +# server { +# listen localhost:110; +# protocol pop3; +# proxy on; +# } +# +# server { +# listen localhost:143; +# protocol imap; +# proxy on; +# } +#} \ No newline at end of file diff --git a/test/mrstub/app/requirements.txt b/test/mrstub/app/requirements.txt new file mode 100644 index 00000000..8fd414f5 --- /dev/null +++ b/test/mrstub/app/requirements.txt @@ -0,0 +1,2 @@ +pip==20.1 +Flask==1.1.2 \ No newline at end of file diff --git a/test/mrstub/start.sh b/test/mrstub/app/start.sh similarity index 91% rename from test/mrstub/start.sh rename to test/mrstub/app/start.sh index 3342bb83..2f33b1a6 100644 --- a/test/mrstub/start.sh +++ b/test/mrstub/app/start.sh @@ -1,5 +1,4 @@ #!/bin/bash - # ============LICENSE_START=============================================== # Copyright (C) 2020 Nordix Foundation. All rights reserved. # ======================================================================== @@ -17,5 +16,8 @@ # ============LICENSE_END================================================= # -nodejs frontend.js & -python3 -u ./mr.py \ No newline at end of file +#start nginx +nginx -c /usr/src/app/nginx.conf + +#start mrstub +python3 -u main.py \ No newline at end of file diff --git a/test/mrstub/basic_test.sh b/test/mrstub/basic_test.sh index 577894d8..e9ca1d25 100755 --- a/test/mrstub/basic_test.sh +++ b/test/mrstub/basic_test.sh @@ -74,7 +74,7 @@ do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent' 200 echo "=== Send a json response ===" # Create minimal accepted response message echo "[{\"correlationId\": \""$CORRID"\", \"message\": {\"test\":\"testresponse\"}, \"status\": \"200\"}]" > .tmp.json -RESULT="OK" +RESULT="{}" do_curl POST /events/A1-POLICY-AGENT-WRITE 200 .tmp.json echo "=== Fetch a response ===" @@ -115,7 +115,7 @@ RESULT="json:[]" do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=5000' 200 T2=$SECONDS if [ $(($T2-$T1)) -lt 5 ] || [ $(($T2-$T1)) -gt 7 ]; then - echo "Delay to short or too long"$(($T2-$T1))". Should be 10 sec" + echo "Delay too short or too long"$(($T2-$T1))". Should be 10 sec" exit 1 else echo " Delay ok:"$(($T2-$T1)) @@ -147,7 +147,7 @@ do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=1000&limit= echo "=== Send a json response ===" # Create minimal accepted response message echo "[{\"correlationId\": \""$CORRID"\", \"message\": \"test2-response\", \"status\": \"200\"}]" > .tmp.json -RESULT="OK" +RESULT="{}" do_curl POST /events/A1-POLICY-AGENT-WRITE 200 .tmp.json echo "=== Fetch a response ===" @@ -156,4 +156,4 @@ do_curl GET '/receive-response?correlationid='$CORRID 200 echo "********************" echo "*** All tests ok ***" -echo "********************" +echo "********************" \ No newline at end of file diff --git a/test/mrstub/nginx_wsgi_flask/cert/pass b/test/mrstub/cert/pass similarity index 100% rename from test/mrstub/nginx_wsgi_flask/cert/pass rename to test/mrstub/cert/pass diff --git a/test/mrstub/frontend.js b/test/mrstub/frontend.js deleted file mode 100644 index 7b08f752..00000000 --- a/test/mrstub/frontend.js +++ /dev/null @@ -1,117 +0,0 @@ -// ============LICENSE_START=============================================== -// Copyright (C) 2020 Nordix Foundation. All rights reserved. -// ======================================================================== -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// ============LICENSE_END================================================= -// - -//This script acts like a proxy. All operations, except MR GET messages, are re-sent to the python backend server. -//The MR GET is intercepted and the python backend is polled until a message is available or up to a -//maximum time decided by a query parameter. No query parameter will result in a 10s long poll. - - -const proxy = require('express-http-proxy'); -const app = require('express')(); -const http = require('http'); -const https = require('https'); -const fs = require('fs'); -var privateKey; -var certificate; -var credentials; - -try { - privateKey = fs.readFileSync('cert/key.crt', 'utf8'); - certificate = fs.readFileSync('cert/cert.crt', 'utf8'); - credentials = {key: privateKey, - cert: certificate, - passphrase: 'test'}; -} catch(exp) { - console.log("Could not load cert and key") -} - -const httpPort=3905; -const httpsPort=3906; -const proxyport=2222 - -const sleep = (milliseconds) => { - return new Promise(resolve => setTimeout(resolve, milliseconds)) -} - -app.get("*/events/A1-POLICY-AGENT-READ/users/policy-agent*", inititate_long_poll); - -function inititate_long_poll(req,res) { - var millis=10000 //MR default is 10sec - var tmp=req.query.timeout - if (tmp != undefined) { - millis=parseInt(tmp); - millis=(millis < 0 ? 10000 : Math.min(millis, 60000)) //Max poll is 60 sec - console.log("Setting poll time to (ms): " + millis) - } - do_poll(req, res, req.url, Date.now()+millis) -} - -function do_poll(req,res, url, millis) { - const options = { - hostname: 'localhost', - port: proxyport, - path: url, - method: 'GET' - } - http.get(options, function(resp) { - let data = ''; - // Receiving chunk by chunk - resp.on('data', (chunk) => { - data += chunk; - }); - - // Full response received - resp.on('end', () => { - var payload=data.trim(); - if (resp.statusCode == 200 && payload.length == 2 && payload=="[]" && Date.now() { - do_poll(req,res, this.url, this.millis) - }) - } else { - //Eventually return the response - res.statusCode=resp.statusCode - res.header(resp.headers); - res.send(data) - return; - } - }); - }.bind({millis:millis, url:url})).on("error", (err) => { - console.log("Error when reading from backend: " + err.message); - res.statusCode=500 - res.send("ERROR detected in frontend: "+ err.message) - return - }); -} - -//Catch all, resend from proxy -app.use(proxy('localhost:'+proxyport, { - limit: '5mb', -})); - -//Start serving http -var httpServer = http.createServer(app); -var httpsServer; -console.log("Running on http: "+httpPort) -httpServer.listen(httpPort, "::"); - -//Start serving https if cert is available -if (credentials != undefined) { - httpsServer = https.createServer(credentials, app); - console.log("Running on https: "+httpsPort) - httpsServer.listen(httpsPort, "::"); -} diff --git a/test/mrstub/mr.py b/test/mrstub/mr.py deleted file mode 100644 index 9c5a2c8d..00000000 --- a/test/mrstub/mr.py +++ /dev/null @@ -1,276 +0,0 @@ - -# ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. -# ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END================================================= -# - -from flask import Flask, request -from time import sleep -import time -import datetime -import json -from flask import Flask -from flask import Response -import traceback - -app = Flask(__name__) - -# list of messages to/from Dmaap -msg_requests=[] -msg_responses={} - -# Server info -HOST_IP = "127.0.0.1" -HOST_PORT = 2222 - -# Metrics vars -cntr_msg_requests_submitted=0 -cntr_msg_requests_fetched=0 -cntr_msg_responses_submitted=0 -cntr_msg_responses_fetched=0 - -# Request and response constants -AGENT_WRITE_URL="/events/A1-POLICY-AGENT-WRITE" -AGENT_READ_URL="/events/A1-POLICY-AGENT-READ/users/policy-agent" -APP_WRITE_URL="/send-request" -APP_READ_URL="/receive-response" -MIME_TEXT="text/plain" -MIME_JSON="application/json" -CAUGHT_EXCEPTION="Caught exception: " -SERVER_ERROR="Server error :" - -#I'm alive function -@app.route('/', - methods=['GET']) -def index(): - return 'OK', 200 - - -# Helper function to create a Dmaap request message -# args : -# response: json formatted string of a complete Dmaap message -def create_message(operation, correlation_id, payload, url): - if (payload is None): - payload="{}" - time_stamp=datetime.datetime.utcnow() - msg = '{\"apiVersion\":\"1.0\",\"operation\":\"'+operation+'\",\"correlationId\":\"'+correlation_id+'\",\"originatorId\": \"849e6c6b420\",' - msg = msg + '\"payload\":'+payload+',\"requestId\":\"23343221\", \"target\":\"policy-agent\", \"timestamp\":\"'+str(time_stamp)+'\", \"type\":\"request\",\"url\":\"'+url+'\"}' - return msg - - -### MR-stub interface, for MR control - -# Send a message to MR -# URI and parameters (GET): /send-request?operation=&url= -# response: (http 200) o4 400 for parameter error or 500 for other errors -@app.route(APP_WRITE_URL, - methods=['PUT','POST']) -def sendrequest(): - global msg_requests - global cntr_msg_requests_submitted - - try: - - oper=request.args.get('operation') - if (oper is None): - print(APP_WRITE_URL+" parameter 'operation' missing") - return Response('Parameter operation missing in request', status=400, mimetype=MIME_TEXT) - - url=request.args.get('url') - if (url is None): - print(APP_WRITE_URL+" parameter 'url' missing") - return Response('Parameter url missing in request', status=400, mimetype=MIME_TEXT) - - if (oper != "GET" and oper != "PUT" and oper != "POST" and oper != "DELETE"): - print(APP_WRITE_URL+" parameter 'operation' need to be: DEL|PUT|POST|DELETE") - return Response('Parameter operation does not contain DEL|PUT|POST|DELETE in request', status=400, mimetype=MIME_TEXT) - - print(APP_WRITE_URL+" operation="+oper+" url="+url) - correlation_id=str(time.time_ns()) - payload=None - if (oper == "PUT") and (request.json is not None): - payload=json.dumps(request.json) - - msg=create_message(oper, correlation_id, payload, url) - print(msg) - print(APP_WRITE_URL+" MSG(correlationid = "+correlation_id+"): " + json.dumps(json.loads(msg), indent=2)) - msg_requests.append(msg) - cntr_msg_requests_submitted += 1 - return Response(correlation_id, status=200, mimetype=MIME_TEXT) - except Exception as e: - print(APP_WRITE_URL+"-"+CAUGHT_EXCEPTION+" "+str(e) + " "+traceback.format_exc()) - return Response(SERVER_ERROR+" "+str(e), status=500, mimetype=MIME_TEXT) - -# Receive a message response for MR for the included correlation id -# URI and parameter, (GET): /receive-response?correlationid= -# response: 200 or empty 204 or other errors 500 -@app.route(APP_READ_URL, - methods=['GET']) -def receiveresponse(): - global msg_responses - global cntr_msg_responses_fetched - - try: - id=request.args.get('correlationid') - if (id is None): - print(APP_READ_URL+" parameter 'correclationid' missing") - return Response('Parameter correlationid missing in json', status=500, mimetype=MIME_TEXT) - - if (id in msg_responses): - answer=msg_responses[id] - del msg_responses[id] - print(APP_READ_URL+" response (correlationid="+id+"): " + answer) - cntr_msg_responses_fetched += 1 - return Response(answer, status=200, mimetype=MIME_JSON) - - print(APP_READ_URL+" - no messages (correlationid="+id+"): ") - return Response('', status=204, mimetype=MIME_JSON) - except Exception as e: - print(APP_READ_URL+"-"+CAUGHT_EXCEPTION+" "+str(e) + " "+traceback.format_exc()) - return Response(SERVER_ERROR+" "+str(e), status=500, mimetype=MIME_TEXT) - -### Dmaap interface ### - -# Read messages stream. URI according to agent configuration. -# URI, (GET): /events/A1-POLICY-AGENT-READ/users/policy-agent -# response: 200 , or 500 for other errors -@app.route(AGENT_READ_URL, - methods=['GET']) -def events_read(): - global msg_requests - global cntr_msg_requests_fetched - - limit=request.args.get('limit') - if (limit is None): - limit=4096 - else: - limit=int(limit) - if (limit<0): - limit=0 - if (limit>4096): - limit=4096 - print("Limting number of returned messages to: "+str(limit)) - try: - msgs='' - cntr=0 - while(cntr0): - if (len(msgs)>1): - msgs=msgs+',' - msgs=msgs+msg_requests.pop(0) - cntr_msg_requests_fetched += 1 - cntr=cntr+1 - msgs='['+msgs+']' - print(AGENT_READ_URL+" MSGs: "+json.dumps(json.loads(msgs), indent=2)) - return Response(msgs, status=200, mimetype=MIME_JSON) - except Exception as e: - print(AGENT_READ_URL+"-"+CAUGHT_EXCEPTION+" "+str(e) + " "+traceback.format_exc()) - return Response(SERVER_ERROR+" "+str(e), status=500, mimetype=MIME_TEXT) - -# Write messages stream. URI according to agent configuration. -# URI and payload, (PUT or POST): /events/A1-POLICY-AGENT-WRITE -# response: OK 200 or 400 for missing json parameters, 500 for other errors -@app.route(AGENT_WRITE_URL, - methods=['PUT','POST']) -def events_write(): - global msg_responses - global cntr_msg_responses_submitted - - try: - answer=request.json - print(AGENT_WRITE_URL+ " json=" + json.dumps(answer, indent=2)) - for item in answer: - id=item['correlationId'] - if (id is None): - print(AGENT_WRITE_URL+" parameter 'correlatonid' missing") - return Response('Parameter missing in json', status=400, mimetype=MIME_TEXT) - msg=item['message'] - if (msg is None): - print(AGENT_WRITE_URL+" parameter 'msgs' missing") - return Response('Parameter >message> missing in json', status=400, mimetype=MIME_TEXT) - status=item['status'] - if (status is None): - print(AGENT_WRITE_URL+" parameter 'status' missing") - return Response('Parameter missing in json', status=400, mimetype=MIME_TEXT) - if isinstance(msg, list) or isinstance(msg, dict): - msg_str=json.dumps(msg)+status[0:3] - else: - msg_str=msg+status[0:3] - msg_responses[id]=msg_str - cntr_msg_responses_submitted += 1 - print(AGENT_WRITE_URL+ " msg+status (correlationid="+id+") :" + str(msg_str)) - except Exception as e: - print(AGENT_WRITE_URL+"-"+CAUGHT_EXCEPTION+" "+str(e) + " "+traceback.format_exc()) - return Response('{"message": "' + SERVER_ERROR + ' ' + str(e) + '","status":"500"}', status=200, mimetype=MIME_JSON) - - return Response('{}', status=200, mimetype=MIME_JSON) - - -### Functions for metrics read out ### - -@app.route('/counter/requests_submitted', - methods=['GET']) -def requests_submitted(): - return Response(str(cntr_msg_requests_submitted), status=200, mimetype=MIME_TEXT) - -@app.route('/counter/requests_fetched', - methods=['GET']) -def requests_fetched(): - return Response(str(cntr_msg_requests_fetched), status=200, mimetype=MIME_TEXT) - -@app.route('/counter/responses_submitted', - methods=['GET']) -def responses_submitted(): - return Response(str(cntr_msg_responses_submitted), status=200, mimetype=MIME_TEXT) - -@app.route('/counter/responses_fetched', - methods=['GET']) -def responses_fetched(): - return Response(str(cntr_msg_responses_fetched), status=200, mimetype=MIME_TEXT) - -@app.route('/counter/current_requests', - methods=['GET']) -def current_requests(): - return Response(str(len(msg_requests)), status=200, mimetype=MIME_TEXT) - -@app.route('/counter/current_responses', - methods=['GET']) -def current_responses(): - return Response(str(len(msg_responses)), status=200, mimetype=MIME_TEXT) - -### Admin ### - -# Reset all messsages and counters -@app.route('/reset', - methods=['GET', 'POST', 'PUT']) -def reset(): - global cntr_msg_requests_submitted - global cntr_msg_requests_fetched - global cntr_msg_responses_submitted - global cntr_msg_responses_fetched - global msg_requests - global msg_responses - - cntr_msg_requests_submitted=0 - cntr_msg_requests_fetched=0 - cntr_msg_responses_submitted=0 - cntr_msg_responses_fetched=0 - msg_requests=[] - msg_responses={} - return Response('OK', status=200, mimetype=MIME_TEXT) - -### Main function ### - -if __name__ == "__main__": - app.run(port=HOST_PORT, host=HOST_IP) diff --git a/test/mrstub/nginx_wsgi_flask/Dockerfile b/test/mrstub/nginx_wsgi_flask/Dockerfile deleted file mode 100644 index d6e84645..00000000 --- a/test/mrstub/nginx_wsgi_flask/Dockerfile +++ /dev/null @@ -1,25 +0,0 @@ -# ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. -# ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END================================================= -# - -FROM tiangolo/uwsgi-nginx-flask:python3.7 - -COPY ./cert/cert.crt /etc/ssl/private/ -COPY ./cert/key.crt /etc/ssl/private/ -COPY ./cert/pass /etc/ssl/private/ - -COPY ./app /app - diff --git a/test/mrstub/nginx_wsgi_flask/app/main.py b/test/mrstub/nginx_wsgi_flask/app/main.py deleted file mode 100644 index 9c5a2c8d..00000000 --- a/test/mrstub/nginx_wsgi_flask/app/main.py +++ /dev/null @@ -1,276 +0,0 @@ - -# ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. -# ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END================================================= -# - -from flask import Flask, request -from time import sleep -import time -import datetime -import json -from flask import Flask -from flask import Response -import traceback - -app = Flask(__name__) - -# list of messages to/from Dmaap -msg_requests=[] -msg_responses={} - -# Server info -HOST_IP = "127.0.0.1" -HOST_PORT = 2222 - -# Metrics vars -cntr_msg_requests_submitted=0 -cntr_msg_requests_fetched=0 -cntr_msg_responses_submitted=0 -cntr_msg_responses_fetched=0 - -# Request and response constants -AGENT_WRITE_URL="/events/A1-POLICY-AGENT-WRITE" -AGENT_READ_URL="/events/A1-POLICY-AGENT-READ/users/policy-agent" -APP_WRITE_URL="/send-request" -APP_READ_URL="/receive-response" -MIME_TEXT="text/plain" -MIME_JSON="application/json" -CAUGHT_EXCEPTION="Caught exception: " -SERVER_ERROR="Server error :" - -#I'm alive function -@app.route('/', - methods=['GET']) -def index(): - return 'OK', 200 - - -# Helper function to create a Dmaap request message -# args : -# response: json formatted string of a complete Dmaap message -def create_message(operation, correlation_id, payload, url): - if (payload is None): - payload="{}" - time_stamp=datetime.datetime.utcnow() - msg = '{\"apiVersion\":\"1.0\",\"operation\":\"'+operation+'\",\"correlationId\":\"'+correlation_id+'\",\"originatorId\": \"849e6c6b420\",' - msg = msg + '\"payload\":'+payload+',\"requestId\":\"23343221\", \"target\":\"policy-agent\", \"timestamp\":\"'+str(time_stamp)+'\", \"type\":\"request\",\"url\":\"'+url+'\"}' - return msg - - -### MR-stub interface, for MR control - -# Send a message to MR -# URI and parameters (GET): /send-request?operation=&url= -# response: (http 200) o4 400 for parameter error or 500 for other errors -@app.route(APP_WRITE_URL, - methods=['PUT','POST']) -def sendrequest(): - global msg_requests - global cntr_msg_requests_submitted - - try: - - oper=request.args.get('operation') - if (oper is None): - print(APP_WRITE_URL+" parameter 'operation' missing") - return Response('Parameter operation missing in request', status=400, mimetype=MIME_TEXT) - - url=request.args.get('url') - if (url is None): - print(APP_WRITE_URL+" parameter 'url' missing") - return Response('Parameter url missing in request', status=400, mimetype=MIME_TEXT) - - if (oper != "GET" and oper != "PUT" and oper != "POST" and oper != "DELETE"): - print(APP_WRITE_URL+" parameter 'operation' need to be: DEL|PUT|POST|DELETE") - return Response('Parameter operation does not contain DEL|PUT|POST|DELETE in request', status=400, mimetype=MIME_TEXT) - - print(APP_WRITE_URL+" operation="+oper+" url="+url) - correlation_id=str(time.time_ns()) - payload=None - if (oper == "PUT") and (request.json is not None): - payload=json.dumps(request.json) - - msg=create_message(oper, correlation_id, payload, url) - print(msg) - print(APP_WRITE_URL+" MSG(correlationid = "+correlation_id+"): " + json.dumps(json.loads(msg), indent=2)) - msg_requests.append(msg) - cntr_msg_requests_submitted += 1 - return Response(correlation_id, status=200, mimetype=MIME_TEXT) - except Exception as e: - print(APP_WRITE_URL+"-"+CAUGHT_EXCEPTION+" "+str(e) + " "+traceback.format_exc()) - return Response(SERVER_ERROR+" "+str(e), status=500, mimetype=MIME_TEXT) - -# Receive a message response for MR for the included correlation id -# URI and parameter, (GET): /receive-response?correlationid= -# response: 200 or empty 204 or other errors 500 -@app.route(APP_READ_URL, - methods=['GET']) -def receiveresponse(): - global msg_responses - global cntr_msg_responses_fetched - - try: - id=request.args.get('correlationid') - if (id is None): - print(APP_READ_URL+" parameter 'correclationid' missing") - return Response('Parameter correlationid missing in json', status=500, mimetype=MIME_TEXT) - - if (id in msg_responses): - answer=msg_responses[id] - del msg_responses[id] - print(APP_READ_URL+" response (correlationid="+id+"): " + answer) - cntr_msg_responses_fetched += 1 - return Response(answer, status=200, mimetype=MIME_JSON) - - print(APP_READ_URL+" - no messages (correlationid="+id+"): ") - return Response('', status=204, mimetype=MIME_JSON) - except Exception as e: - print(APP_READ_URL+"-"+CAUGHT_EXCEPTION+" "+str(e) + " "+traceback.format_exc()) - return Response(SERVER_ERROR+" "+str(e), status=500, mimetype=MIME_TEXT) - -### Dmaap interface ### - -# Read messages stream. URI according to agent configuration. -# URI, (GET): /events/A1-POLICY-AGENT-READ/users/policy-agent -# response: 200 , or 500 for other errors -@app.route(AGENT_READ_URL, - methods=['GET']) -def events_read(): - global msg_requests - global cntr_msg_requests_fetched - - limit=request.args.get('limit') - if (limit is None): - limit=4096 - else: - limit=int(limit) - if (limit<0): - limit=0 - if (limit>4096): - limit=4096 - print("Limting number of returned messages to: "+str(limit)) - try: - msgs='' - cntr=0 - while(cntr0): - if (len(msgs)>1): - msgs=msgs+',' - msgs=msgs+msg_requests.pop(0) - cntr_msg_requests_fetched += 1 - cntr=cntr+1 - msgs='['+msgs+']' - print(AGENT_READ_URL+" MSGs: "+json.dumps(json.loads(msgs), indent=2)) - return Response(msgs, status=200, mimetype=MIME_JSON) - except Exception as e: - print(AGENT_READ_URL+"-"+CAUGHT_EXCEPTION+" "+str(e) + " "+traceback.format_exc()) - return Response(SERVER_ERROR+" "+str(e), status=500, mimetype=MIME_TEXT) - -# Write messages stream. URI according to agent configuration. -# URI and payload, (PUT or POST): /events/A1-POLICY-AGENT-WRITE -# response: OK 200 or 400 for missing json parameters, 500 for other errors -@app.route(AGENT_WRITE_URL, - methods=['PUT','POST']) -def events_write(): - global msg_responses - global cntr_msg_responses_submitted - - try: - answer=request.json - print(AGENT_WRITE_URL+ " json=" + json.dumps(answer, indent=2)) - for item in answer: - id=item['correlationId'] - if (id is None): - print(AGENT_WRITE_URL+" parameter 'correlatonid' missing") - return Response('Parameter missing in json', status=400, mimetype=MIME_TEXT) - msg=item['message'] - if (msg is None): - print(AGENT_WRITE_URL+" parameter 'msgs' missing") - return Response('Parameter >message> missing in json', status=400, mimetype=MIME_TEXT) - status=item['status'] - if (status is None): - print(AGENT_WRITE_URL+" parameter 'status' missing") - return Response('Parameter missing in json', status=400, mimetype=MIME_TEXT) - if isinstance(msg, list) or isinstance(msg, dict): - msg_str=json.dumps(msg)+status[0:3] - else: - msg_str=msg+status[0:3] - msg_responses[id]=msg_str - cntr_msg_responses_submitted += 1 - print(AGENT_WRITE_URL+ " msg+status (correlationid="+id+") :" + str(msg_str)) - except Exception as e: - print(AGENT_WRITE_URL+"-"+CAUGHT_EXCEPTION+" "+str(e) + " "+traceback.format_exc()) - return Response('{"message": "' + SERVER_ERROR + ' ' + str(e) + '","status":"500"}', status=200, mimetype=MIME_JSON) - - return Response('{}', status=200, mimetype=MIME_JSON) - - -### Functions for metrics read out ### - -@app.route('/counter/requests_submitted', - methods=['GET']) -def requests_submitted(): - return Response(str(cntr_msg_requests_submitted), status=200, mimetype=MIME_TEXT) - -@app.route('/counter/requests_fetched', - methods=['GET']) -def requests_fetched(): - return Response(str(cntr_msg_requests_fetched), status=200, mimetype=MIME_TEXT) - -@app.route('/counter/responses_submitted', - methods=['GET']) -def responses_submitted(): - return Response(str(cntr_msg_responses_submitted), status=200, mimetype=MIME_TEXT) - -@app.route('/counter/responses_fetched', - methods=['GET']) -def responses_fetched(): - return Response(str(cntr_msg_responses_fetched), status=200, mimetype=MIME_TEXT) - -@app.route('/counter/current_requests', - methods=['GET']) -def current_requests(): - return Response(str(len(msg_requests)), status=200, mimetype=MIME_TEXT) - -@app.route('/counter/current_responses', - methods=['GET']) -def current_responses(): - return Response(str(len(msg_responses)), status=200, mimetype=MIME_TEXT) - -### Admin ### - -# Reset all messsages and counters -@app.route('/reset', - methods=['GET', 'POST', 'PUT']) -def reset(): - global cntr_msg_requests_submitted - global cntr_msg_requests_fetched - global cntr_msg_responses_submitted - global cntr_msg_responses_fetched - global msg_requests - global msg_responses - - cntr_msg_requests_submitted=0 - cntr_msg_requests_fetched=0 - cntr_msg_responses_submitted=0 - cntr_msg_responses_fetched=0 - msg_requests=[] - msg_responses={} - return Response('OK', status=200, mimetype=MIME_TEXT) - -### Main function ### - -if __name__ == "__main__": - app.run(port=HOST_PORT, host=HOST_IP) diff --git a/test/mrstub/nginx_wsgi_flask/app/nginx.conf b/test/mrstub/nginx_wsgi_flask/app/nginx.conf deleted file mode 100644 index 387303c6..00000000 --- a/test/mrstub/nginx_wsgi_flask/app/nginx.conf +++ /dev/null @@ -1,58 +0,0 @@ -# ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. -# ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END================================================= -# - -user nginx; -worker_processes 1; -error_log /var/log/nginx/error.log warn; -pid /var/run/nginx.pid; -events { - worker_connections 1024; -} -http { - ssl_password_file /etc/ssl/private/pass; - include /etc/nginx/mime.types; - default_type application/octet-stream; - log_format main '$remote_addr - $remote_user [$time_local] "$request" ' - '$status $body_bytes_sent "$http_referer" ' - '"$http_user_agent" "$http_x_forwarded_for"'; - access_log /var/log/nginx/access.log main; - sendfile on; - keepalive_timeout 65; - include /etc/nginx/conf.d/*.conf; - - server { - listen 80 ; - listen [::]:80; - listen 443 ssl ; - listen [::]:443 ssl; - server_name localhost; - ssl_certificate /etc/ssl/private/cert.crt; - ssl_certificate_key /etc/ssl/private/key.crt; - - location / { - try_files $uri @app; - } - location @app { - include uwsgi_params; - uwsgi_pass unix:///tmp/uwsgi.sock; - } - location /static { - alias /app/static; - } - } -} -daemon off; diff --git a/test/mrstub/nginx_wsgi_flask/app/prestart.sh b/test/mrstub/nginx_wsgi_flask/app/prestart.sh deleted file mode 100644 index d4f4576a..00000000 --- a/test/mrstub/nginx_wsgi_flask/app/prestart.sh +++ /dev/null @@ -1,22 +0,0 @@ -#! /usr/bin/env bash - -# ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. -# ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END================================================= -# - -echo "start nginx, uwsgi, flask application..." - - diff --git a/test/mrstub/nginx_wsgi_flask/app/uwsgi.ini b/test/mrstub/nginx_wsgi_flask/app/uwsgi.ini deleted file mode 100644 index 4bd92fc4..00000000 --- a/test/mrstub/nginx_wsgi_flask/app/uwsgi.ini +++ /dev/null @@ -1,21 +0,0 @@ -# ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. -# ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END================================================= -# - -[uwsgi] -module = main -callable = app -cheaper = 1 \ No newline at end of file diff --git a/test/mrstub/nginx_wsgi_flask/basic_test.sh b/test/mrstub/nginx_wsgi_flask/basic_test.sh deleted file mode 100755 index 2a11e506..00000000 --- a/test/mrstub/nginx_wsgi_flask/basic_test.sh +++ /dev/null @@ -1,135 +0,0 @@ -#!/bin/bash - -# ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. -# ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END================================================= -# - -# Automated test script for mrstub container - -# Run the build_and_start with the same arg as this script -if [ $# -ne 1 ]; then - echo "Usage: ./basic_test nonsecure|secure" - exit 1 -fi -if [ "$1" != "nonsecure" ] && [ "$1" != "secure" ]; then - echo "Usage: ./basic_test nonsecure|secure" - exit 1 -fi - -if [ $1 == "nonsecure" ]; then - #Default http port for the simulator - PORT=3905 - # Set http protocol - HTTPX="http" -else - #Default https port for the mr-stub - PORT=3906 - # Set https protocol - HTTPX="https" -fi - -# source function to do curl and check result -. ../../common/do_curl_function.sh - -echo "=== Stub hello world ===" -RESULT="OK" -do_curl GET / 200 - -echo "=== Stub reset ===" -RESULT="OK" -do_curl GET /reset 200 - -## Test with json response - -echo "=== Send a request ===" -RESULT="*" -#create payload -echo "{\"data\": \"data-value\"}" > .tmp.json - -do_curl POST '/send-request?operation=PUT&url=/test' 200 .tmp.json -#Save id for later -CORRID=$body - -echo "=== Fetch a response, shall be empty ===" -RESULT="" -do_curl GET '/receive-response?correlationid='$CORRID 204 - -echo "=== Fetch a request ===" -RESULT="json:[{\"apiVersion\":\"1.0\",\"operation\":\"PUT\",\"correlationId\":\""$CORRID"\",\"originatorId\": \"849e6c6b420\",\"payload\":{\"data\": \"data-value\"},\"requestId\":\"23343221\", \"target\":\"policy-agent\", \"timestamp\":\"????\", \"type\":\"request\",\"url\":\"/test\"}]" -do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent' 200 - -echo "=== Send a json response ===" -# Create minimal accepted response message -echo "[{\"correlationId\": \""$CORRID"\", \"message\": {\"test\":\"testresponse\"}, \"status\": \"200\"}]" > .tmp.json -RESULT="OK" -do_curl POST /events/A1-POLICY-AGENT-WRITE 200 .tmp.json - -echo "=== Fetch a response ===" -RESULT="{\"test\": \"testresponse\"}200" -do_curl GET '/receive-response?correlationid='$CORRID 200 - -### Test with plain text response - -echo "=== Send a request ===" -RESULT="*" -do_curl POST '/send-request?operation=GET&url=/test2' 200 -#Save id for later -CORRID=$body - -echo "=== Fetch a response, shall be empty ===" -RESULT="" -do_curl GET '/receive-response?correlationid='$CORRID 204 - -echo "=== Fetch a request ===" -RESULT="json:[{\"apiVersion\":\"1.0\",\"operation\":\"GET\",\"correlationId\":\""$CORRID"\",\"originatorId\": \"849e6c6b420\",\"payload\":{},\"requestId\":\"23343221\", \"target\":\"policy-agent\", \"timestamp\":\"????\", \"type\":\"request\",\"url\":\"/test2\"}]" -do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent' 200 - -echo "=== Fetch a request with limit 25, shall be empty. ===" -RESULT="json-array-size:0" -do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=1000&limit=25' 200 - -echo "=== Send 5 request to test limit on MR GET===" -RESULT="*" -for i in {1..5} -do - do_curl POST '/send-request?operation=GET&url=/test2' 200 -done - -echo "=== Fetch a request with limit 3. ===" -RESULT="json-array-size:3" -do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=1000&limit=3' 200 - -echo "=== Fetch a request with limit 3, shall return 2. ===" -RESULT="json-array-size:2" -do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=1000&limit=3' 200 - -echo "=== Fetch a request with limit 3, shall return 0. ===" -RESULT="json-array-size:0" -do_curl GET '/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=1000&limit=3' 200 - -echo "=== Send a json response ===" -# Create minimal accepted response message -echo "[{\"correlationId\": \""$CORRID"\", \"message\": \"test2-response\", \"status\": \"200\"}]" > .tmp.json -RESULT="OK" -do_curl POST /events/A1-POLICY-AGENT-WRITE 200 .tmp.json - -echo "=== Fetch a response ===" -RESULT="test2-response200" -do_curl GET '/receive-response?correlationid='$CORRID 200 - -echo "********************" -echo "*** All tests ok ***" -echo "********************" diff --git a/test/mrstub/nginx_wsgi_flask/cert/cert.crt b/test/mrstub/nginx_wsgi_flask/cert/cert.crt deleted file mode 100644 index a24dfc49..00000000 --- a/test/mrstub/nginx_wsgi_flask/cert/cert.crt +++ /dev/null @@ -1,16 +0,0 @@ ------BEGIN CERTIFICATE----- -MIICljCCAX4CCQCv7SV/aTc/YjANBgkqhkiG9w0BAQsFADANMQswCQYDVQQGEwJT -RTAeFw0yMDA1MDMwMDI0MzdaFw00NzA5MTgwMDI0MzdaMA0xCzAJBgNVBAYTAlNF -MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApsGQcCv+Ce/+AbHx+3Wu -ujGtWF7uLX+/MahOHPfdXqidwG7OpmYnGkL06cA52P0BcZdc1hPGQbQdFJC8aW6U -5X9owRz9IRiwpzRhRqmMJfeqrLaqLL9K5MpCv+qsDzXu9ngRLJDk5CyeEfTjosEr -GWDywWahQKHChamdH701djFGwWGP3gttGvQoMnaSpzeyDKitBZql6bSxKkhWgFop -yxfU7qjbzOASLWaMx2r+MIJ88+AYDqYBTj649N534AYrIdjlQnvEKzGH0sOgHFYO -oaTTvmE/vRPlmbSX1U7mo/SvMWNPZkKUPDltyapOpBltfMiRJH4ndLOXJWRgmYha -SQIDAQABMA0GCSqGSIb3DQEBCwUAA4IBAQAdAwQpntpgUWUxCTk/Pw2+w5v+VxMM -K6QWhm9JdRn3XKQnKrFexVRso/x8TA8V50EUGwQwbnKApNXvJsV2jvbP/YwDsG2u -jBxs0DSspjDvbhUTkuWNYufQZIUGYMyccHap+CKD4rD2loMkmwbh5rII3SGEzUFE -rOY4VhqDjGCcILbChiY/QMA6Uyb6jLGxTARhgblWi9RWr9LuKv7raaUcnAIz1GO8 -z559kUnOKbsB46RZKRa0uIumz9qqXqxnVLWnIwT3DinpXsnzcPqNyyhTk6XR+W5o -0AuUCyT1WKlejrfMmmV6hRNHbT4x7cQrx4EjNf5hM00mN++F+QdGMa/G ------END CERTIFICATE----- diff --git a/test/mrstub/nginx_wsgi_flask/cert/key.crt b/test/mrstub/nginx_wsgi_flask/cert/key.crt deleted file mode 100644 index 105ee75b..00000000 --- a/test/mrstub/nginx_wsgi_flask/cert/key.crt +++ /dev/null @@ -1,30 +0,0 @@ ------BEGIN ENCRYPTED PRIVATE KEY----- -MIIFHzBJBgkqhkiG9w0BBQ0wPDAbBgkqhkiG9w0BBQwwDgQIpz2Uxhl1+ZwCAggA -MB0GCWCGSAFlAwQBKgQQu1or54X1Bk5IMPGoDrdxkASCBNCBKcePejHXlG0fb2qt -TtQrpEr8UR60iFOaeUQ2Lc1zK0wzFCXAIXEWEcaozv75mJ5ReemkBMCyuzPJnoiM -LTeKuoUw8l48S9arB9l+/vVgUnMY0fm+QDsnPffkXKxC2kNwwFgGCT7tIGezuo/e -a9a5JJY707YEnkhUKWAQI2Oz/I95tbeYu64d/WtSN2OLu5JVLsCGAhV4cqcShjEb -pFlfgOHrT0z+qK7YXVR9P74qAZtGsH2ydUrtPtdvddKRpOAm4LzDNmox4Bs6e9nr -jY56sVRiHGhqeeqW04qRks5ReZF7zuwEgUSzGNlAcbbHn6FNJPOZKuN0e8KYexEM -y0G04rSNW8qppMsvez6txsou62CeIZ5LyAumwaJJYzwkob0nCmWYcZl5tSpkXZly -HsQKI2UlO3tiRKd057a46/kxcK85Pwav3Il+FaRXJkzl2rkU3DSy9SjaGL0ROD0U -1EaZCjeDdzN2GmqRQ1WhN5ivowQyWVf6H/mrxtkWZ3qLKmpa1JmvUgOybPcbqqQr -tqjj3Oj0zvLFZDqBjfIlTAAimXPgh6qLHH+qUGrI62pMpaldNZNy/swnpPuTX2sF -TUxFZvnGOmG3qHyvPm91+PypbdVSMb0PeB75XQFqWmajwnua7xfWrH8PLSijp5xQ -aLyiJ1jjFqXWE9D2v7JhB2BNCYlHxP98UI8kHxh7Fw5y0EKT5pCcbrg2nuLzMrCz -D4QaxZRuiIiPgy21kowk3WbHLYAjG7f9cIcbbX6Khc/3ulbB8xJ24WNRuzv4EHeh -TATHqk8nIgpkn1zmvPsKILdWzqZh70IlSctSzoIGzI6C2J76ycSZmcKtar2BZya9 -f1coUlFgXMvdmrf4bt4j2u/biA48OJaVlWBYVfIXUbliFTAQ8biRZFC2n3Xg+W8t -U2xqW14lZWBOIQFJp27foG6Z4JzyL2WZgQ0PWe0m0+tDaKA/LSWB2Qpwt4o2n0cb -RCs++c0eFCeOgErEfmmeburMhzQsfkUqpsL+J/ZMaRSiuTCpYM8qbz+KKT/Z6zbl -2cHWxSFRIqRKAMsj2a61IANjNIdwi2uBHZrWH1HMVVXAbGUJQFKZhxdpn5PBrXqg -vHRa9u0MQFCjs9NcQAGnBQDS6u+pUVO02WT4MvTker+hbu+f6NPU9FMLu+QbQUEP -SUdEZL4W9ZuBTdS3n/fTHEL8wKRB5yEW/CS5JuD+8YinZZXrsd3n3Oky05fdk6Bk -QH9cjMXdsd0Sb0Epw3CWGtXZ6YTHlVWqjdTNlOQdzQ7qfzktgcKujGwvQK0Mgd8x -nmG+f/HWMOss0JEL3ZR+K9Rr50u8/R+W5+e4VE57yw1fg9Jpq2/sVe2Pt8S7isFK -qDLoFZtF5RXi1O9KcA9BpnQX1ihPSC1RoY1pGXoF2D4KkV9U4/4j2qM6MGxjQ6lw -MN0qJ/N70Lti3YWqvYiTymLwVJr8FqoMQsV19MB8012Xd51Bvy6igddhrO83wuuV -b8PlUzl3Tl7yOviYqxiJ0xd8qw+Hs4+FkHbZIFJcUzTHVbb4SlPUE3wn6nrrIcfK -rT4wsYhK3afrlvK3ILi6kzzazS1dK+Hv9+mNozNf5u5nNBFQ+7MhtttzLWIaiV6D -ilLpOwcoO0X0qrzXKR7a+rQ/Dw== ------END ENCRYPTED PRIVATE KEY----- diff --git a/test/mrstub/nginx_wsgi_flask/start-mr.sh b/test/mrstub/nginx_wsgi_flask/start-mr.sh deleted file mode 100755 index b201df75..00000000 --- a/test/mrstub/nginx_wsgi_flask/start-mr.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -# ============LICENSE_START=============================================== -# Copyright (C) 2020 Nordix Foundation. All rights reserved. -# ======================================================================== -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END================================================= -# - -docker build -t testmr . -docker run --name testmrcontainer -p 3905:80 -p 3906:443 testmr \ No newline at end of file diff --git a/test/mrstub/package.json b/test/mrstub/package.json deleted file mode 100644 index ab94945a..00000000 --- a/test/mrstub/package.json +++ /dev/null @@ -1,65 +0,0 @@ -{ - "name": "app", - "version": "1.0.0", - "description": "", - "main": "frontend.js", - "dependencies": { - "accepts": "^1.3.7", - "array-flatten": "^3.0.0", - "body-parser": "^1.19.0", - "bytes": "^3.1.0", - "content-disposition": "^0.5.3", - "content-type": "^1.0.4", - "cookie": "^0.4.1", - "cookie-signature": "^1.1.0", - "debug": "^4.1.1", - "depd": "^2.0.0", - "destroy": "^1.0.4", - "ee-first": "^1.1.1", - "encodeurl": "^1.0.2", - "es6-promise": "^4.2.8", - "escape-html": "^1.0.3", - "etag": "^1.8.1", - "express": "^4.17.1", - "express-http-proxy": "^1.6.0", - "finalhandler": "^1.1.2", - "forwarded": "^0.1.2", - "fresh": "^0.5.2", - "http-errors": "^1.7.3", - "iconv-lite": "^0.5.1", - "inherits": "^2.0.4", - "ipaddr.js": "^1.9.1", - "media-typer": "^1.1.0", - "merge-descriptors": "^1.0.1", - "methods": "^1.1.2", - "mime": "^2.4.5", - "mime-db": "^1.44.0", - "mime-types": "^2.1.27", - "ms": "^2.1.2", - "negotiator": "^0.6.2", - "on-finished": "^2.3.0", - "parseurl": "^1.3.3", - "path-to-regexp": "^6.1.0", - "proxy-addr": "^2.0.6", - "qs": "^6.9.3", - "range-parser": "^1.2.1", - "raw-body": "^2.4.1", - "safe-buffer": "^5.2.0", - "safer-buffer": "^2.1.2", - "send": "^0.17.1", - "serve-static": "^1.14.1", - "setprototypeof": "^1.2.0", - "statuses": "^2.0.0", - "toidentifier": "^1.0.0", - "type-is": "^1.6.18", - "unpipe": "^1.0.0", - "utils-merge": "^1.0.1", - "vary": "^1.1.2" - }, - "devDependencies": {}, - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "", - "license": "ISC" -} diff --git a/test/mrstub/requirements.txt b/test/mrstub/requirements.txt deleted file mode 100644 index 7c2c8e60..00000000 --- a/test/mrstub/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -pip==20.1 -Flask==1.1.2 - - - diff --git a/test/simulator-group/mr/cert/pass b/test/simulator-group/mr/cert/pass new file mode 100644 index 00000000..30d74d25 --- /dev/null +++ b/test/simulator-group/mr/cert/pass @@ -0,0 +1 @@ +test \ No newline at end of file -- 2.16.6