mechanize.cr/spec/http_auth_store_spec.cr

89 lines
2.4 KiB
Crystal
Raw Normal View History

2021-12-29 09:23:42 +01:00
require "./spec_helper"
describe "Mechanize AuthStore test" do
it "add_auth" do
auth_store = Mechanize::HTTP::AuthStore.new
url = URI.parse("http://example.com/")
user = "kanezoh"
password = "password"
2022-01-01 05:27:20 +01:00
realm = ""
2021-12-29 09:23:42 +01:00
auth_store.add_auth(url, user, password)
2022-01-01 05:27:20 +01:00
auth_store.auth_accounts[url].size.should eq 1
2022-01-02 14:14:58 +01:00
auth_store.auth_accounts[url][realm].should eq(["kanezoh", "password", ""])
2022-01-01 05:27:20 +01:00
end
2022-01-02 14:14:58 +01:00
it "test_add_auth_domain" do
2022-01-01 05:27:20 +01:00
auth_store = Mechanize::HTTP::AuthStore.new
url = URI.parse("http://example.com/")
user = "kanezoh"
password = "password"
2022-01-02 14:14:58 +01:00
domain = "domain"
2022-01-01 05:27:20 +01:00
realm = ""
2022-01-02 14:14:58 +01:00
auth_store.add_auth(url, user, password, nil, domain)
auth_store.auth_accounts[url][realm].should eq(["kanezoh", "password", "domain"])
end
it "test_add_auth_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"
expected = {
url => {
"" => ["user1", "pass", ""],
"realm" => ["user2", "pass", ""],
},
}
auth_store.auth_accounts.should eq expected
end
it "test_add_auth_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"
expected = {
url => {
"realm" => ["user1", "pass", ""],
"Realm" => ["user2", "pass", ""],
},
}
auth_store.auth_accounts.should eq expected
end
it "test_add_auth_string" do
auth_store = Mechanize::HTTP::AuthStore.new
url = URI.parse("http://example.com/")
auth_store.add_auth "#{url}/path", "user", "pass"
expected = {
url => {
"" => ["user", "pass", ""],
},
}
auth_store.auth_accounts.should eq expected
end
it "test_credentials_eh" do
auth_store = Mechanize::HTTP::AuthStore.new
url = URI.parse("http://example.com/")
challenges = [
Mechanize::HTTP::AuthChallenge.new("Basic", {"realm" => "r"}),
Mechanize::HTTP::AuthChallenge.new("Digest", {"realm" => "r"}),
]
auth_store.credentials?(url, challenges).should_not eq true
auth_store.add_auth url, "user", "pass"
auth_store.credentials?(url, challenges).should eq true
auth_store.credentials?("#{url}/path", challenges).should eq true
2021-12-29 09:23:42 +01:00
end
end