mirror of
https://github.com/inspec/inspec
synced 2024-11-10 15:14:23 +00:00
docs: Enhance http
resource documentation (#2715)
* Simplify `http` resource example Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>
This commit is contained in:
parent
0982ed53ba
commit
0240ab4f6e
1 changed files with 116 additions and 20 deletions
|
@ -33,27 +33,9 @@ where
|
|||
|
||||
<br>
|
||||
|
||||
## Local vs. Remote
|
||||
## Example
|
||||
|
||||
Beginning with InSpec 1.41, you can enable the ability to have the HTTP test execute on the remote target:
|
||||
|
||||
describe http('http://www.example.com', enable_remote_worker: true) do
|
||||
its('body') { should cmp 'awesome' }
|
||||
end
|
||||
|
||||
In InSpec 2.0, the HTTP test will automatically execute remotely whenever InSpec is testing a remote node.
|
||||
|
||||
<br>
|
||||
|
||||
## Properties
|
||||
|
||||
body, headers, http_method, status,
|
||||
|
||||
<br>
|
||||
|
||||
## Property Examples
|
||||
|
||||
The following examples show how to use this InSpec audit resource.
|
||||
The following examples show how to use this InSpec audit resource. An `http` resource block declares the configuration settings to be tested:
|
||||
|
||||
### Simple http test
|
||||
|
||||
|
@ -78,6 +60,114 @@ For example, a service is listening on default http port can be tested like this
|
|||
|
||||
<br>
|
||||
|
||||
## Local vs. Remote
|
||||
|
||||
Beginning with InSpec 1.41, you can enable the ability to have the HTTP test execute on the remote target:
|
||||
|
||||
describe http('http://www.example.com', enable_remote_worker: true) do
|
||||
its('body') { should cmp 'awesome' }
|
||||
end
|
||||
|
||||
In InSpec 2.0, the HTTP test will automatically execute remotely whenever InSpec is testing a remote node.
|
||||
|
||||
<br>
|
||||
|
||||
## Parameters
|
||||
|
||||
* `url`, `auth`, `params`, `method`, `headers`, `data`, `open_timeout`, `read_timeout`, `ssl_verify`
|
||||
|
||||
## Parameter Examples
|
||||
|
||||
### url
|
||||
|
||||
`('url')` is the url to test.
|
||||
|
||||
describe http('http://localhost:8080/ping') do
|
||||
...
|
||||
end
|
||||
|
||||
### auth
|
||||
|
||||
`auth: { user: 'user', pass: 'test' }` may be specified for basic auth request.
|
||||
|
||||
describe http('http://localhost:8080/ping',
|
||||
auth: {user: 'user', pass: 'test'}) do
|
||||
...
|
||||
end
|
||||
|
||||
### params
|
||||
|
||||
`{params}` may be specified for http request parameters.
|
||||
|
||||
describe http('http://localhost:8080/ping',
|
||||
params: {format: 'html'}) do
|
||||
...
|
||||
end
|
||||
|
||||
### method
|
||||
|
||||
`'method'` may be specified for http request method (default to 'GET').
|
||||
|
||||
describe http('http://localhost:8080/ping',
|
||||
method: 'POST') do
|
||||
...
|
||||
end
|
||||
|
||||
### headers
|
||||
|
||||
`{headers}` may be specified for http request headers.
|
||||
|
||||
describe http('http://localhost:8080/ping',
|
||||
headers: {'Content-Type' => 'application/json'}) do
|
||||
...
|
||||
end
|
||||
|
||||
### data
|
||||
|
||||
`data` may be specified for http request body.
|
||||
|
||||
describe http('http://localhost:8080/ping',
|
||||
data: '{"data":{"a":"1","b":"five"}}') do
|
||||
...
|
||||
end
|
||||
|
||||
### open_timeout
|
||||
|
||||
`open_timeout` may be specified for a timeout for opening connections (default to 60).
|
||||
|
||||
describe('http://localhost:8080/ping',
|
||||
open_timeout: '90') do
|
||||
...
|
||||
end
|
||||
|
||||
### read_timeout
|
||||
|
||||
`read_timeout` may be specified for a timeout for reading connections (default to 60).
|
||||
|
||||
describe('http://localhost:8080/ping',
|
||||
read_timeout: '90') do
|
||||
...
|
||||
end
|
||||
|
||||
### ssl_verify
|
||||
|
||||
`ssl_verify` may be specified to enable or disable verification of SSL certificates (default to `true`).
|
||||
|
||||
describe('http://localhost:8080/ping',
|
||||
ssl_verify: 'true') do
|
||||
...
|
||||
end
|
||||
|
||||
<br>
|
||||
|
||||
## Properties
|
||||
|
||||
* `body`, `headers`, `http_method`, `status`,
|
||||
|
||||
<br>
|
||||
|
||||
## Property Examples
|
||||
|
||||
### body
|
||||
|
||||
The `body` matcher tests body content of http response:
|
||||
|
@ -99,3 +189,9 @@ Individual headers can be tested via:
|
|||
The `status` matcher tests status of the http response:
|
||||
|
||||
its('status') { should eq 200 }
|
||||
|
||||
<br>
|
||||
|
||||
## Matchers
|
||||
|
||||
For a full list of available matchers, please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
|
Loading…
Reference in a new issue