From 3ddcd594aad41449eda80e47ae3706b7cf90a7df Mon Sep 17 00:00:00 2001 From: Kanezoh Date: Mon, 3 Jan 2022 07:18:04 +0900 Subject: [PATCH] credentials_for test --- spec/http_auth_store_spec.cr | 51 ++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/spec/http_auth_store_spec.cr b/spec/http_auth_store_spec.cr index d86b493..97abcc8 100644 --- a/spec/http_auth_store_spec.cr +++ b/spec/http_auth_store_spec.cr @@ -85,4 +85,55 @@ describe "Mechanize AuthStore test" do auth_store.credentials?(url, challenges).should eq true auth_store.credentials?("#{url}/path", challenges).should eq true end + + it "test_credentials_for" do + auth_store = Mechanize::HTTP::AuthStore.new + url = URI.parse("http://example.com/") + auth_store.credentials_for(url, "realm").should eq nil + + auth_store.add_auth url, "user", "pass", "realm" + + auth_store.credentials_for(url, "realm").should eq ["user", "pass", ""] + auth_store.credentials_for(url.to_s, "realm").should eq ["user", "pass", ""] + + auth_store.credentials_for(url, "other").should eq nil + end + + it "test_credentials_for_no_realm" do + auth_store = Mechanize::HTTP::AuthStore.new + url = URI.parse("http://example.com/") + auth_store.add_auth url, "user", "pass" # no realm set + + auth_store.credentials_for(url, "realm").should eq ["user", "pass", ""] + end + + it "test_credentials_for_realm" do + auth_store = Mechanize::HTTP::AuthStore.new + url = URI.parse("http://example.com/") + auth_store.add_auth url, "user1", "pass" + auth_store.add_auth url, "user2", "pass", "realm" + + auth_store.credentials_for(url, "realm").should eq ["user2", "pass", ""] + auth_store.credentials_for(url, "other").should eq ["user1", "pass", ""] + end + + it "test_credentials_for_realm_case" do + auth_store = Mechanize::HTTP::AuthStore.new + url = URI.parse("http://example.com/") + auth_store.add_auth url, "user1", "pass", "realm" + auth_store.add_auth url, "user2", "pass", "Realm" + + auth_store.credentials_for(url, "realm").should eq ["user1", "pass", ""] + auth_store.credentials_for(url, "Realm").should eq ["user2", "pass", ""] + end + + it "test_credentials_for_path" do + auth_store = Mechanize::HTTP::AuthStore.new + url = URI.parse("http://example.com/") + auth_store.add_auth url, "user", "pass", "realm" + + url = url.to_s + "/path" + + auth_store.credentials_for(url, "realm").should eq ["user", "pass", ""] + end end