From 8bc7fde247cdf4fb6c7c9b5bc3dd57020cfafda6 Mon Sep 17 00:00:00 2001 From: David Garvey Date: Thu, 16 Feb 2023 10:29:53 +0100 Subject: [PATCH 01/19] update script to run all tests --- .github/workflows/tyk-demo-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tyk-demo-tests.yml b/.github/workflows/tyk-demo-tests.yml index 873509dd..65db8fa8 100644 --- a/.github/workflows/tyk-demo-tests.yml +++ b/.github/workflows/tyk-demo-tests.yml @@ -29,5 +29,5 @@ jobs: if: success() || failure() run: cat bootstrap.log - name: Run Postman tests - run: sudo ./scripts/test.sh + run: sudo ./scripts/test-all.sh - run: echo "🍏 This job's status is ${{ job.status }}." From 4514995539e79525eb08eb18219a6cdf4d2e7d48 Mon Sep 17 00:00:00 2001 From: David Garvey Date: Thu, 16 Feb 2023 10:41:05 +0100 Subject: [PATCH 02/19] Refactor github action to test all eligible deployments --- .github/workflows/tyk-demo-tests.yml | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/.github/workflows/tyk-demo-tests.yml b/.github/workflows/tyk-demo-tests.yml index 65db8fa8..bf845e0b 100644 --- a/.github/workflows/tyk-demo-tests.yml +++ b/.github/workflows/tyk-demo-tests.yml @@ -7,27 +7,25 @@ jobs: - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." - - name: Check out repository code + - name: Check Out Repository Code uses: actions/checkout@v3 - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." - - name: Create environment file + - name: Create Environment File uses: "finnp/create-file-action@master" env: FILE_NAME: ".env" FILE_DATA: "DASHBOARD_LICENCE=${{ secrets.DASH_LICENSE }}" - - name: Update hosts + - name: Update Hosts run: sudo ./scripts/update-hosts.sh - - name: Bootstrap Tyk - run: sudo ./up.sh - - name: Store bootstrap log + - name: Bootstrap and Test All Eligible Deployments + run: sudo ./scripts/test-all.sh + - name: Store Bootstrap Log if: success() || failure() uses: actions/upload-artifact@v3 with: name: bootstrap-log path: bootstrap.log - - name: Show bootstrap log + - name: Show Bootstrap Log if: success() || failure() run: cat bootstrap.log - - name: Run Postman tests - run: sudo ./scripts/test-all.sh - run: echo "🍏 This job's status is ${{ job.status }}." From c759ccf727c32a28a49610ce4e635064dc60c1ce Mon Sep 17 00:00:00 2001 From: David Garvey Date: Thu, 16 Feb 2023 11:05:57 +0100 Subject: [PATCH 03/19] refactor workflow env var actions --- .github/workflows/tyk-demo-tests.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tyk-demo-tests.yml b/.github/workflows/tyk-demo-tests.yml index bf845e0b..03e12f62 100644 --- a/.github/workflows/tyk-demo-tests.yml +++ b/.github/workflows/tyk-demo-tests.yml @@ -11,10 +11,9 @@ jobs: uses: actions/checkout@v3 - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." - name: Create Environment File - uses: "finnp/create-file-action@master" - env: - FILE_NAME: ".env" - FILE_DATA: "DASHBOARD_LICENCE=${{ secrets.DASH_LICENSE }}" + run: | + echo "DASHBOARD_LICENCE=${{ secrets.DASH_LICENSE }}" >> $GITHUB_ENV + echo "MDCB_LICENCE=${{ secrets.MDCB_LICENSE }}" >> $GITHUB_ENV - name: Update Hosts run: sudo ./scripts/update-hosts.sh - name: Bootstrap and Test All Eligible Deployments From d6d96a4f1c6b7ec47c117d616e6ed81e153420ad Mon Sep 17 00:00:00 2001 From: David Garvey Date: Thu, 16 Feb 2023 11:09:43 +0100 Subject: [PATCH 04/19] debugging env file creation --- .github/workflows/tyk-demo-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tyk-demo-tests.yml b/.github/workflows/tyk-demo-tests.yml index 03e12f62..44032b09 100644 --- a/.github/workflows/tyk-demo-tests.yml +++ b/.github/workflows/tyk-demo-tests.yml @@ -12,8 +12,8 @@ jobs: - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." - name: Create Environment File run: | - echo "DASHBOARD_LICENCE=${{ secrets.DASH_LICENSE }}" >> $GITHUB_ENV - echo "MDCB_LICENCE=${{ secrets.MDCB_LICENSE }}" >> $GITHUB_ENV + echo "DASHBOARD_LICENCE=${{ secrets.DASH_LICENSE }}" >> .env + echo "MDCB_LICENCE=${{ secrets.MDCB_LICENSE }}" >> .env - name: Update Hosts run: sudo ./scripts/update-hosts.sh - name: Bootstrap and Test All Eligible Deployments From cd473481b76693c417d98794bffe25a9c62c0b9f Mon Sep 17 00:00:00 2001 From: David Garvey Date: Thu, 16 Feb 2023 11:36:16 +0100 Subject: [PATCH 05/19] resolve issue with env var not being set --- deployments/mdcb/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployments/mdcb/docker-compose.yml b/deployments/mdcb/docker-compose.yml index 96b6984f..18b0c0aa 100644 --- a/deployments/mdcb/docker-compose.yml +++ b/deployments/mdcb/docker-compose.yml @@ -21,7 +21,7 @@ services: environment: - TYK_INSTRUMENTATION=${INSTRUMENTATION_ENABLED:-0} - TYK_GW_TRACER_ENABLED=${TRACING_ENABLED:-0} - - TYK_GW_SLAVEOPTIONS_APIKEY=${MDCB_USER_API_CREDENTIALS:?} + - TYK_GW_SLAVEOPTIONS_APIKEY=${MDCB_USER_API_CREDENTIALS:-placeholder} volumes: - ./deployments/mdcb/volumes/tyk-worker-gateway/tyk.conf:/opt/tyk-gateway/tyk.conf - ./deployments/tyk/volumes/tyk-gateway/certs:/opt/tyk-gateway/certs From 0111d561920605389b38e6477825fbd12362260c Mon Sep 17 00:00:00 2001 From: David Garvey Date: Thu, 16 Feb 2023 11:51:43 +0100 Subject: [PATCH 06/19] fix issue with not counting failures --- scripts/test-all.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/test-all.sh b/scripts/test-all.sh index 4d88c839..ef360a1b 100755 --- a/scripts/test-all.sh +++ b/scripts/test-all.sh @@ -131,10 +131,10 @@ do test_skip_count=$((test_skip_count+1));; 4) echo "$(tput setaf 1)Fail$(tput sgr 0) ${result_names[$i]} - Create failed" - test_skip_count=$((test_fail_count+1));; + test_fail_count=$((test_fail_count+1));; 5) echo "$(tput setaf 1)Fail$(tput sgr 0) ${result_names[$i]} - Remove failed" - test_skip_count=$((test_fail_count+1));; + test_fail_count=$((test_fail_count+1));; *) echo "ERROR: Unexpected result code. Exiting." exit 2;; From 82dbf1f66c6ee74655c436217ca57287ec6c777e Mon Sep 17 00:00:00 2001 From: David Garvey Date: Thu, 16 Feb 2023 13:00:31 +0100 Subject: [PATCH 07/19] fix colour usage for github action console --- scripts/test-all.sh | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/scripts/test-all.sh b/scripts/test-all.sh index ef360a1b..f908cb3a 100755 --- a/scripts/test-all.sh +++ b/scripts/test-all.sh @@ -13,6 +13,11 @@ # If no tests fail then this script will exit with a 0, otherwise it will be a non-zero value # The script must be run from the repository root i.e. ./scripts/test-all.sh +RED='\033[0;31m' +GREEN='\033[0;32m' +BLUE='\033[0;34m' +NOCOLOUR='\033[0m' + echo "Checking for active deployments" if [ ! -s .bootstrap/bootstrapped_deployments ]; then echo " No active deployments found - proceeding with tests" @@ -118,22 +123,22 @@ do result_print="" case ${result_codes[$i]} in 0) - echo "$(tput setaf 2)Pass$(tput sgr 0) ${result_names[$i]} - Tests passed" + echo "${GREEN}Pass${NOCOLOUR} ${result_names[$i]} - Tests passed" test_pass_count=$((test_pass_count+1));; 1) - echo "$(tput setaf 1)Fail$(tput sgr 0) ${result_names[$i]} - Tests failed" + echo "${RED}Fail${NOCOLOUR} ${result_names[$i]} - Tests failed" test_fail_count=$((test_fail_count+1));; 2) - echo "$(tput setaf 4)Skip$(tput sgr 0) ${result_names[$i]} - No collection" + echo "${BLUE}Skip${NOCOLOUR} ${result_names[$i]} - No collection" test_skip_count=$((test_skip_count+1));; 3) - echo "$(tput setaf 4)Skip$(tput sgr 0) ${result_names[$i]} - No tests" + echo "${BLUE}Skip${NOCOLOUR} ${result_names[$i]} - No tests" test_skip_count=$((test_skip_count+1));; 4) - echo "$(tput setaf 1)Fail$(tput sgr 0) ${result_names[$i]} - Create failed" + echo "${RED}Fail${NOCOLOUR} ${result_names[$i]} - Create failed" test_fail_count=$((test_fail_count+1));; 5) - echo "$(tput setaf 1)Fail$(tput sgr 0) ${result_names[$i]} - Remove failed" + echo "$(tput setaf 1)Fail${NOCOLOUR} ${result_names[$i]} - Remove failed" test_fail_count=$((test_fail_count+1));; *) echo "ERROR: Unexpected result code. Exiting." @@ -142,9 +147,9 @@ do done echo -e "\nTest Result Totals:" -echo "$(tput setaf 2)Pass$(tput sgr 0):$test_pass_count" -echo "$(tput setaf 1)Fail$(tput sgr 0):$test_fail_count" -echo "$(tput setaf 4)Skip$(tput sgr 0):$test_skip_count" +echo "${GREEN}Pass${NOCOLOUR}:$test_pass_count" +echo "${RED}Fail${NOCOLOUR}:$test_fail_count" +echo "${BLUE}Skip${NOCOLOUR}:$test_skip_count" echo -e "\nExit Status:" if [ $test_fail_count = 0 ]; then From 749d83de5d045de89d10acd4a9dab1a8c8414d07 Mon Sep 17 00:00:00 2001 From: David Garvey Date: Thu, 16 Feb 2023 14:52:07 +0100 Subject: [PATCH 08/19] enable bootstrap log persistence --- up.sh | 58 ++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/up.sh b/up.sh index eacfae18..1a5c59f7 100755 --- a/up.sh +++ b/up.sh @@ -2,10 +2,9 @@ source scripts/common.sh -echo "Bringing Tyk Demo deployment UP" +persist_log=false -# restart bootstrap log file -echo -n > bootstrap.log +echo "Bringing Tyk Demo deployment UP" # check .env file exists if [ ! -f .env ]; then @@ -61,19 +60,41 @@ else deployments_to_create+=("tyk") fi -# extract new deployments from arguments -for deployment in "$@"; do - # skip "tyk" deployment, as it is handled automatically - [ "$deployment" == "tyk" ] && continue - - # skip existing deployments, to avoid rebootstrapping - if [ ! -z $(grep "$deployment" ".bootstrap/bootstrapped_deployments") ]; then - echo "Deployment \"$deployment\" already exists, skipping." - continue - fi - - echo "$deployment" >> .bootstrap/bootstrapped_deployments - deployments_to_create+=("$deployment") +deployment_names=(deployments/*) +# process arguments +for argument in "$@"; do + argument_is_deployment=false + # process arguments that refer to deployments + for deployment_name in "${deployment_names[@]}" + do + if [ "deployments/$argument" = "$deployment_name" ]; then + argument_is_deployment=true + + # "tyk" deployment is handled automatically, so skip + [ "$deployment_name" == "tyk" ] && continue + + # skip existing deployments, to avoid rebootstrapping + if [ ! -z $(grep "$argument" ".bootstrap/bootstrapped_deployments") ]; then + echo "Deployment \"$argument\" already exists, skipping." + continue + fi + + echo "$argument" >> .bootstrap/bootstrapped_deployments + deployments_to_create+=("$argument") + break + fi + done + + # continue if argument was processed as a deployment + [ "$argument_is_deployment" = true ] && continue + + # process arguments that are not deployments + case $argument in + "persist-log") + echo "Persisting bootstrap log" + persist_log=true;; + *) echo "Argument \"$argument\" is unknown, ignoring.";; + esac done # check if bootstrap is needed @@ -89,6 +110,11 @@ for deployment in "${deployments_to_create[@]}"; do echo " $deployment" done +# clear log, if it is not persisted +if [ "$persist_log" = false ]; then + echo -n > bootstrap.log +fi + # bring the containers up command_docker_compose="$(generate_docker_compose_command) up --remove-orphans -d" echo "Running docker compose command: $command_docker_compose" From 7ce32950d5cb6c30732a72d0b6c89754449eaff9 Mon Sep 17 00:00:00 2001 From: David Garvey Date: Thu, 16 Feb 2023 15:06:15 +0100 Subject: [PATCH 09/19] use persistence + fix colours --- scripts/test-all.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/test-all.sh b/scripts/test-all.sh index f908cb3a..0defad21 100755 --- a/scripts/test-all.sh +++ b/scripts/test-all.sh @@ -68,7 +68,7 @@ do fi echo "Creating deployment: $deployment_name" - ./up.sh $deployment_name + ./up.sh $deployment_name persist-log if [ "$?" != "0" ]; then echo " Failed to create $deployment_name deployment" result_codes[${#result_codes[@]}]=4 @@ -123,22 +123,22 @@ do result_print="" case ${result_codes[$i]} in 0) - echo "${GREEN}Pass${NOCOLOUR} ${result_names[$i]} - Tests passed" + echo -e "${GREEN}Pass${NOCOLOUR} ${result_names[$i]} - Tests passed" test_pass_count=$((test_pass_count+1));; 1) - echo "${RED}Fail${NOCOLOUR} ${result_names[$i]} - Tests failed" + echo -e "${RED}Fail${NOCOLOUR} ${result_names[$i]} - Tests failed" test_fail_count=$((test_fail_count+1));; 2) - echo "${BLUE}Skip${NOCOLOUR} ${result_names[$i]} - No collection" + echo -e "${BLUE}Skip${NOCOLOUR} ${result_names[$i]} - No collection" test_skip_count=$((test_skip_count+1));; 3) - echo "${BLUE}Skip${NOCOLOUR} ${result_names[$i]} - No tests" + echo -e "${BLUE}Skip${NOCOLOUR} ${result_names[$i]} - No tests" test_skip_count=$((test_skip_count+1));; 4) - echo "${RED}Fail${NOCOLOUR} ${result_names[$i]} - Create failed" + echo -e "${RED}Fail${NOCOLOUR} ${result_names[$i]} - Create failed" test_fail_count=$((test_fail_count+1));; 5) - echo "$(tput setaf 1)Fail${NOCOLOUR} ${result_names[$i]} - Remove failed" + echo -e "$(tput setaf 1)Fail${NOCOLOUR} ${result_names[$i]} - Remove failed" test_fail_count=$((test_fail_count+1));; *) echo "ERROR: Unexpected result code. Exiting." @@ -147,9 +147,9 @@ do done echo -e "\nTest Result Totals:" -echo "${GREEN}Pass${NOCOLOUR}:$test_pass_count" -echo "${RED}Fail${NOCOLOUR}:$test_fail_count" -echo "${BLUE}Skip${NOCOLOUR}:$test_skip_count" +echo -e "${GREEN}Pass${NOCOLOUR}:$test_pass_count" +echo -e "${RED}Fail${NOCOLOUR}:$test_fail_count" +echo -e "${BLUE}Skip${NOCOLOUR}:$test_skip_count" echo -e "\nExit Status:" if [ $test_fail_count = 0 ]; then From 8b7c4b68a2e3c373deee5652c183ba9c4c1e44a9 Mon Sep 17 00:00:00 2001 From: David Garvey Date: Thu, 16 Feb 2023 15:17:25 +0100 Subject: [PATCH 10/19] add missing escape flags --- scripts/test-all.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/test-all.sh b/scripts/test-all.sh index 0defad21..be13effb 100755 --- a/scripts/test-all.sh +++ b/scripts/test-all.sh @@ -49,7 +49,7 @@ do echo "Validating deployment's Postman collection ($postman_collection_file_name)" if [ -z "$(ls -A $postman_collection_path 2>/dev/null)" ]; then - echo " Collection not found. Skipping to next deployment." + echo -e " Collection not found. ${BLUE}Skipping${NOCOLOUR} to next deployment." result_codes[${#result_codes[@]}]=2 continue else @@ -60,7 +60,7 @@ do # The jq command finds "listen" fields which have the value "test", if none are returned then the collection doesn't contain any tests postman_collection_tests=$(jq '..|.listen?|select(.=="test")' $postman_collection_path) if [[ "$postman_collection_tests" == "" ]]; then - echo " Collection does not contain any tests. Skipping to next deployment." + echo -e " Collection does not contain any tests. ${BLUE}Skipping${NOCOLOUR} to next deployment." result_codes[${#result_codes[@]}]=3 continue else @@ -70,7 +70,7 @@ do echo "Creating deployment: $deployment_name" ./up.sh $deployment_name persist-log if [ "$?" != "0" ]; then - echo " Failed to create $deployment_name deployment" + echo -e " ${RED}Failed${NOCOLOUR} to create $deployment_name deployment" result_codes[${#result_codes[@]}]=4 echo "Removing deployment: $deployment_name" ./down.sh @@ -92,10 +92,10 @@ do --insecure if [ "$?" != "0" ]; then - echo "Tests failed for $deployment_name deployment" + echo -e "Tests ${RED}failed${NOCOLOUR} for $deployment_name deployment" result_codes[${#result_codes[@]}]=1 else - echo "Tests passed for $deployment_name deployment" + echo -e "Tests ${GREEN}passed${NOCOLOUR} for $deployment_name deployment" result_codes[${#result_codes[@]}]=0 fi @@ -103,7 +103,7 @@ do ./down.sh if [ "$?" != "0" ]; then - echo " Failed to remove $deployment_name deployment" + echo -e " ${RED}Failed${NOCOLOUR} to remove $deployment_name deployment" result_codes[${#result_codes[@]}]=5 # failing to remove a deployment may negatively affect subsequent deployments and tests continue From 913cdb82907a8a9cf21faa7325c22c994ac4671d Mon Sep 17 00:00:00 2001 From: David Garvey Date: Thu, 16 Feb 2023 15:55:59 +0100 Subject: [PATCH 11/19] attempt to fix port issue on github container --- deployments/mdcb/README.md | 4 ++-- deployments/mdcb/bootstrap.sh | 2 +- deployments/mdcb/docker-compose.yml | 2 +- deployments/mdcb/tyk_demo_mdcb.postman_collection.json | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/deployments/mdcb/README.md b/deployments/mdcb/README.md index ee2d29e5..ab834dcf 100644 --- a/deployments/mdcb/README.md +++ b/deployments/mdcb/README.md @@ -12,7 +12,7 @@ MDCB architecture creates a Control Plane and a Data Plane: - MDCB is the link between the Planes The worker Gateway can be accessed here: -- [Tyk Worker Gateway](http://tyk-worker-gateway.localhost:8084) +- [Tyk Worker Gateway](http://tyk-worker-gateway.localhost:8090) ## Setup @@ -79,7 +79,7 @@ These indicate that the Gateway has lost its connection to MDCB. You can then try accessing APIs via the Worker Gateway: ``` -curl http://tyk-worker-gateway.localhost:8084/basic-open-api/get +curl http://tyk-worker-gateway.localhost:8090/basic-open-api/get ``` You will receive a response, despite the Gateway being disconnected from MDCB. In a typical multi-data centre deployment, this would allow the Gateway to continue operating in the event of connectivity disuption between it and the primary data centre where MDCB is deployed. diff --git a/deployments/mdcb/bootstrap.sh b/deployments/mdcb/bootstrap.sh index fc25b005..fa8daf6b 100755 --- a/deployments/mdcb/bootstrap.sh +++ b/deployments/mdcb/bootstrap.sh @@ -7,7 +7,7 @@ log_start_deployment bootstrap_progress log_message "Setting global variables" -worker_gateway_base_url="http://tyk-worker-gateway.localhost:8084" +worker_gateway_base_url="http://tyk-worker-gateway.localhost:8090" dashboard_base_url="http://tyk-dashboard.localhost:3000" log_ok bootstrap_progress diff --git a/deployments/mdcb/docker-compose.yml b/deployments/mdcb/docker-compose.yml index 18b0c0aa..8fc2d1a5 100644 --- a/deployments/mdcb/docker-compose.yml +++ b/deployments/mdcb/docker-compose.yml @@ -15,7 +15,7 @@ services: tyk-worker-gateway: image: tykio/tyk-gateway:${GATEWAY_WORKER_VERSION:-v4.3.3-rc2} ports: - - 8084:8080 + - 8090:8080 networks: - tyk environment: diff --git a/deployments/mdcb/tyk_demo_mdcb.postman_collection.json b/deployments/mdcb/tyk_demo_mdcb.postman_collection.json index bbf3d261..7e623ba9 100644 --- a/deployments/mdcb/tyk_demo_mdcb.postman_collection.json +++ b/deployments/mdcb/tyk_demo_mdcb.postman_collection.json @@ -44,7 +44,7 @@ "variable": [ { "key": "tyk-worker-gateway.host", - "value": "tyk-worker-gateway.localhost:8084" + "value": "tyk-worker-gateway.localhost:8090" } ] } \ No newline at end of file From 84163ec6be19e7bfc6ff7c3ffd4740a12d11769f Mon Sep 17 00:00:00 2001 From: David Garvey Date: Thu, 16 Feb 2023 17:59:52 +0100 Subject: [PATCH 12/19] use new image tag format + provide backend target --- deployments/waf/docker-compose.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deployments/waf/docker-compose.yml b/deployments/waf/docker-compose.yml index 00758727..365558fa 100644 --- a/deployments/waf/docker-compose.yml +++ b/deployments/waf/docker-compose.yml @@ -1,13 +1,14 @@ version: '3.3' services: waf: - image: owasp/modsecurity-crs:v3.0 + image: owasp/modsecurity-crs:3.3.4-apache-202302060502 networks: - tyk ports: - "8500:80" environment: - PARANOIA=1 + - BACKEND=http://httpbin deploy: restart_policy: condition: any \ No newline at end of file From 26274b99669c339390f7211813b4575cdb094d1f Mon Sep 17 00:00:00 2001 From: David Garvey Date: Fri, 17 Feb 2023 11:39:50 +0100 Subject: [PATCH 13/19] update tests for new modsecurity-crs version --- .../waf/tyk_demo_waf.postman_collection.json | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/deployments/waf/tyk_demo_waf.postman_collection.json b/deployments/waf/tyk_demo_waf.postman_collection.json index acf73398..6dc9b9ce 100644 --- a/deployments/waf/tyk_demo_waf.postman_collection.json +++ b/deployments/waf/tyk_demo_waf.postman_collection.json @@ -1,6 +1,6 @@ { "info": { - "_postman_id": "eeb6bf53-3960-4bb4-aaf0-0a1f1239dfb5", + "_postman_id": "9806a85d-289d-423f-be8f-ba8e2fdae08d", "name": "Tyk Demo - WAF", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" }, @@ -11,14 +11,14 @@ { "listen": "test", "script": { - "id": "b8e091fa-5bf4-429b-af47-84fbb05fddd6", "exec": [ "pm.test(\"Response time is less than 200ms\", function () {", " pm.expect(pm.response.responseTime).to.be.below(200);", "});", "", - "pm.test(\"Body matches string\", function () {", - " pm.expect(pm.response.text()).to.include(\"hello world\");", + "pm.test(\"Non-empty UUID response returned\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.uuid).is.not.empty;", "});" ], "type": "text/javascript" @@ -29,13 +29,16 @@ "method": "GET", "header": [], "url": { - "raw": "http://{{waf.host}}", + "raw": "http://{{waf.host}}/uuid", "protocol": "http", "host": [ "{{waf.host}}" + ], + "path": [ + "uuid" ] }, - "description": "This request checks that the Web Application Firewall (WAF) is operational.\n\nIt should return a HTTP 200 response with the body text `hello world`." + "description": "This request checks that the Web Application Firewall (WAF) is operational.\n\nIt should return a HTTP 200 response with a JSON body containing a UUID." }, "response": [] }, @@ -45,7 +48,6 @@ { "listen": "test", "script": { - "id": "e35f2848-c599-49c2-b2b6-271fe944c0bb", "exec": [ "pm.test(\"Status code is 403\", function () {", " pm.response.to.have.status(403);", @@ -83,7 +85,6 @@ { "listen": "test", "script": { - "id": "9497f7bc-b1be-4c0d-9832-7016ff2c61ac", "exec": [ "pm.test(\"Status code is 200\", function () {", " pm.response.to.have.status(200);", @@ -116,7 +117,6 @@ { "listen": "test", "script": { - "id": "a5902804-e15d-4cc8-b974-208783e9cb2f", "exec": [ "pm.test(\"Status code is 400\", function () {", " pm.response.to.have.status(400);", @@ -155,7 +155,6 @@ "response": [] } ], - "protocolProfileBehavior": {}, "variable": [ { "key": "waf.host", From 9384540acacf91009d7df7c9c43257d21cce89e8 Mon Sep 17 00:00:00 2001 From: David Garvey Date: Fri, 17 Feb 2023 12:34:46 +0100 Subject: [PATCH 14/19] optimise logic and improve docs --- up.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/up.sh b/up.sh index 1a5c59f7..5f3d6100 100755 --- a/up.sh +++ b/up.sh @@ -2,6 +2,8 @@ source scripts/common.sh +# persistence of bootstrap.log file is disabled by default, meaning the file is +# to enable persistence, use argument "persist-log" when running this script persist_log=false echo "Bringing Tyk Demo deployment UP" @@ -64,19 +66,20 @@ deployment_names=(deployments/*) # process arguments for argument in "$@"; do argument_is_deployment=false + + # "tyk" deployment is handled automatically, so ignore and continue to next argument + [ "$deployment_name" == "tyk" ] && continue + # process arguments that refer to deployments for deployment_name in "${deployment_names[@]}" do if [ "deployments/$argument" = "$deployment_name" ]; then argument_is_deployment=true - # "tyk" deployment is handled automatically, so skip - [ "$deployment_name" == "tyk" ] && continue - # skip existing deployments, to avoid rebootstrapping if [ ! -z $(grep "$argument" ".bootstrap/bootstrapped_deployments") ]; then echo "Deployment \"$argument\" already exists, skipping." - continue + break fi echo "$argument" >> .bootstrap/bootstrapped_deployments @@ -85,7 +88,7 @@ for argument in "$@"; do fi done - # continue if argument was processed as a deployment + # skip to next argument if this argument has already been processed as a deployment [ "$argument_is_deployment" = true ] && continue # process arguments that are not deployments From 4c17a1d93005a37423e5115df10cc27404b6881c Mon Sep 17 00:00:00 2001 From: David Garvey Date: Fri, 17 Feb 2023 16:50:58 +0100 Subject: [PATCH 15/19] create test results log + asset --- .github/workflows/tyk-demo-tests.yml | 6 ++++++ .gitignore | 1 + scripts/test-all.sh | 6 +++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tyk-demo-tests.yml b/.github/workflows/tyk-demo-tests.yml index 44032b09..8d7b2d8e 100644 --- a/.github/workflows/tyk-demo-tests.yml +++ b/.github/workflows/tyk-demo-tests.yml @@ -24,6 +24,12 @@ jobs: with: name: bootstrap-log path: bootstrap.log + - name: Store Test Results Log + if: success() || failure() + uses: actions/upload-artifact@v3 + with: + name: test-results-log + path: test-results.log - name: Show Bootstrap Log if: success() || failure() run: cat bootstrap.log diff --git a/.gitignore b/.gitignore index 50d64b04..01a7af14 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ deployments/tyk/volumes/tyk-gateway/certs/tls-private-key.pem deployments/tyk/volumes/tyk-gateway/certs/private-key.pem deployments/tyk/volumes/tyk-gateway/certs/public-key.pem deployments/tyk/volumes/tyk-dashboard/certs/private-key.pem +test-result.log ## Portal Deployment deployments/portal/volumes/database/portal.db diff --git a/scripts/test-all.sh b/scripts/test-all.sh index be13effb..221b8805 100755 --- a/scripts/test-all.sh +++ b/scripts/test-all.sh @@ -30,6 +30,9 @@ else ./down.sh fi +# clear test result log file +echo -n > test-result.log + declare -a result_names declare -a result_codes @@ -89,7 +92,8 @@ do postman/newman:alpine \ run "/etc/postman/tyk_demo.postman_collection.json" \ --environment /etc/postman/test.postman_environment.json \ - --insecure + --insecure \ + | tee -a test-result.log if [ "$?" != "0" ]; then echo -e "Tests ${RED}failed${NOCOLOUR} for $deployment_name deployment" From a81ff2fd1cda16248bc3b981933618c07d73aa62 Mon Sep 17 00:00:00 2001 From: David Garvey Date: Fri, 17 Feb 2023 17:27:24 +0100 Subject: [PATCH 16/19] fix file name --- .github/workflows/tyk-demo-tests.yml | 6 +++--- .gitignore | 2 +- scripts/test-all.sh | 6 ++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/tyk-demo-tests.yml b/.github/workflows/tyk-demo-tests.yml index 8d7b2d8e..64036ac4 100644 --- a/.github/workflows/tyk-demo-tests.yml +++ b/.github/workflows/tyk-demo-tests.yml @@ -24,12 +24,12 @@ jobs: with: name: bootstrap-log path: bootstrap.log - - name: Store Test Results Log + - name: Store Test Log if: success() || failure() uses: actions/upload-artifact@v3 with: - name: test-results-log - path: test-results.log + name: test-log + path: test.log - name: Show Bootstrap Log if: success() || failure() run: cat bootstrap.log diff --git a/.gitignore b/.gitignore index 01a7af14..dd9b288e 100644 --- a/.gitignore +++ b/.gitignore @@ -18,7 +18,7 @@ deployments/tyk/volumes/tyk-gateway/certs/tls-private-key.pem deployments/tyk/volumes/tyk-gateway/certs/private-key.pem deployments/tyk/volumes/tyk-gateway/certs/public-key.pem deployments/tyk/volumes/tyk-dashboard/certs/private-key.pem -test-result.log +test.log ## Portal Deployment deployments/portal/volumes/database/portal.db diff --git a/scripts/test-all.sh b/scripts/test-all.sh index 221b8805..cd9718d2 100755 --- a/scripts/test-all.sh +++ b/scripts/test-all.sh @@ -31,7 +31,7 @@ else fi # clear test result log file -echo -n > test-result.log +echo -n > test.log declare -a result_names declare -a result_codes @@ -93,7 +93,9 @@ do run "/etc/postman/tyk_demo.postman_collection.json" \ --environment /etc/postman/test.postman_environment.json \ --insecure \ - | tee -a test-result.log + | tee -a test.log + # output of above command is captured in test.log file + # file will contain control characters, so is advised to use command "less -r test.log", or similar, to view it if [ "$?" != "0" ]; then echo -e "Tests ${RED}failed${NOCOLOUR} for $deployment_name deployment" From f59ddda28a82b33cdfe45aff05d6b0a91b3a3005 Mon Sep 17 00:00:00 2001 From: David Garvey Date: Fri, 17 Feb 2023 17:40:16 +0100 Subject: [PATCH 17/19] note about test failure due to environment --- scripts/test-all.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/test-all.sh b/scripts/test-all.sh index cd9718d2..06e50ceb 100755 --- a/scripts/test-all.sh +++ b/scripts/test-all.sh @@ -11,6 +11,7 @@ # A test is considered successful if a deployment can be created, tested and removed without error # The scope of testing is limited to the tests defined within the Postman collection # If no tests fail then this script will exit with a 0, otherwise it will be a non-zero value +# Tests may fail due to environmental reasons, so if you experience a failure it's worth checking that it wasn't caused by an environmental error, such as lack of resources # The script must be run from the repository root i.e. ./scripts/test-all.sh RED='\033[0;31m' From 33321bc85de1dd7803dfb572bdd36c48fa7d5173 Mon Sep 17 00:00:00 2001 From: David Garvey Date: Mon, 20 Feb 2023 11:33:40 +0100 Subject: [PATCH 18/19] show test log --- .github/workflows/tyk-demo-tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/tyk-demo-tests.yml b/.github/workflows/tyk-demo-tests.yml index 64036ac4..b4dcd89e 100644 --- a/.github/workflows/tyk-demo-tests.yml +++ b/.github/workflows/tyk-demo-tests.yml @@ -33,4 +33,7 @@ jobs: - name: Show Bootstrap Log if: success() || failure() run: cat bootstrap.log + - name: Show Test Log + if: success() || failure() + run: cat test.log - run: echo "🍏 This job's status is ${{ job.status }}." From 8f27805ede9f74831573cfc955e648a8ebd8750b Mon Sep 17 00:00:00 2001 From: David Garvey Date: Mon, 20 Feb 2023 17:44:41 +0100 Subject: [PATCH 19/19] fix + tidy --- scripts/test-all.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/test-all.sh b/scripts/test-all.sh index 06e50ceb..b81c790e 100755 --- a/scripts/test-all.sh +++ b/scripts/test-all.sh @@ -31,8 +31,9 @@ else ./down.sh fi -# clear test result log file +# clear log files echo -n > test.log +echo -n > bootstrap.log declare -a result_names declare -a result_codes @@ -127,7 +128,6 @@ test_fail_count=0 test_skip_count=0 for i in "${!result_codes[@]}" do - result_print="" case ${result_codes[$i]} in 0) echo -e "${GREEN}Pass${NOCOLOUR} ${result_names[$i]} - Tests passed" @@ -145,7 +145,7 @@ do echo -e "${RED}Fail${NOCOLOUR} ${result_names[$i]} - Create failed" test_fail_count=$((test_fail_count+1));; 5) - echo -e "$(tput setaf 1)Fail${NOCOLOUR} ${result_names[$i]} - Remove failed" + echo -e "${RED}Fail${NOCOLOUR} ${result_names[$i]} - Remove failed" test_fail_count=$((test_fail_count+1));; *) echo "ERROR: Unexpected result code. Exiting." @@ -160,9 +160,9 @@ echo -e "${BLUE}Skip${NOCOLOUR}:$test_skip_count" echo -e "\nExit Status:" if [ $test_fail_count = 0 ]; then - echo "Failure count is 0, exiting with code 0" + echo "No failures detected, exiting with code 0" exit 0 else - echo "Failure count is not 0, exiting with code 1" + echo "Failures detected, exiting with code 1" exit 1 fi