kemal/spec/middleware/http_basic_auth_spec.cr

29 lines
1,018 B
Crystal
Raw Normal View History

2015-12-27 09:53:54 +00:00
require "../spec_helper"
describe "Kemal::Middleware::HTTPBasicAuth" do
it "goes to next handler with correct credentials" do
auth_handler = Kemal::Middleware::HTTPBasicAuth.new("serdar", "123")
request = HTTP::Request.new(
"GET",
"/",
headers: HTTP::Headers{"Authorization": "Basic c2VyZGFyOjEyMw=="},
)
2016-01-24 10:22:25 +00:00
io_with_context = create_request_and_return_io(auth_handler, request)
client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
client_response.status_code.should eq 404
2015-12-27 09:53:54 +00:00
end
it "returns 401 with incorrect credentials" do
auth_handler = Kemal::Middleware::HTTPBasicAuth.new("serdar", "123")
request = HTTP::Request.new(
"GET",
"/",
headers: HTTP::Headers{"Authorization": "NotBasic"},
)
2016-01-24 10:22:25 +00:00
io_with_context = create_request_and_return_io(auth_handler, request)
client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
client_response.status_code.should eq 401
2015-12-27 09:53:54 +00:00
end
end