mirror of
https://github.com/inspec/inspec
synced 2024-12-24 03:53:15 +00:00
798aebf672
This changes the default read and open timeouts to be 60 seconds which matches the defaults for `Net::HTTP` backend which Faraday uses by default: https://ruby-doc.org/stdlib-2.4.1/libdoc/net/http/rdoc/Net/HTTP.html#read_timeout-attribute-method https://ruby-doc.org/stdlib-2.4.1/libdoc/net/http/rdoc/Net/HTTP.html#open_timeout-attribute-method The current timeout values are too small which causes tests to be flakey. Signed-off-by: Seth Chisamore <schisamo@chef.io>
62 lines
2.4 KiB
Ruby
62 lines
2.4 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
|
|
|
|
it 'verify http with timeouts' do
|
|
stub_request(:get, "www.example.com").to_return(status: 200, body: 'params ok')
|
|
|
|
resource = load_resource('http', 'http://www.example.com', open_timeout: 10, read_timeout: 10)
|
|
_(resource.instance_variable_get(:@open_timeout)).must_equal 10
|
|
_(resource.instance_variable_get(:@read_timeout)).must_equal 10
|
|
end
|
|
end
|