From 5ea1b838a7c211a34aeb66c88585fcd473485c53 Mon Sep 17 00:00:00 2001 From: Jay Caines-Gooby Date: Mon, 4 Jul 2022 19:34:40 +0100 Subject: [PATCH] Add a curl passthrough option -o This lets us send custom switches to curl like -k to ignore invalid certificates. Call ttfb like this: ttfb -o "-k" https://self-signed.badssl.com --- tests/tests.bats | 12 +++++++++++- ttfb | 8 +++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/tests/tests.bats b/tests/tests.bats index b414598..18b7b0f 100644 --- a/tests/tests.bats +++ b/tests/tests.bats @@ -26,6 +26,7 @@ } @test "-l logs to specific file" { + # skip rundir="$(mktemp -d)" logdir="$(mktemp -d)" pwd="$PWD" @@ -35,6 +36,7 @@ } @test "-l exits if the path the custom log file doesn't exist" { + # skip rundir="$(mktemp -d)" logdir="$(mktemp -d)" rmdir "$logdir" @@ -110,7 +112,6 @@ @test "-d logs multiple requests to multiple urls to multiple custom log files" { # skip rundir="$(mktemp -d)" - echo $rundir pwd="$PWD" cd "$rundir" && run "$pwd/ttfb" -n2 -l "$rundir/custom.log" example.com example.com/hello-world [ $status -eq 0 ] @@ -119,3 +120,12 @@ [ $(grep " 200 OK" "$rundir/example_com-custom.log" | wc -l) -eq 2 ] [ $(grep " 404 Not Found" "$rundir/example_com_hello_world-custom.log" | wc -l) -eq 2 ] } + +@test "pass custom curl options via our -o option" { + # This test passes -k to curl, so it can successfully + # call https://self-signed.badssl.com which has a self-signed certificate + # which would normally result in a fail + # skip + run "$pwd/ttfb" -o "-k" https://self-signed.badssl.com + [[ "$output" != "0" ]] +} diff --git a/ttfb b/ttfb index 41fb362..99a8aa7 100755 --- a/ttfb +++ b/ttfb @@ -100,13 +100,15 @@ DEBUG="" LOG="" NUM_REQUESTS=0 VERBOSE=0 +options=() -while getopts ":n:dl:v" OPTION +while getopts "dl:n:o:v" OPTION do case $OPTION in d) DEBUG=1 ;; l) LOG="$OPTARG" ;; n) NUM_REQUESTS=$OPTARG ;; + o) options+=("$(echo $OPTARG | xargs)") ;; v) VERBOSE=1 ;; \?) show_usage exit 1 @@ -143,16 +145,12 @@ LOG=$(basename "$LOG") DEBUG=${DEBUG:-0} -options=() options+=(-o /dev/null) options+=(-s) options+=(-L) options+=($HTTP_VERSION) options+=(-H 'Cache-Control: no-cache') options+=(-w 'echo DNS lookup: %{time_namelookup} TLS handshake: %{time_appconnect} TTFB including connection: %{time_starttransfer} TTFB: $(echo %{time_starttransfer} - %{time_appconnect} | bc) Total time: %{time_total} \n') -if [ $DEBUG -eq 1 ]; then - options+=(-D "${LOG_DIRECTORY}/${LOG}") -fi for URL in $URLS; do