Skip to content

Commit fc008df

Browse files
bastelfreakekohl
andcommitted
curl_command: Add support for --user option
Co-authored-by: Ewoud Kohl van Wijngaarden <ewoud@kohlvanwijngaarden.nl>
1 parent 78798c8 commit fc008df

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,15 @@ Some [Serverspec](https://serverspec.org/) extensions are shipped and enabled by
280280
Often you want to test some service that exposes things over HTTP.
281281
Instead of using [`command("curl …")`](https://serverspec.org/resource_types.html#command) you can use `curl_command(…)` which behaves like a Serverspec `command` but adds matchers for the HTTP response code and the response body.
282282

283+
Various parameters map to curl CLI options.
284+
The following parameters are supported (they map directly to the curl CLI options, check the curl manpage for details):
285+
286+
* `headers` ( hash of header options
287+
* `user`
288+
* `cacert`
289+
* `cert`
290+
* `key`
291+
283292
```ruby
284293
describe curl_command("http://localhost:8080/api/ping") do
285294
its(:response_code) { is_expected.to eq(200) }
@@ -290,4 +299,9 @@ describe curl_command('http://localhost:8080/api/status', headers: { 'Accept' =>
290299
its(:response_code) { is_expected.to eq(200) }
291300
its(:body_as_json) { is_expected.to eq({'status': 'ok'}) }
292301
end
302+
303+
describe curl_command('http://localhost:8080/api/status', user: 'foo:bar', cacert: '/tmp/ca.pem', cert: '/tmp/baz.pem', key: '/tmp/baz.key') do
304+
its(:response_code) { is_expected.to eq(200) }
305+
its(:body_as_json) { is_expected.to eq({'status': 'ok'}) }
306+
end
293307
```

lib/voxpupuli/acceptance/serverspec_extensions/curl_command.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def curl_command
3333

3434
@options.each do |option, value|
3535
case option
36-
when :cacert, :cert, :key
36+
when :cacert, :cert, :key, :user
3737
command += " --#{option} '#{value}'"
3838
when :headers
3939
value.each do |header, header_value|

0 commit comments

Comments
 (0)