add test
parent
972fc61ad7
commit
d54a93a64a
|
@ -0,0 +1,15 @@
|
||||||
|
require "./spec_helper"
|
||||||
|
|
||||||
|
WebMock.stub(:get, "http://auth.example.com/")
|
||||||
|
.with(headers: {"Authorization" => "Basic #{Base64.strict_encode("user:pass").chomp}"})
|
||||||
|
.to_return(status: 200)
|
||||||
|
|
||||||
|
WebMock.stub(:get, "http://auth.example.com/")
|
||||||
|
.to_return(status: 401, headers: {"WWW-Authenticate" => "Basic realm=\"Access to the staging site\", charset=\"UTF-8\""})
|
||||||
|
|
||||||
|
describe "Mechanize HTTP Authentication test" do
|
||||||
|
it "auth" do
|
||||||
|
agent = Mechanize.new
|
||||||
|
agent.get("http://auth.example.com/")
|
||||||
|
end
|
||||||
|
end
|
|
@ -47,6 +47,10 @@ class Mechanize
|
||||||
return follow_redirect(response, headers, page)
|
return follow_redirect(response, headers, page)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if response && response.status.unauthorized?
|
||||||
|
response_authenticate(response)
|
||||||
|
end
|
||||||
|
|
||||||
page
|
page
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -220,6 +224,10 @@ class Mechanize
|
||||||
target_url
|
target_url
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private def response_authenticate(response)
|
||||||
|
www_authenticate = response.headers["www-authenticate"]
|
||||||
|
end
|
||||||
|
|
||||||
# reset request cookie before setting headers.
|
# reset request cookie before setting headers.
|
||||||
private def reset_request_header_cookies
|
private def reset_request_header_cookies
|
||||||
request_headers.delete("Cookie")
|
request_headers.delete("Cookie")
|
||||||
|
|
Loading…
Reference in New Issue