mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Merge pull request #162 from omarroth/fix-0.18
Fix SSL and specs for 0.18
This commit is contained in:
commit
e9665c124b
8 changed files with 35 additions and 35 deletions
|
@ -6,7 +6,7 @@ describe "Kemal::Middleware::HTTPBasicAuth" do
|
||||||
request = HTTP::Request.new(
|
request = HTTP::Request.new(
|
||||||
"GET",
|
"GET",
|
||||||
"/",
|
"/",
|
||||||
headers: HTTP::Headers{"Authorization": "Basic c2VyZGFyOjEyMw=="},
|
headers: HTTP::Headers{"Authorization" => "Basic c2VyZGFyOjEyMw=="},
|
||||||
)
|
)
|
||||||
|
|
||||||
io_with_context = create_request_and_return_io(auth_handler, request)
|
io_with_context = create_request_and_return_io(auth_handler, request)
|
||||||
|
@ -19,7 +19,7 @@ describe "Kemal::Middleware::HTTPBasicAuth" do
|
||||||
request = HTTP::Request.new(
|
request = HTTP::Request.new(
|
||||||
"GET",
|
"GET",
|
||||||
"/",
|
"/",
|
||||||
headers: HTTP::Headers{"Authorization": "NotBasic"},
|
headers: HTTP::Headers{"Authorization" => "NotBasic"},
|
||||||
)
|
)
|
||||||
io_with_context = create_request_and_return_io(auth_handler, request)
|
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 = HTTP::Client::Response.from_io(io_with_context, decompress: false)
|
||||||
|
|
|
@ -45,16 +45,16 @@ describe "ParamParser" do
|
||||||
"POST",
|
"POST",
|
||||||
"/?hasan=cemal",
|
"/?hasan=cemal",
|
||||||
body: "name=serdar&age=99",
|
body: "name=serdar&age=99",
|
||||||
headers: HTTP::Headers{"Content-Type": "application/x-www-form-urlencoded"},
|
headers: HTTP::Headers{"Content-Type" => "application/x-www-form-urlencoded"},
|
||||||
)
|
)
|
||||||
|
|
||||||
query_params = Kemal::ParamParser.new(request).query
|
query_params = Kemal::ParamParser.new(request).query
|
||||||
{"hasan": "cemal"}.each do |k, v|
|
{"hasan" => "cemal"}.each do |k, v|
|
||||||
query_params[k].should eq(v)
|
query_params[k].should eq(v)
|
||||||
end
|
end
|
||||||
|
|
||||||
body_params = Kemal::ParamParser.new(request).body
|
body_params = Kemal::ParamParser.new(request).body
|
||||||
{"name": "serdar", "age": "99"}.each do |k, v|
|
{"name" => "serdar", "age" => "99"}.each do |k, v|
|
||||||
body_params[k].should eq(v)
|
body_params[k].should eq(v)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -69,7 +69,7 @@ describe "ParamParser" do
|
||||||
"POST",
|
"POST",
|
||||||
"/",
|
"/",
|
||||||
body: "hasan=cemal&hasan=lamec",
|
body: "hasan=cemal&hasan=lamec",
|
||||||
headers: HTTP::Headers{"Content-Type": "application/x-www-form-urlencoded"},
|
headers: HTTP::Headers{"Content-Type" => "application/x-www-form-urlencoded"},
|
||||||
)
|
)
|
||||||
|
|
||||||
body_params = Kemal::ParamParser.new(request).body
|
body_params = Kemal::ParamParser.new(request).body
|
||||||
|
@ -84,11 +84,11 @@ describe "ParamParser" do
|
||||||
"POST",
|
"POST",
|
||||||
"/",
|
"/",
|
||||||
body: "{\"name\": \"Serdar\"}",
|
body: "{\"name\": \"Serdar\"}",
|
||||||
headers: HTTP::Headers{"Content-Type": "application/json"},
|
headers: HTTP::Headers{"Content-Type" => "application/json"},
|
||||||
)
|
)
|
||||||
|
|
||||||
json_params = Kemal::ParamParser.new(request).json
|
json_params = Kemal::ParamParser.new(request).json
|
||||||
json_params.should eq({"name": "Serdar"})
|
json_params.should eq({"name" => "Serdar"})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "parses request body for array" do
|
it "parses request body for array" do
|
||||||
|
@ -98,11 +98,11 @@ describe "ParamParser" do
|
||||||
"POST",
|
"POST",
|
||||||
"/",
|
"/",
|
||||||
body: "[1]",
|
body: "[1]",
|
||||||
headers: HTTP::Headers{"Content-Type": "application/json"},
|
headers: HTTP::Headers{"Content-Type" => "application/json"},
|
||||||
)
|
)
|
||||||
|
|
||||||
json_params = Kemal::ParamParser.new(request).json
|
json_params = Kemal::ParamParser.new(request).json
|
||||||
json_params.should eq({"_json": [1]})
|
json_params.should eq({"_json" => [1]})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "parses request body and query params" do
|
it "parses request body and query params" do
|
||||||
|
@ -112,16 +112,16 @@ describe "ParamParser" do
|
||||||
"POST",
|
"POST",
|
||||||
"/?foo=bar",
|
"/?foo=bar",
|
||||||
body: "[1]",
|
body: "[1]",
|
||||||
headers: HTTP::Headers{"Content-Type": "application/json"},
|
headers: HTTP::Headers{"Content-Type" => "application/json"},
|
||||||
)
|
)
|
||||||
|
|
||||||
query_params = Kemal::ParamParser.new(request).query
|
query_params = Kemal::ParamParser.new(request).query
|
||||||
{"foo": "bar"}.each do |k, v|
|
{"foo" => "bar"}.each do |k, v|
|
||||||
query_params[k].should eq(v)
|
query_params[k].should eq(v)
|
||||||
end
|
end
|
||||||
|
|
||||||
json_params = Kemal::ParamParser.new(request).json
|
json_params = Kemal::ParamParser.new(request).json
|
||||||
json_params.should eq({"_json": [1]})
|
json_params.should eq({"_json" => [1]})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "handles no request body" do
|
it "handles no request body" do
|
||||||
|
@ -130,7 +130,7 @@ describe "ParamParser" do
|
||||||
request = HTTP::Request.new(
|
request = HTTP::Request.new(
|
||||||
"GET",
|
"GET",
|
||||||
"/",
|
"/",
|
||||||
headers: HTTP::Headers{"Content-Type": "application/json"},
|
headers: HTTP::Headers{"Content-Type" => "application/json"},
|
||||||
)
|
)
|
||||||
|
|
||||||
url_params = Kemal::ParamParser.new(request).url
|
url_params = Kemal::ParamParser.new(request).url
|
||||||
|
@ -160,7 +160,7 @@ describe "ParamParser" do
|
||||||
"POST",
|
"POST",
|
||||||
"/?hasan=cemal",
|
"/?hasan=cemal",
|
||||||
body: "name=serdar&age=99",
|
body: "name=serdar&age=99",
|
||||||
headers: HTTP::Headers{"Content-Type": "text/plain"},
|
headers: HTTP::Headers{"Content-Type" => "text/plain"},
|
||||||
)
|
)
|
||||||
|
|
||||||
query_params = Kemal::ParamParser.new(request).query
|
query_params = Kemal::ParamParser.new(request).query
|
||||||
|
|
|
@ -49,7 +49,7 @@ describe "Kemal::RouteHandler" do
|
||||||
"POST",
|
"POST",
|
||||||
"/",
|
"/",
|
||||||
body: json_payload.to_json,
|
body: json_payload.to_json,
|
||||||
headers: HTTP::Headers{"Content-Type": "application/json"},
|
headers: HTTP::Headers{"Content-Type" => "application/json"},
|
||||||
)
|
)
|
||||||
client_response = call_request_on_app(request)
|
client_response = call_request_on_app(request)
|
||||||
client_response.body.should eq("Hello Serdar Age 26")
|
client_response.body.should eq("Hello Serdar Age 26")
|
||||||
|
@ -57,7 +57,7 @@ describe "Kemal::RouteHandler" do
|
||||||
|
|
||||||
it "parses JSON with string array" do
|
it "parses JSON with string array" do
|
||||||
post "/" do |env|
|
post "/" do |env|
|
||||||
skills = env.params.json["skills"] as Array
|
skills = env.params.json["skills"].as(Array)
|
||||||
"Skills #{skills.each.join(',')}"
|
"Skills #{skills.each.join(',')}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ describe "Kemal::RouteHandler" do
|
||||||
"POST",
|
"POST",
|
||||||
"/",
|
"/",
|
||||||
body: json_payload.to_json,
|
body: json_payload.to_json,
|
||||||
headers: HTTP::Headers{"Content-Type": "application/json"},
|
headers: HTTP::Headers{"Content-Type" => "application/json"},
|
||||||
)
|
)
|
||||||
client_response = call_request_on_app(request)
|
client_response = call_request_on_app(request)
|
||||||
client_response.body.should eq("Skills ruby,crystal")
|
client_response.body.should eq("Skills ruby,crystal")
|
||||||
|
@ -74,9 +74,9 @@ describe "Kemal::RouteHandler" do
|
||||||
|
|
||||||
it "parses JSON with json object array" do
|
it "parses JSON with json object array" do
|
||||||
post "/" do |env|
|
post "/" do |env|
|
||||||
skills = env.params.json["skills"] as Array
|
skills = env.params.json["skills"].as(Array)
|
||||||
skills_from_languages = skills.map do |skill|
|
skills_from_languages = skills.map do |skill|
|
||||||
skill = skill as Hash
|
skill = skill.as(Hash)
|
||||||
skill["language"]
|
skill["language"]
|
||||||
end
|
end
|
||||||
"Skills #{skills_from_languages.each.join(',')}"
|
"Skills #{skills_from_languages.each.join(',')}"
|
||||||
|
@ -87,7 +87,7 @@ describe "Kemal::RouteHandler" do
|
||||||
"POST",
|
"POST",
|
||||||
"/",
|
"/",
|
||||||
body: json_payload.to_json,
|
body: json_payload.to_json,
|
||||||
headers: HTTP::Headers{"Content-Type": "application/json"},
|
headers: HTTP::Headers{"Content-Type" => "application/json"},
|
||||||
)
|
)
|
||||||
|
|
||||||
client_response = call_request_on_app(request)
|
client_response = call_request_on_app(request)
|
||||||
|
@ -102,7 +102,7 @@ describe "Kemal::RouteHandler" do
|
||||||
"POST",
|
"POST",
|
||||||
"/",
|
"/",
|
||||||
body: "_method=PUT",
|
body: "_method=PUT",
|
||||||
headers: HTTP::Headers{"Content-Type": "application/x-www-form-urlencoded"}
|
headers: HTTP::Headers{"Content-Type" => "application/x-www-form-urlencoded"}
|
||||||
)
|
)
|
||||||
client_response = call_request_on_app(request)
|
client_response = call_request_on_app(request)
|
||||||
client_response.body.should eq("Hello World from PUT")
|
client_response.body.should eq("Hello World from PUT")
|
||||||
|
@ -116,7 +116,7 @@ describe "Kemal::RouteHandler" do
|
||||||
"POST",
|
"POST",
|
||||||
"/",
|
"/",
|
||||||
body: "_method=PATCH",
|
body: "_method=PATCH",
|
||||||
headers: HTTP::Headers{"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}
|
headers: HTTP::Headers{"Content-Type" => "application/x-www-form-urlencoded; charset=UTF-8"}
|
||||||
)
|
)
|
||||||
client_response = call_request_on_app(request)
|
client_response = call_request_on_app(request)
|
||||||
client_response.body.should eq("Hello World from PATCH")
|
client_response.body.should eq("Hello World from PATCH")
|
||||||
|
@ -131,7 +131,7 @@ describe "Kemal::RouteHandler" do
|
||||||
"POST",
|
"POST",
|
||||||
"/",
|
"/",
|
||||||
body: "_method=DELETE",
|
body: "_method=DELETE",
|
||||||
headers: HTTP::Headers{"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}
|
headers: HTTP::Headers{"Content-Type" => "application/x-www-form-urlencoded; charset=UTF-8"}
|
||||||
)
|
)
|
||||||
client_response = call_request_on_app(request)
|
client_response = call_request_on_app(request)
|
||||||
client_response.body.should eq("Hello World from DELETE")
|
client_response.body.should eq("Hello World from DELETE")
|
||||||
|
|
|
@ -4,9 +4,9 @@ describe "Kemal::WebSocketHandler" do
|
||||||
it "doesn't match on wrong route" do
|
it "doesn't match on wrong route" do
|
||||||
handler = Kemal::WebSocketHandler.new "/" { }
|
handler = Kemal::WebSocketHandler.new "/" { }
|
||||||
headers = HTTP::Headers{
|
headers = HTTP::Headers{
|
||||||
"Upgrade": "websocket",
|
"Upgrade" => "websocket",
|
||||||
"Connection": "Upgrade",
|
"Connection" => "Upgrade",
|
||||||
"Sec-WebSocket-Key": "dGhlIHNhbXBsZSBub25jZQ==",
|
"Sec-WebSocket-Key" => "dGhlIHNhbXBsZSBub25jZQ==",
|
||||||
}
|
}
|
||||||
request = HTTP::Request.new("GET", "/asd", headers)
|
request = HTTP::Request.new("GET", "/asd", headers)
|
||||||
io_with_context = create_request_and_return_io(handler, request)
|
io_with_context = create_request_and_return_io(handler, request)
|
||||||
|
@ -17,9 +17,9 @@ describe "Kemal::WebSocketHandler" do
|
||||||
it "matches on given route" do
|
it "matches on given route" do
|
||||||
handler = Kemal::WebSocketHandler.new "/" { }
|
handler = Kemal::WebSocketHandler.new "/" { }
|
||||||
headers = HTTP::Headers{
|
headers = HTTP::Headers{
|
||||||
"Upgrade": "websocket",
|
"Upgrade" => "websocket",
|
||||||
"Connection": "Upgrade",
|
"Connection" => "Upgrade",
|
||||||
"Sec-WebSocket-Key": "dGhlIHNhbXBsZSBub25jZQ==",
|
"Sec-WebSocket-Key" => "dGhlIHNhbXBsZSBub25jZQ==",
|
||||||
}
|
}
|
||||||
request = HTTP::Request.new("GET", "/", headers)
|
request = HTTP::Request.new("GET", "/", headers)
|
||||||
io_with_context = create_ws_request_and_return_io(handler, request)
|
io_with_context = create_ws_request_and_return_io(handler, request)
|
||||||
|
|
|
@ -10,7 +10,7 @@ module Kemal
|
||||||
config.add_handler Kemal::RouteHandler::INSTANCE
|
config.add_handler Kemal::RouteHandler::INSTANCE
|
||||||
|
|
||||||
config.server = HTTP::Server.new(config.host_binding.not_nil!, config.port, config.handlers)
|
config.server = HTTP::Server.new(config.host_binding.not_nil!, config.port, config.handlers)
|
||||||
config.server.not_nil!.ssl = config.ssl
|
config.server.not_nil!.tls = config.ssl
|
||||||
|
|
||||||
unless Kemal.config.error_handlers.has_key?(404)
|
unless Kemal.config.error_handlers.has_key?(404)
|
||||||
error 404 do |env|
|
error 404 do |env|
|
||||||
|
|
|
@ -45,8 +45,8 @@ module Kemal
|
||||||
puts "SSL Key Not Found"; exit unless @key_file
|
puts "SSL Key Not Found"; exit unless @key_file
|
||||||
puts "SSL Certificate Not Found"; exit unless @cert_file
|
puts "SSL Certificate Not Found"; exit unless @cert_file
|
||||||
ssl = Kemal::Middleware::SSL.new
|
ssl = Kemal::Middleware::SSL.new
|
||||||
ssl.set_key_file @key_file.not_nil!.to_slice
|
ssl.set_key_file @key_file.not_nil!
|
||||||
ssl.set_cert_file @cert_file.not_nil!.to_slice
|
ssl.set_cert_file @cert_file.not_nil!
|
||||||
Kemal.config.ssl = ssl.context
|
Kemal.config.ssl = ssl.context
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@ module Kemal
|
||||||
INSTANCE = Config.new
|
INSTANCE = Config.new
|
||||||
HANDLERS = [] of HTTP::Handler
|
HANDLERS = [] of HTTP::Handler
|
||||||
ERROR_HANDLERS = {} of Int32 => HTTP::Server::Context -> String
|
ERROR_HANDLERS = {} of Int32 => HTTP::Server::Context -> String
|
||||||
@ssl : OpenSSL::SSL::Context?
|
@ssl : OpenSSL::SSL::Context::Server?
|
||||||
@server : HTTP::Server?
|
@server : HTTP::Server?
|
||||||
|
|
||||||
property host_binding, ssl, port, env, public_folder, logging,
|
property host_binding, ssl, port, env, public_folder, logging,
|
||||||
|
|
|
@ -3,7 +3,7 @@ module Kemal::Middleware
|
||||||
getter context
|
getter context
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@context = OpenSSL::SSL::Context.new
|
@context = OpenSSL::SSL::Context::Server.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_key_file(key_file)
|
def set_key_file(key_file)
|
||||||
|
|
Loading…
Reference in a new issue