mechanize.cr/spec/http_auth_spec.cr

20 lines
564 B
Crystal
Raw Normal View History

2021-12-01 12:29:36 +01:00
require "./spec_helper"
2022-01-04 01:53:04 +01:00
require "./server.cr"
2021-12-01 12:29:36 +01:00
describe "Mechanize HTTP Authentication test" do
2022-01-04 05:09:09 +01:00
WebMock.allow_net_connect = true
it "should be unsuccessful without credentials " do
2022-01-04 01:53:04 +01:00
agent = Mechanize.new
page = agent.get("#{TEST_SERVER_URL}/secret")
2022-01-04 05:09:09 +01:00
page.code.should eq 401
# WebMock.allow_net_connect = false
end
it "should be successful with credentials " do
agent = Mechanize.new
agent.add_auth("#{TEST_SERVER_URL}", "username", "password")
page = agent.get("#{TEST_SERVER_URL}/secret")
page.code.should eq 200
end
2021-12-01 12:29:36 +01:00
end