add test
This commit is contained in:
parent
972fc61ad7
commit
d54a93a64a
15
spec/http_auth_spec.cr
Normal file
15
spec/http_auth_spec.cr
Normal file
@ -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)
|
||||
end
|
||||
|
||||
if response && response.status.unauthorized?
|
||||
response_authenticate(response)
|
||||
end
|
||||
|
||||
page
|
||||
end
|
||||
|
||||
@ -220,6 +224,10 @@ class Mechanize
|
||||
target_url
|
||||
end
|
||||
|
||||
private def response_authenticate(response)
|
||||
www_authenticate = response.headers["www-authenticate"]
|
||||
end
|
||||
|
||||
# reset request cookie before setting headers.
|
||||
private def reset_request_header_cookies
|
||||
request_headers.delete("Cookie")
|
||||
|
Loading…
Reference in New Issue
Block a user