add auth challenge test
This commit is contained in:
parent
c5f07b126e
commit
d6d8f68cd1
61
spec/http_auth_challenge_spec.cr
Normal file
61
spec/http_auth_challenge_spec.cr
Normal file
@ -0,0 +1,61 @@
|
||||
require "./spec_helper"
|
||||
|
||||
describe "Mechanize AuthChallenge test" do
|
||||
it "test_realm_basic" do
|
||||
uri = URI.parse "http://example.com/"
|
||||
challenge = Mechanize::HTTP::AuthChallenge.new "Digest", {"realm" => "r"}, "Digest realm=r"
|
||||
challenge.scheme = "Basic"
|
||||
|
||||
expected = Mechanize::HTTP::AuthRealm.new "Basic", uri, "r"
|
||||
uri_path = URI.parse("http://example.com/foo")
|
||||
|
||||
challenge.realm(uri_path).should eq expected
|
||||
end
|
||||
|
||||
it "test_realm_digest" do
|
||||
uri = URI.parse "http://example.com/"
|
||||
challenge = Mechanize::HTTP::AuthChallenge.new "Digest", {"realm" => "r"}, "Digest realm=r"
|
||||
|
||||
expected = Mechanize::HTTP::AuthRealm.new "Digest", uri, "r"
|
||||
uri_path = URI.parse("http://example.com/foo")
|
||||
|
||||
challenge.realm(uri_path).should eq expected
|
||||
end
|
||||
|
||||
it "test_realm_digest_case" do
|
||||
uri = URI.parse "http://example.com/"
|
||||
challenge = Mechanize::HTTP::AuthChallenge.new "Digest", {"realm" => "R"}, "Digest realm=R"
|
||||
|
||||
expected = Mechanize::HTTP::AuthRealm.new "Digest", uri, "R"
|
||||
uri_path = URI.parse("http://example.com/foo")
|
||||
|
||||
challenge.realm(uri_path).should eq expected
|
||||
end
|
||||
|
||||
it "test_realm_unknown" do
|
||||
challenge = Mechanize::HTTP::AuthChallenge.new "Digest", {"realm" => "R"}, "Digest realm=R"
|
||||
challenge.scheme = "Unknown"
|
||||
|
||||
uri_path = URI.parse("http://example.com/foo")
|
||||
expect_raises(Exception, "unknown HTTP authentication scheme #{challenge.scheme}") do
|
||||
challenge.realm(uri_path)
|
||||
end
|
||||
end
|
||||
|
||||
it "test_realm_name" do
|
||||
uri = URI.parse "http://example.com/"
|
||||
challenge = Mechanize::HTTP::AuthChallenge.new "Digest", {"realm" => "r"}, "Digest realm=r"
|
||||
challenge.realm_name.should eq "r"
|
||||
end
|
||||
|
||||
it "test_realm_name_case" do
|
||||
uri = URI.parse "http://example.com/"
|
||||
challenge = Mechanize::HTTP::AuthChallenge.new "Digest", {"realm" => "R"}, "Digest realm=R"
|
||||
challenge.realm_name.should eq "R"
|
||||
end
|
||||
|
||||
it "test_realm_name_ntlm" do
|
||||
challenge = Mechanize::HTTP::AuthChallenge.new "Negotiate, NTLM"
|
||||
challenge.realm_name.should eq nil
|
||||
end
|
||||
end
|
@ -39,6 +39,7 @@ class Mechanize
|
||||
Mechanize::HTTP::AuthRealm.new scheme, target_uri, self["realm"]
|
||||
else
|
||||
# raise Mechanize::Error, "unknown HTTP authentication scheme #{scheme}"
|
||||
raise Exception.new("unknown HTTP authentication scheme #{scheme}")
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user