add auth challenge test

master
Kanezoh 2022-01-05 10:18:33 +09:00
parent c5f07b126e
commit d6d8f68cd1
2 changed files with 62 additions and 0 deletions

View 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

View File

@ -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