mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Add HTTPBasicAuth middleware
This commit is contained in:
parent
8b6700695d
commit
743fd3682d
4 changed files with 65 additions and 0 deletions
25
spec/middleware/http_basic_auth_spec.cr
Normal file
25
spec/middleware/http_basic_auth_spec.cr
Normal file
|
@ -0,0 +1,25 @@
|
|||
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=="},
|
||||
)
|
||||
response = auth_handler.call(request)
|
||||
response.status_code.should eq 404
|
||||
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"},
|
||||
)
|
||||
response = auth_handler.call(request)
|
||||
response.status_code.should eq 401
|
||||
end
|
||||
end
|
|
@ -1,5 +1,6 @@
|
|||
require "spec"
|
||||
require "../src/kemal/*"
|
||||
require "../src/kemal/middleware/*"
|
||||
|
||||
include Kemal
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue