webmock
webmock copied to clipboard
Stubbing Cookie/s with Typhoeus
Unless I am doing something wrong, it's currently not possible to stub Typhoeus requests with cookies.
stub_request(:get, url)
.with(headers: { 'Cookie' => 'key=value' })
.to_return(body: 'Cookies Accepted!')
does not work because Typhoeus does not set the Cookie header it seems, but rather use the :cookie option (https://github.com/typhoeus/ethon/blob/c5c9c6e10114c9939642be522ab05432ca7ec5d2/lib/ethon/curls/options.rb#L340):
@request=
#<Typhoeus::Request:0x0000000003619150
@__webmock_request_signature=
#<WebMock::RequestSignature:0x000000000361ec68
@body=nil,
@headers=
{"User-Agent"=>"WPScan v3.5.0 (https://wpscan.org/)", "Expect"=>""},
@method=:get,
@uri=#<Addressable::URI:0x1b0f4b8 URI:http://wp.lab/>>,
@base_url="http://wp.lab/",
@block_connection=false,
@on_complete=[],
@on_headers=[],
@on_progress=[],
@on_success=[],
@options=
{:headers=>
{"User-Agent"=>"WPScan v3.5.0 (https://wpscan.org/)", "Expect"=>""},
:accept_encoding=>"gzip, deflate",
:method=>:get,
:cookie=>"key=value",
:followlocation=>true,
:maxredirs=>3},
@original_options=
{:headers=>{"User-Agent"=>"WPScan v3.5.0 (https://wpscan.org/)"},
:accept_encoding=>"gzip, deflate",
:method=>:get,
:cookie=>"key=value",
:followlocation=>true,
:maxredirs=>3},
@response=#<Typhoeus::Response:0x0000000003628d80 ...>>>