Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
431253f
Create a temp dir that works on Linux and Darwin
foobaar Sep 13, 2016
5840ad7
Allow testing redirect return codes
Dec 11, 2017
137b921
Add functions to allow debugging requests
Dec 11, 2017
7f2d7d8
Merge remote-tracking branch 'foobaar/master' into merge_version
ben-cnv Jul 6, 2018
8c12bf9
Add authentication support (through curl -u option)
benjamin-cartereau Jul 10, 2018
c0bef90
Update Readme with credential function
benjamin-cartereau Jul 10, 2018
f002d6f
Update Readme with credential function
benjamin-cartereau Jul 10, 2018
76e667f
Add smoke_no_credentials to reset credentials and when smoke_assert_c…
benjamin-cartereau Jul 26, 2018
16cfbbb
Add an assertion to check that a server is not responding : smoke_ass…
benjamin-cartereau Jul 27, 2018
760581d
smoke_no_credentials does not reset USERNAME & PASSWORD + _smoke_prin…
benjamin-cartereau Jul 27, 2018
6520271
in smoke_assert_code*, if no response code, display 'no response'
benjamin-cartereau Jul 27, 2018
3ece134
Add new function 'smoke_custom_header' to add a custom header (can be…
benjamin-cartereau Aug 1, 2018
158e2d6
replace --quiet option in grep by -q
websid Jun 14, 2019
8932ae4
Merge remote-tracking branch 'websid/master'
benjamin-cartereau Jul 3, 2019
ae5ce61
Added CORS: Options + Origin support. Show Verb on report. Documentat…
pjmolina Nov 6, 2019
c25df6a
Merge remote-tracking branch 'asm89/master'
benjamin-cartereau Oct 21, 2020
3515f30
Merge remote-tracking branch 'pjmolina/feature/cors-check'
benjamin-cartereau Oct 21, 2020
b4a5706
Add an option to set proxy and noproxy options
benjamin-cartereau Oct 21, 2020
06677b7
Transform proxy and noproxy vars as array to prevent escape/expansion…
benjamin-cartereau Oct 22, 2020
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
38 changes: 19 additions & 19 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
Copyright (c) 2013 Alexander <iam.asm89@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Copyright (c) 2013 Alexander <iam.asm89@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
124 changes: 101 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Features:
- Response body checks
- Response code checks
- Response header checks
- GET/POST on endpoints
- GET/POST/OPTIONS on endpoints
- ORIGIN support for testing CORS responses
- CSRF tokens
- Reporting and sane exit codes

Expand All @@ -33,7 +34,7 @@ Running:

```bash
$ ./smoke-google
> http://google.com/
> GET http://google.com/
[ OK ] 2xx Response code
[ OK ] Body contains "search"
OK (2/2)
Expand Down Expand Up @@ -78,6 +79,25 @@ The minimal smoke test will check if a URL returns with a 200 response code:
smoke_url_ok "http://google.com"
```

It is also possible to check for other response codes explicitly:

```bash
smoke_url "http://google.com/doesnotexist"
smoke_assert_code 404
```

### GET a URL and check for redirects

In order to check for redirects, you must call `smoke_no_follow` before calling `smoke_url`:

```bash
smoke_no_follow
smoke_url "http://google.com"
smoke_assert_code 302
```

You can follow redirects again by calling `smoke_follow`

### POST a URL and check the response code

A more advanced smoke test will POST data to a URL. Such a test can be used to
Expand Down Expand Up @@ -110,6 +130,15 @@ By checking response headers, you can make sure to get the correct content type:
smoke_assert_headers "Content-Type: text/html; charset=utf-8"
```

### Checking the server is not responding

In order to check a server is not responding, you can use `smoke_assert_no_response` after calling `smoke_url`:

```bash
smoke_url "http://myserver.com:5000/"
smoke_assert_no_response
```

### Configuring a base URL

It is possible to setup a base URL that is prepended for each URL that is
Expand All @@ -125,13 +154,13 @@ smoke_url_ok "/login"

If the server requires a certain host header to be set, override the host from the URL with

```
```bash
smoke_host "example.org"
```

To un-override, set it empty:

```
```bash
smoke_host ""
```

Expand All @@ -146,6 +175,22 @@ smoke_header "X-Forwarded-Proto: https"

Existing custom headers can be unset with `remove_smoke_headers`.

### Checking CORS is enabled for a certain Origin

First of all, set the origin header with:

```
smoke_origin "https://acme.corp"
```

Then test for CORS headers using:

```
smoke_url_cors "https://api.com/endpoint"
smoke_assert_headers "Access-Control-Allow-Credentials: true"
smoke_assert_headers "Access-Control-Allow-Origin: https://acme.corp"
```

### CSRF tokens

Web applications that are protected with CSRF tokens will need to extract a
Expand Down Expand Up @@ -185,6 +230,33 @@ smoke_response_body # raw body (html/json/...)
smoke_response_headers # list of headers
```

### Authentication

If the server requires an authentication (for example : HTTP Basic authentication), you must call `smoke_credentials` before calling `smoke_url`.
If you simply specify the user name, you will be prompted for a password.

```bash
smoke_credentials "username" "password"
smoke_url "http://secured-website.com"
```

To un-set credentials, call `smoke_no_credentials` :

```bash
smoke_no_credentials
```

### Debugging

In order to debug your requests, call `smoke_debug` before calling `smoke_url`:

```bash
smoke_debug
smoke_url_ok "http://google.com"
```

You can turn off debugging by calling `smoke_no_debug`

Advanced example
----------------

Expand Down Expand Up @@ -229,22 +301,28 @@ smoke_report
API
---

| function | description |
|---------------------------------|------------------------------------------------------|
|`smoke_assert_body <string>` | assert that the body contains `<string>` |
|`smoke_assert_code <code>` | assert that there was a `<code>` response code |
|`smoke_assert_code_ok` | assert that there was a `2xx` response code |
|`smoke_assert_headers <string>` | assert that the headers contain `<string>` |
|`smoke_csrf <token>` | set the csrf token to use in POST requests |
|`smoke_form <url> <datafile>` | POST data on url |
|`smoke_form_ok <url> <datafile>` | POST data on url and check for a `2xx` response code |
|`smoke_report` | prints the report and exits |
|`smoke_response_body` | body of the last response |
|`smoke_response_code` | code of the last response |
|`smoke_response_headers` | headers of the last response |
|`smoke_url <url>` | GET a url |
|`smoke_url_ok <url>` | GET a url and check for a `2xx` response code |
|`smoke_url_prefix <prefix>` | set the prefix to use for every url (e.g. domain) |
|`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 |
| function | description |
|-----------------------------------------|------------------------------------------------------------------------------------------------|
|`smoke_assert_body <string>` | assert that the body contains `<string>` |
|`smoke_assert_code <code>` | assert that there was a `<code>` response code |
|`smoke_assert_code_ok` | assert that there was a `2xx` response code |
|`smoke_assert_headers <string>` | assert that the headers contain `<string>` |
|`smoke_assert_no_response` | assert that the server is not responding |
|`smoke_credentials <string> [<string>]` | set the credentials to use : login (and password). If password is not set, it will be prompted |
|`smoke_csrf <token>` | set the csrf token to use in POST requests |
|`smoke_form <url> <datafile>` | POST data on url |
|`smoke_form_ok <url> <datafile>` | POST data on url and check for a `2xx` response code |
|`smoke_origin <origin>` | set the `Origin` header |
|`smoke_proxy <proxy>` | set the HTTP proxy to use [protocol://][user:password@]proxyhost[:port] |
|`smoke_no_proxy [<no-proxy-list>]` | Comma-separated list of hosts which do not use a proxy |
|`smoke_report` | prints the report and exits |
|`smoke_response_body` | body of the last response |
|`smoke_response_code` | code of the last response |
|`smoke_response_headers` | headers of the last response |
|`smoke_url <url>` | GET a url |
|`smoke_url_ok <url>` | GET a url and check for a `2xx` response code |
|`smoke_url_prefix <prefix>` | set the prefix to use for every url (e.g. domain) |
|`smoke_host <host>` | set the host header to use |
|`smoke_header <header>` | set additional request header (in the form `Key: value`) |
|`remove_smoke_headers` | remove all headers |
|`smoke_tcp_ok <host> <port>` | open a tcp connection and check for a `Connected` response |
Loading