diff --git a/tests/tests/template.txt b/tests/TEMPLATE.txt similarity index 100% rename from tests/tests/template.txt rename to tests/TEMPLATE.txt diff --git a/tests/docker-compose.yaml b/tests/docker-compose.yaml index 5952efe..57086b9 100644 --- a/tests/docker-compose.yaml +++ b/tests/docker-compose.yaml @@ -4,6 +4,8 @@ services: myapp: container_name: myapp image: myapptest + ports: + - "3000:3000" config: container_name: configmanager diff --git a/tests/runStressTests.sh b/tests/runStressTests.sh new file mode 100755 index 0000000..cb20c65 --- /dev/null +++ b/tests/runStressTests.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +# Build test images +docker build -f myappDockerfile -t myapptest ../myapp/ +docker build -f configmanagerDockerfile -t configmanagertest ../configmanager/ +docker build -f proxyDockerfile -t proxytest ../proxy/ + +# Delete possible container conflicts +docker rm -f myapp +docker rm -f configmanager +docker rm -f proxy + +# Start the application in demo mode +docker-compose up -d + +# Wait for docker-compose to be ready (checking the logs) +while :; do + status=`docker-compose logs | grep "wasm log: read new config"` + if [ "$status" == "" ]; then + sleep 1 # wait one second before checking again + else + break + fi +done + +# Give some time to Envoy to deploy the config +sleep 4 + +# Run all tests +for test_script in $(find ./stress -type f -name "*.sh") +do + echo "NOW RUNNING TEST: $test_script" + bash "$test_script" +done + +# Done! +echo "ALL TESTS COMPLETED" + +# Cleanup +docker-compose down + diff --git a/tests/runtests.sh b/tests/runTests.sh similarity index 100% rename from tests/runtests.sh rename to tests/runTests.sh diff --git a/tests/stress/10000-0.sh b/tests/stress/10000-0.sh new file mode 100644 index 0000000..d7f21bc --- /dev/null +++ b/tests/stress/10000-0.sh @@ -0,0 +1,62 @@ +# Time taken for 10000 requests, 1 injected decoy (replace) but 0 trigger (except for last one) + +# Configure decoys +config=' +{ + "filters": [ + { + "decoy": { + "key": "admin1234" + }, + "inject": { + "store": { + "inResponse": "/robots.txt", + "withVerb": "GET", + "as": "body", + "at": { + "method": "replace", + "property": "((.|\n)*)" + } + } + } + } + ] +} +' + +# connect to configmanager, update /data/cad-default.json +echo "$config" | docker exec -i configmanager sh -c 'cat > /data/cad-default.json' +# wait a few seconds for the proxy to read the new config +sleep 5 + + +# Start timing +start_time=$(date +%s.%N) + +# Temporary file for curl output +tempfile=$(uuidgen -r) + +# Do relevant action(s) +for ((i=1; i<=9999; i++)); do + curl -v http://localhost:8000/ >/dev/null 2>&1 +done +# Check in the 1000th iteration that the decoy is properly injected +curl -v http://localhost:8000/robots.txt >$tempfile 2>&1 + +# Check INJECTION (in $tempfile) +status=$(grep "admin1234" $tempfile) + +# Output result & time +if [ -z "$status" ]; then + echo -e "\033[0;31mFAIL\033[0m" +else + echo -e "\033[0;32mPASS\033[0m" +fi + +check_1_time=$(date +%s.%N) +execution_time=$(echo "$check_1_time - $start_time" | bc) +echo "Execution time: $execution_time seconds" + +# Cleanup +rm $tempfile + diff --git a/tests/tests/10000-1.sh b/tests/stress/10000-1.sh similarity index 100% rename from tests/tests/10000-1.sh rename to tests/stress/10000-1.sh diff --git a/tests/stress/10000-100.sh b/tests/stress/10000-100.sh new file mode 100644 index 0000000..7de538e --- /dev/null +++ b/tests/stress/10000-100.sh @@ -0,0 +1,83 @@ +# Time taken for 10000 requests, 100 injected decoy (replace) - each triggered 10 times + +# Configure decoys +element=' +{ + "decoy": { + "key": "somekey" + }, + "inject": { + "store": { + "inResponse": "/1", + "withVerb": "GET", + "as": "body", + "at": { + "method": "replace", + "property": "((.|\n)*)" + } + } + } +} +' + +# Create an array to store the modified elements +declare -a elements + +# Loop through numbers from 1 to 100 and replace /1 with / +for ((i=1; i<=100; i++)); do + modified_element=$(echo "$element" | sed "s/\/1/\/$i/") + elements+=("$modified_element") +done + +# Initialize the decoys variable +config="{ \"filters\": [" + +for ((i=0; i<${#elements[@]}; i++)); do + # Add a comma between elements except for the last one + if [ $i -eq $((${#elements[@]} - 1)) ]; then + config+="$(printf '%s' "${elements[$i]}")" + else + config+="$(printf '%s' "${elements[$i]}")," + fi +done + +config+="]}" + +# connect to configmanager, update /data/cad-default.json +echo "$config" | docker exec -i configmanager sh -c 'cat > /data/cad-default.json' +# wait a few seconds for the proxy to read the new config +sleep 5 + + +# Start timing +start_time=$(date +%s.%N) + +# Temporary file for curl output +tempfile=$(uuidgen -r) + +# Do relevant action(s) +# Query each decoy 100 times +for ((i=1; i<=100; i++)); do + for ((j=1; j<=99; j++)); do + curl -v "http://localhost:8000/$i" >/dev/null 2>&1 + done + # on the 100th time, check that the decoy was properly injected + curl -v "http://localhost:8000/$i" >$tempfile 2>&1 + # Check INJECTION (in $tempfile) + status=$(grep "somekey" $tempfile) + + # Output result & time + if [ -z "$status" ]; then + echo -e "\033[0;31mFAIL\033[0m" + else + echo -e "\033[0;32mPASS\033[0m" + fi +done + +check_1_time=$(date +%s.%N) +execution_time=$(echo "$check_1_time - $start_time" | bc) +echo "Execution time: $execution_time seconds" + +# Cleanup +rm $tempfile + diff --git a/tests/stress/10000-direct.sh b/tests/stress/10000-direct.sh new file mode 100644 index 0000000..275b812 --- /dev/null +++ b/tests/stress/10000-direct.sh @@ -0,0 +1,32 @@ +# Time taken for 10000 requests sent directly to myapp (e.g. not through Envoy) + +# Start timing +start_time=$(date +%s.%N) + +# Temporary file for curl output +tempfile=$(uuidgen -r) + +# Do relevant action(s) +for ((i=1; i<=9999; i++)); do + curl -v http://localhost:3000/ >/dev/null 2>&1 +done +# Check in the 1000th iteration that myapp is properly running +curl -v http://localhost:3000/ >$tempfile 2>&1 + +# Check INJECTION (in $tempfile) +status=$(grep "Welcome" $tempfile) + +# Output result & time +if [ -z "$status" ]; then + echo -e "\033[0;31mFAIL\033[0m" +else + echo -e "\033[0;32mPASS\033[0m" +fi + +check_1_time=$(date +%s.%N) +execution_time=$(echo "$check_1_time - $start_time" | bc) +echo "Execution time: $execution_time seconds" + +# Cleanup +rm $tempfile +