Skip to content

Commit

Permalink
test: support URL encoded values
Browse files Browse the repository at this point in the history
  • Loading branch information
ludovicm67 committed Jun 11, 2024
1 parent a7bfd3f commit 7b4aa14
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion test/app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ const cleanupHeaderValue = (
if (newValue.length > 256) {
return defaultValue;
}
return newValue;

// Support URL encoded values
return decodeURIComponent(newValue);
};

// Fetch values from environment variables
Expand Down
22 changes: 22 additions & 0 deletions test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,28 @@ if [ "${req5}" -ne "${req8}" ]; then
error "should be the same"
fi

# Just try with xkey with slashes
req1=$(curl -sL -X POST --data '{"foo": "bar"}' http://localhost:8081/x-header/http://example.com/custom/path | jq .time)
req2=$(curl -sL -X POST --data '{"foo": "bar"}' http://localhost:8081/x-header/http://example.com/custom/path | jq .time)
req3=$(curl -sL -X POST --data '{"foo": "bar"}' http://localhost:8081/x-header/http%3A%2F%2Fexample.com%2Fcustom%2Fpath | jq .time)
req4=$(curl -sL -X POST --data '{"foo": "bar"}' http://localhost:8081/x-header/http%3A%2F%2Fexample.com%2Fcustom%2Fpath | jq .time)
if [ "${req1}" -ne "${req2}" ]; then
error "should be the same - url with slashes"
fi
if [ "${req3}" -ne "${req4}" ]; then
error "should be the same - encoded url with slashes"
fi
# Clear cache
curl -sL -X PURGE -H 'xkey: http://example.com/custom/path' http://localhost:8081/ >/dev/null
req5=$(curl -sL -X POST --data '{"foo": "bar"}' http://localhost:8081/x-header/http://example.com/custom/path | jq .time)
req6=$(curl -sL -X POST --data '{"foo": "bar"}' http://localhost:8081/x-header/http%3A%2F%2Fexample.com%2Fcustom%2Fpath | jq .time)
if [ "${req1}" -eq "${req5}" ]; then
error "should not be the same - url with slashes"
fi
if [ "${req3}" -eq "${req6}" ]; then
error "should not be the same - encoded url with slashes"
fi

# If we are at this point, no test failed
info "All tests passed :)"
docker compose down
Expand Down

0 comments on commit 7b4aa14

Please sign in to comment.