From 723971a39d368f54cf9ee682427c4876af48bd21 Mon Sep 17 00:00:00 2001 From: andri lim Date: Fri, 28 May 2021 23:48:23 +0700 Subject: [PATCH] autobahn: add test for tlsserver (#42) also publish the result to github pages like ws server --- .github/workflows/ci.yml | 25 +++++++++++++++++++++---- autobahn/Readme.md | 33 +++++++++++++++------------------ autobahn/fuzzingclient.json | 2 +- autobahn/fuzzingclient_tls.json | 12 ++++++++++++ autobahn/index.md | 6 ++++++ scripts/start_server_tls.sh | 27 +++++++++++++++++++++++++++ 6 files changed, 82 insertions(+), 23 deletions(-) create mode 100644 autobahn/fuzzingclient_tls.json create mode 100644 autobahn/index.md create mode 100644 scripts/start_server_tls.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 55b211e0..dc4a0e53 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -202,27 +202,44 @@ jobs: nimble test - name: Setup Python version - if: runner.os == 'macos' && matrix.target.cpu == 'amd64' + if: runner.os == 'linux' && matrix.target.cpu == 'amd64' && github.event_name == 'push' uses: actions/setup-python@v2 with: python-version: pypy-2.7 - name: Setup and run Autobahn test suite. - if: runner.os == 'macos' && matrix.target.cpu == 'amd64' + # we switch to linux because + # kill $(pidof server) not working on macos + if: runner.os == 'linux' && matrix.target.cpu == 'amd64' && github.event_name == 'push' run: | + sudo apt-get install -y python-dev pip install virtualenv + pip install markdown2 virtualenv --python=/usr/bin/python2 autobahn source autobahn/bin/activate pip install autobahntestsuite cd nim-ws + mkdir autobahn/reports + sed -i "s/COMMIT_SHA_SHORT/${GITHUB_SHA::7}/g" autobahn/index.md + sed -i "s/COMMIT_SHA/$GITHUB_SHA/g" autobahn/index.md + markdown2 autobahn/index.md > autobahn/reports/index.html + chmod +x ./scripts/start_server.sh ./scripts/start_server.sh cd autobahn wstest --mode fuzzingclient --spec fuzzingclient.json + kill $(pidof server) + + cd .. + chmod +x ./scripts/start_server_tls.sh + ./scripts/start_server_tls.sh + cd autobahn + wstest --mode fuzzingclient --spec fuzzingclient_tls.json + kill $(pidof tlsserver) - name: Deploy autobahn report. - if: runner.os == 'macos' && matrix.target.cpu == 'amd64' + if: runner.os == 'linux' && matrix.target.cpu == 'amd64' && github.event_name == 'push' uses: peaceiris/actions-gh-pages@v3 with: personal_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./nim-ws/autobahn/reports/servers + publish_dir: ./nim-ws/autobahn/reports diff --git a/autobahn/Readme.md b/autobahn/Readme.md index 684518ac..73936953 100644 --- a/autobahn/Readme.md +++ b/autobahn/Readme.md @@ -1,25 +1,22 @@ ## Running autobahn test suite. -### Start the websocket server - -```bash -nim c -r examples/server.nim -``` ### Install autobahn - ```bash - # Set up virtualenv in autobahn folder - virtualenv --python=/usr/bin/python2 autobahn +```bash +# Set up virtualenv in autobahn folder +virtualenv --python=/usr/bin/python2 autobahn - # Activate the virtualenv - source autobahn/bin/activate +# Activate the virtualenv +source autobahn/bin/activate - # Install autobahn - pip install autobahntestsuite - ``` +# Install autobahn +pip install autobahntestsuite +``` - ### Run the test Websocket client. - ```bash - wstest --mode fuzzingclient --spec fuzzingclient.json - ``` +### Run the test Websocket client. +* ws server: `nim c -r examples/server.nim` + * autobahn: `wstest --mode fuzzingclient --spec fuzzingclient.json` + * Reports will be generated in `reports/server` which can be configured in `fuzzingclient.json` - Reports will be generated in `reports/server` which can be configured in `fuzzingclient.json` \ No newline at end of file +* wss server: `nim c -r examples/tlsserver.nim` + * autobahn: `wstest --mode fuzzingclient --spec fuzzingclient_tls.json` + * Reports will be generated in `reports/server_tls` which can be configured in `fuzzingclient_tls.json` diff --git a/autobahn/fuzzingclient.json b/autobahn/fuzzingclient.json index 456a2bf7..e41c882b 100644 --- a/autobahn/fuzzingclient.json +++ b/autobahn/fuzzingclient.json @@ -1,5 +1,5 @@ { - "outdir": "./reports/servers", + "outdir": "./reports/server", "servers": [ { "agent": "nim-ws example server", diff --git a/autobahn/fuzzingclient_tls.json b/autobahn/fuzzingclient_tls.json new file mode 100644 index 00000000..fab38ddb --- /dev/null +++ b/autobahn/fuzzingclient_tls.json @@ -0,0 +1,12 @@ +{ + "outdir": "./reports/server_tls", + + "servers": [{ + "agent": "nim-ws tls server", + "url": "wss://127.0.0.1:8888/wss" + }], + + "cases": ["*"], + "exclude-cases": [], + "exclude-agent-cases": {} +} diff --git a/autobahn/index.md b/autobahn/index.md new file mode 100644 index 00000000..b028ad60 --- /dev/null +++ b/autobahn/index.md @@ -0,0 +1,6 @@ +# Autobahn summary report + +Generated by commit [COMMIT_SHA_SHORT](https://github.com/status-im/nim-ws/commit/COMMIT_SHA). + +* [ws server summary report](server/index.html) +* [wss server summary report](server_tls/index.html) diff --git a/scripts/start_server_tls.sh b/scripts/start_server_tls.sh new file mode 100644 index 00000000..375b8a06 --- /dev/null +++ b/scripts/start_server_tls.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +nim c -r examples/tlsserver.nim & + +max_iterations=10 +wait_seconds=6 +http_endpoint="https://127.0.0.1:8888/" + +iterations=0 +while true +do + ((iterations++)) + echo "Attempt $iterations" + sleep $wait_seconds + + http_code=$(curl -k --verbose -s -o /tmp/result.txt -w '%{http_code}' "$http_endpoint";) + + if [ "$http_code" -eq 200 ]; then + echo "Server Up" + break + fi + + if [ "$iterations" -ge "$max_iterations" ]; then + echo "Loop Timeout" + exit 1 + fi +done