|
| 1 | +set -xeEo pipefail |
| 2 | + |
| 3 | +source CI/tests/common.sh |
| 4 | + |
| 5 | +trap error ERR |
| 6 | +trap finish EXIT |
| 7 | +# port mapping has been configured in kind-config.yml |
| 8 | +SERVICE_URL=http://localhost:8888 |
| 9 | +PAYLOAD_GET_1="{ \ |
| 10 | + \"status\":\"internal server error\" \ |
| 11 | +}" |
| 12 | +STATUS_CODE_GET_1=500 |
| 13 | + |
| 14 | +PAYLOAD_PATCH_1="resource patched" |
| 15 | +STATUS_CODE_PATCH_1=201 |
| 16 | + |
| 17 | +PAYLOAD_POST_1="{ \ |
| 18 | + \"status\": \"unauthorized\" \ |
| 19 | +}" |
| 20 | +STATUS_CODE_POST_1=401 |
| 21 | + |
| 22 | +PAYLOAD_GET_2="{ \ |
| 23 | + \"status\":\"resource created\" \ |
| 24 | +}" |
| 25 | +STATUS_CODE_GET_2=201 |
| 26 | + |
| 27 | +PAYLOAD_PATCH_2="bad request" |
| 28 | +STATUS_CODE_PATCH_2=400 |
| 29 | + |
| 30 | +PAYLOAD_POST_2="not found" |
| 31 | +STATUS_CODE_POST_2=404 |
| 32 | + |
| 33 | +JSON_MIME="application/json" |
| 34 | +TEXT_MIME="text/plain" |
| 35 | + |
| 36 | +function functional_test_service_hijacking { |
| 37 | + |
| 38 | + export scenario_type="service_hijacking" |
| 39 | + export scenario_file="scenarios/kube/service_hijacking.yaml" |
| 40 | + export post_config="" |
| 41 | + envsubst < CI/config/common_test_config.yaml > CI/config/service_hijacking.yaml |
| 42 | + python3 -m coverage run -a run_kraken.py -c CI/config/service_hijacking.yaml > /dev/null 2>&1 & |
| 43 | + PID=$! |
| 44 | + while [ `curl -X GET -s -o /dev/null -I -w "%{http_code}" $SERVICE_URL/list/index.php` == 404 ]; do echo "waiting scenario to kick in."; sleep 1; done; |
| 45 | + OUT_GET="`curl -X GET -s $SERVICE_URL/list/index.php`" |
| 46 | + OUT_CONTENT=`curl -X GET -s -o /dev/null -I -w "%{content_type}" $SERVICE_URL/list/index.php` |
| 47 | + OUT_STATUS_CODE=`curl -X GET -s -o /dev/null -I -w "%{http_code}" $SERVICE_URL/list/index.php` |
| 48 | + [ "${PAYLOAD_GET_1//[$'\t\r\n ']}" == "${OUT_GET//[$'\t\r\n ']}" ] && echo "Step 1 GET Payload OK" || (echo "Payload did not match. Test failed." && exit 1) |
| 49 | + [ "$OUT_STATUS_CODE" == "$STATUS_CODE_GET_1" ] && echo "Step 1 GET Status Code OK" || (echo " Step 1 GET status code did not match. Test failed." && exit 1) |
| 50 | + [ "$OUT_CONTENT" == "$JSON_MIME" ] && echo "Step 1 GET MIME OK" || (echo " Step 1 GET MIME did not match. Test failed." && exit 1) |
| 51 | + |
| 52 | + OUT_POST="`curl -s -X POST $SERVICE_URL/list/index.php`" |
| 53 | + OUT_STATUS_CODE=`curl -X POST -s -o /dev/null -I -w "%{http_code}" $SERVICE_URL/list/index.php` |
| 54 | + OUT_CONTENT=`curl -X POST -s -o /dev/null -I -w "%{content_type}" $SERVICE_URL/list/index.php` |
| 55 | + [ "${PAYLOAD_POST_1//[$'\t\r\n ']}" == "${OUT_POST//[$'\t\r\n ']}" ] && echo "Step 1 POST Payload OK" || (echo "Payload did not match. Test failed." && exit 1) |
| 56 | + [ "$OUT_STATUS_CODE" == "$STATUS_CODE_POST_1" ] && echo "Step 1 POST Status Code OK" || (echo "Step 1 POST status code did not match. Test failed." && exit 1) |
| 57 | + [ "$OUT_CONTENT" == "$JSON_MIME" ] && echo "Step 1 POST MIME OK" || (echo " Step 1 POST MIME did not match. Test failed." && exit 1) |
| 58 | + |
| 59 | + OUT_PATCH="`curl -s -X PATCH $SERVICE_URL/patch`" |
| 60 | + OUT_STATUS_CODE=`curl -X PATCH -s -o /dev/null -I -w "%{http_code}" $SERVICE_URL/patch` |
| 61 | + OUT_CONTENT=`curl -X PATCH -s -o /dev/null -I -w "%{content_type}" $SERVICE_URL/patch` |
| 62 | + [ "${PAYLOAD_PATCH_1//[$'\t\r\n ']}" == "${OUT_PATCH//[$'\t\r\n ']}" ] && echo "Step 1 PATCH Payload OK" || (echo "Payload did not match. Test failed." && exit 1) |
| 63 | + [ "$OUT_STATUS_CODE" == "$STATUS_CODE_PATCH_1" ] && echo "Step 1 PATCH Status Code OK" || (echo "Step 1 PATCH status code did not match. Test failed." && exit 1) |
| 64 | + [ "$OUT_CONTENT" == "$TEXT_MIME" ] && echo "Step 1 PATCH MIME OK" || (echo " Step 1 PATCH MIME did not match. Test failed." && exit 1) |
| 65 | + # wait for the next step |
| 66 | + sleep 16 |
| 67 | + |
| 68 | + OUT_GET="`curl -X GET -s $SERVICE_URL/list/index.php`" |
| 69 | + OUT_CONTENT=`curl -X GET -s -o /dev/null -I -w "%{content_type}" $SERVICE_URL/list/index.php` |
| 70 | + OUT_STATUS_CODE=`curl -X GET -s -o /dev/null -I -w "%{http_code}" $SERVICE_URL/list/index.php` |
| 71 | + [ "${PAYLOAD_GET_2//[$'\t\r\n ']}" == "${OUT_GET//[$'\t\r\n ']}" ] && echo "Step 2 GET Payload OK" || (echo "Step 2 GET Payload did not match. Test failed." && exit 1) |
| 72 | + [ "$OUT_STATUS_CODE" == "$STATUS_CODE_GET_2" ] && echo "Step 2 GET Status Code OK" || (echo "Step 2 GET status code did not match. Test failed." && exit 1) |
| 73 | + [ "$OUT_CONTENT" == "$JSON_MIME" ] && echo "Step 2 GET MIME OK" || (echo " Step 2 GET MIME did not match. Test failed." && exit 1) |
| 74 | + |
| 75 | + OUT_POST="`curl -s -X POST $SERVICE_URL/list/index.php`" |
| 76 | + OUT_CONTENT=`curl -X POST -s -o /dev/null -I -w "%{content_type}" $SERVICE_URL/list/index.php` |
| 77 | + OUT_STATUS_CODE=`curl -X POST -s -o /dev/null -I -w "%{http_code}" $SERVICE_URL/list/index.php` |
| 78 | + [ "${PAYLOAD_POST_2//[$'\t\r\n ']}" == "${OUT_POST//[$'\t\r\n ']}" ] && echo "Step 2 POST Payload OK" || (echo "Step 2 POST Payload did not match. Test failed." && exit 1) |
| 79 | + [ "$OUT_STATUS_CODE" == "$STATUS_CODE_POST_2" ] && echo "Step 2 POST Status Code OK" || (echo "Step 2 POST status code did not match. Test failed." && exit 1) |
| 80 | + [ "$OUT_CONTENT" == "$TEXT_MIME" ] && echo "Step 2 POST MIME OK" || (echo " Step 2 POST MIME did not match. Test failed." && exit 1) |
| 81 | + |
| 82 | + OUT_PATCH="`curl -s -X PATCH $SERVICE_URL/patch`" |
| 83 | + OUT_CONTENT=`curl -X PATCH -s -o /dev/null -I -w "%{content_type}" $SERVICE_URL/patch` |
| 84 | + OUT_STATUS_CODE=`curl -X PATCH -s -o /dev/null -I -w "%{http_code}" $SERVICE_URL/patch` |
| 85 | + [ "${PAYLOAD_PATCH_2//[$'\t\r\n ']}" == "${OUT_PATCH//[$'\t\r\n ']}" ] && echo "Step 2 PATCH Payload OK" || (echo "Step 2 PATCH Payload did not match. Test failed." && exit 1) |
| 86 | + [ "$OUT_STATUS_CODE" == "$STATUS_CODE_PATCH_2" ] && echo "Step 2 PATCH Status Code OK" || (echo "Step 2 PATCH status code did not match. Test failed." && exit 1) |
| 87 | + [ "$OUT_CONTENT" == "$TEXT_MIME" ] && echo "Step 2 PATCH MIME OK" || (echo " Step 2 PATCH MIME did not match. Test failed." && exit 1) |
| 88 | + wait $PID |
| 89 | + echo "Service Hijacking Chaos test: Success" |
| 90 | +} |
| 91 | + |
| 92 | + |
| 93 | +functional_test_service_hijacking |
0 commit comments