Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,24 @@ smoke_header "X-Forwarded-Proto: https"

Existing custom headers can be unset with `remove_smoke_headers`.

### Basic Auth

Basic Auth credentials can be passed using: `smoke_basic_auth <user> <pass>`
To unset credentials pass no arguments or empty ones.

Full usage example:

```bash
smoke_url "${API}/health"
smoke_assert_code 401

smoke_basic_auth user1 pass1 # set credentials
smoke_url_ok "${API}/health" # call with credentials
smoke_assert_code 200

smoke_basic_auth # unset
```

### CSRF tokens

Web applications that are protected with CSRF tokens will need to extract a
Expand Down Expand Up @@ -248,3 +266,4 @@ API
|`smoke_host <host>` | set the host header to use |
|`smoke_header <header>` | set additional request header |
|`smoke_tcp_ok <host> <port>` | open a tcp connection and check for a `Connected` response |
|`smoke_basic_auth <user> <pass>` | set Basic Auth credentials |
18 changes: 17 additions & 1 deletion smoke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ SMOKE_HEADERS=()

## "Public API"

smoke_basic_auth() {
SMOKE_BASIC_AUTH_USER="$1"
SMOKE_BASIC_AUTH_PASSWORD="$2"
}

smoke_csrf() {
SMOKE_CSRF_TOKEN="$1"
}
Expand Down Expand Up @@ -189,6 +194,10 @@ _curl() {
opt+=(-H "$header")
done
fi
if [[ -n "$SMOKE_BASIC_AUTH_USER" ]]
then
opt+=(-u "$SMOKE_BASIC_AUTH_USER:$SMOKE_BASIC_AUTH_PASSWORD")
fi

curl "${opt[@]}" "$@" > $SMOKE_CURL_BODY
}
Expand Down Expand Up @@ -257,6 +266,13 @@ _smoke_print_success() {
}

_smoke_print_url() {
TEXT="$1"
TEXT="$@"
echo "> $TEXT"

if [[ -n "$SMOKE_BASIC_AUTH_USER" ]]
then
echo "> $${bold}${TEXT}${normal} with BasicAuth ${bold}${SMOKE_BASIC_AUTH_USER}:****${normal}"
else
echo "> ${bold}${TEXT}${normal}"
fi
}