mirror of
https://github.com/inspec/inspec
synced 2024-11-27 15:10:44 +00:00
58585e3455
Signed-off-by: Christoph Hartmann <chris@lollyrock.com>
54 lines
2.1 KiB
Ruby
54 lines
2.1 KiB
Ruby
# encoding: utf-8
|
|
# author: Guilhem Lettron
|
|
|
|
require 'helper'
|
|
require 'inspec/resource'
|
|
|
|
describe 'Inspec::Resources::Http' do
|
|
it 'verify simple http' do
|
|
stub_request(:get, "www.example.com").to_return(status: 200, body: 'pong')
|
|
|
|
resource = load_resource('http', 'http://www.example.com')
|
|
_(resource.status).must_equal 200
|
|
_(resource.body).must_equal 'pong'
|
|
end
|
|
|
|
it 'verify http with basic auth' do
|
|
stub_request(:get, "www.example.com").with(basic_auth: ['user', 'pass']).to_return(status: 200, body: 'auth ok')
|
|
|
|
resource = load_resource('http', 'http://www.example.com', auth: { user: 'user',pass: 'pass'})
|
|
_(resource.status).must_equal 200
|
|
_(resource.body).must_equal 'auth ok'
|
|
end
|
|
|
|
it 'verify http post with data' do
|
|
stub_request(:post, "www.example.com").with(body: {data: {a: '1', b: 'five'}}).to_return(status: 200, body: 'post ok')
|
|
|
|
resource = load_resource('http', 'http://www.example.com',
|
|
method: 'POST',
|
|
data: '{"data":{"a":"1","b":"five"}}',
|
|
headers: {'content-type' => 'application/json'})
|
|
_(resource.status).must_equal 200
|
|
_(resource.body).must_equal 'post ok'
|
|
end
|
|
|
|
it 'verify http headers' do
|
|
stub_request(:post, "www.example.com").with(headers: {'content-type' => 'application/json'}).to_return(status: 200, body: 'headers ok', headers: {'mock' => 'ok'})
|
|
|
|
resource = load_resource('http', 'http://www.example.com',
|
|
method: 'POST',
|
|
data: '{"data":{"a":"1","b":"five"}}',
|
|
headers: {'content-type' => 'application/json'})
|
|
_(resource.status).must_equal 200
|
|
_(resource.body).must_equal 'headers ok'
|
|
_(resource.headers.mock).must_equal 'ok'
|
|
end
|
|
|
|
it 'verify http with params' do
|
|
stub_request(:get, "www.example.com").with(query: {a: 'b'}).to_return(status: 200, body: 'params ok')
|
|
|
|
resource = load_resource('http', 'http://www.example.com', params: {a: 'b'})
|
|
_(resource.status).must_equal 200
|
|
_(resource.body).must_equal 'params ok'
|
|
end
|
|
end
|