Skip to content

Commit 28dc8b6

Browse files
committed
Return environment variables in response body if requested... via an environment variable!
Issue mendhak#43
1 parent d5dc1bc commit 28dc8b6

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ app.all('*', (req, res) => {
5151
echo.clientCertificate = req.socket.getPeerCertificate();
5252
}
5353

54+
if(process.env.ECHO_INCLUDE_ENV_VARS){
55+
echo.env = process.env;
56+
}
5457

5558
if(req.is('application/json')){
5659
echo.json = JSON.parse(req.body)

tests.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,38 @@ fi
362362
message " Stop containers "
363363
docker stop http-echo-tests
364364

365+
message " Check that environment variables returned in response if enabled"
366+
docker run -d --rm -e ECHO_INCLUDE_ENV_VARS=1 --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo
367+
sleep 5
368+
RESPONSE_BODY="$(curl -sk https://localhost:8443/ | jq -r '.env.ECHO_INCLUDE_ENV_VARS')"
369+
370+
if [ "$RESPONSE_BODY" == "1" ]
371+
then
372+
passed "Environment variables present in the output"
373+
else
374+
failed "Client certificate details found in output? ${RESPONSE_BODY}"
375+
exit 1
376+
fi
377+
378+
message " Stop containers "
379+
docker stop http-echo-tests
380+
381+
message " Check that environment variables are not present in response by default"
382+
docker run -d --rm --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo
383+
sleep 5
384+
RESPONSE_BODY_ENV_CHECK="$(curl -sk https://localhost:8443/ | jq 'has("env")')"
385+
386+
if [ "$RESPONSE_BODY_ENV_CHECK" == "false" ]
387+
then
388+
passed "Environment variables not present in the output by default"
389+
else
390+
failed "Environment variables found in output?"
391+
exit 1
392+
fi
393+
394+
message " Stop containers "
395+
docker stop http-echo-tests
396+
365397
popd
366398
rm -rf testarea
367399
message "DONE"

0 commit comments

Comments
 (0)