Packages
bandit
0.7.2
1.12.0
1.11.1
1.11.0
1.10.4
1.10.3
1.10.2
1.10.1
1.10.0
retired
1.9.0
1.8.0
1.7.0
1.6.11
1.6.10
1.6.9
1.6.8
1.6.7
1.6.6
1.6.5
1.6.4
1.6.3
1.6.2
1.6.1
1.6.0
1.5.7
1.5.6
1.5.5
1.5.4
1.5.3
1.5.2
1.5.1
1.5.0
1.4.2
1.4.1
1.4.0
1.3.0
1.2.3
1.2.2
1.2.1
1.2.0
1.1.3
1.1.2
1.1.1
1.1.0
1.0.0
1.0.0-pre.18
1.0.0-pre.17
1.0.0-pre.16
1.0.0-pre.15
1.0.0-pre.14
1.0.0-pre.13
1.0.0-pre.12
1.0.0-pre.11
1.0.0-pre.10
1.0.0-pre.9
1.0.0-pre.8
1.0.0-pre.7
1.0.0-pre.6
1.0.0-pre.5
1.0.0-pre.4
1.0.0-pre.3
1.0.0-pre.2
1.0.0-pre.1
0.7.7
0.7.6
0.7.5
0.7.4
0.7.3
0.7.2
0.7.1
0.7.0
0.6.11
0.6.10
0.6.9
0.6.8
0.6.7
0.6.6
0.6.5
0.6.4
0.6.3
0.6.2
0.6.1
0.6.0
0.5.11
0.5.10
0.5.9
0.5.8
0.5.7
0.5.6
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.10
0.4.9
0.4.8
0.4.7
0.4.6
0.4.5
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.3.9
0.3.8
0.3.7
0.3.6
0.3.5
0.3.4
0.3.3
0.3.2
0.2.3
0.2.2
0.2.1
0.2.0
0.1.1
0.1.0
A pure-Elixir HTTP server built for Plug & WebSock apps
Security advisory:
This version has known vulnerabilities.
View advisories
Current section
Files
Jump to
Current section
Files
test/bandit/initial_handler_test.exs
defmodule InitialHandlerTest do
use ExUnit.Case, async: true
use ServerHelpers
use FinchHelpers
import ExUnit.CaptureLog
def report_version(conn) do
body = "#{get_http_protocol(conn)} #{conn.scheme}"
send_resp(conn, 200, body)
end
describe "disabling protocols requests" do
test "closes connection on HTTP/1 request if so configured", context do
context = http_server(context, http_1_options: [enabled: false])
client = SimpleHTTP1Client.tcp_client(context)
SimpleHTTP1Client.send(client, "GET", "/echo_components", ["host: banana"])
assert SimpleHTTP1Client.connection_closed_for_reading?(client)
end
test "closes connection on HTTP/2 request if so configured", context do
context = https_server(context, http_2_options: [enabled: false])
socket = SimpleH2Client.tls_client(context)
:ssl.send(socket, "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n")
assert :ssl.recv(socket, 0) == {:error, :closed}
end
end
describe "HTTP/1.x handling over TCP" do
setup :http_server
setup :finch_http1_client
test "sets up the HTTP 1.x handler", %{base: base, finch_name: finch_name} do
{:ok, response} = Finch.build(:get, base <> "/report_version") |> Finch.request(finch_name)
assert response.status == 200
assert response.body == "HTTP/1.1 http"
end
end
describe "HTTP/1.x handling over SSL" do
setup :https_server
setup :finch_http1_client
test "sets up the HTTP 1.x handler", %{base: base, finch_name: finch_name} do
{:ok, response} = Finch.build(:get, base <> "/report_version") |> Finch.request(finch_name)
assert response.status == 200
assert response.body == "HTTP/1.1 https"
end
@tag :capture_log
test "closes with an error if HTTP/1.1 is attempted over an h2 ALPN connection", context do
socket = SimpleH2Client.tls_client(context)
:ssl.send(socket, "GET / HTTP/1.1\r\n")
assert :ssl.recv(socket, 0) == {:error, :closed}
end
end
describe "HTTP/2 handling over TCP" do
setup :http_server
setup :finch_h2_client
test "sets up the HTTP/2 handler", %{base: base, finch_name: finch_name} do
{:ok, response} = Finch.build(:get, base <> "/report_version") |> Finch.request(finch_name)
assert response.status == 200
assert response.body == "HTTP/2 http"
end
end
describe "HTTP/2 handling over SSL" do
setup :https_server
setup :finch_h2_client
test "sets up the HTTP/2 handler", %{base: base, finch_name: finch_name} do
{:ok, response} = Finch.build(:get, base <> "/report_version") |> Finch.request(finch_name)
assert response.status == 200
assert response.body == "HTTP/2 https"
end
@tag :capture_log
test "closes with an error if HTTP2 is attempted over a HTTP/1.1 connection", context do
socket = SimpleHTTP1Client.tls_client(context, ["http/1.1"])
:ssl.send(socket, "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n")
assert :ssl.recv(socket, 0) == {:error, :closed}
end
end
describe "unknown protocols" do
setup :http_server
setup :finch_http1_client
test "TLS connection is made to a TCP server", %{base: base, finch_name: finch_name} do
warnings =
capture_log(fn ->
base = String.replace_prefix(base, "http", "https")
_ = Finch.build(:get, base <> "/report_version") |> Finch.request(finch_name)
end)
assert warnings =~ "Connection that looks like TLS received on a clear channel"
end
end
end