Skip to content

Commit

Permalink
adding stress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
valvolt committed Apr 6, 2024
1 parent 5a332f6 commit 5728040
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 0 deletions.
File renamed without changes.
2 changes: 2 additions & 0 deletions tests/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ services:
myapp:
container_name: myapp
image: myapptest
ports:
- "3000:3000"

config:
container_name: configmanager
Expand Down
41 changes: 41 additions & 0 deletions tests/runStressTests.sh
Original file line number Diff line number Diff line change
@@ -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

File renamed without changes.
62 changes: 62 additions & 0 deletions tests/stress/10000-0.sh
Original file line number Diff line number Diff line change
@@ -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

File renamed without changes.
83 changes: 83 additions & 0 deletions tests/stress/10000-100.sh
Original file line number Diff line number Diff line change
@@ -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 /<number>
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

32 changes: 32 additions & 0 deletions tests/stress/10000-direct.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5728040

Please sign in to comment.