Skip to content

Commit 3d0b4b0

Browse files
committed
Upgrade tests to bandit 1.4.0 (nb: library still supports older Bandits)
1 parent 2d6d4d3 commit 3d0b4b0

File tree

3 files changed

+62
-19
lines changed

3 files changed

+62
-19
lines changed

mix.lock

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
%{
2-
"bandit": {:hex, :bandit, "0.6.10", "9440d987acbaed18566d45ce324d3bd73f26412e1976342797e6dac863f55a8d", [:mix], [{:hpax, "~> 0.1.1", [hex: :hpax, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:thousand_island, "~> 0.6.1", [hex: :thousand_island, repo: "hexpm", optional: false]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "cf74aa6e02303f900785bf235ae28e21844fd0a4d46aed9c0f41886fc04a143e"},
2+
"bandit": {:hex, :bandit, "1.4.0", "fdf9c4b9e3a2d8579540ff90f74f514e5bec25f8cb1c7ede6fddd409509e5b4b", [:mix], [{:hpax, "~> 0.1.1", [hex: :hpax, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:thousand_island, "~> 1.0", [hex: :thousand_island, repo: "hexpm", optional: false]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "2d068334fe7a4ea17161b875aa112bfa7d62060e8eefb1a1117b2ab6a817e04f"},
33
"bunt": {:hex, :bunt, "0.2.1", "e2d4792f7bc0ced7583ab54922808919518d0e57ee162901a16a1b6664ef3b14", [:mix], [], "hexpm", "a330bfb4245239787b15005e66ae6845c9cd524a288f0d141c148b02603777a5"},
44
"cowboy": {:hex, :cowboy, "2.9.0", "865dd8b6607e14cf03282e10e934023a1bd8be6f6bacf921a7e2a96d800cd452", [:make, :rebar3], [{:cowlib, "2.11.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "2c729f934b4e1aa149aff882f57c6372c15399a20d54f65c8d67bef583021bde"},
55
"cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"},
@@ -15,13 +15,13 @@
1515
"makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"},
1616
"makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"},
1717
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},
18-
"mime": {:hex, :mime, "2.0.3", "3676436d3d1f7b81b5a2d2bd8405f412c677558c81b1c92be58c00562bb59095", [:mix], [], "hexpm", "27a30bf0db44d25eecba73755acf4068cbfe26a4372f9eb3e4ea3a45956bff6b"},
18+
"mime": {:hex, :mime, "2.0.5", "dc34c8efd439abe6ae0343edbb8556f4d63f178594894720607772a041b04b02", [:mix], [], "hexpm", "da0d64a365c45bc9935cc5c8a7fc5e49a0e0f9932a761c55d6c52b142780a05c"},
1919
"nimble_parsec": {:hex, :nimble_parsec, "1.3.1", "2c54013ecf170e249e9291ed0a62e5832f70a476c61da16f6aac6dca0189f2af", [:mix], [], "hexpm", "2682e3c0b2eb58d90c6375fc0cc30bc7be06f365bf72608804fb9cffa5e1b167"},
20-
"plug": {:hex, :plug, "1.14.0", "ba4f558468f69cbd9f6b356d25443d0b796fbdc887e03fa89001384a9cac638f", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "bf020432c7d4feb7b3af16a0c2701455cbbbb95e5b6866132cb09eb0c29adc14"},
20+
"plug": {:hex, :plug, "1.15.3", "712976f504418f6dff0a3e554c40d705a9bcf89a7ccef92fc6a5ef8f16a30a97", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "cc4365a3c010a56af402e0809208873d113e9c38c401cabd88027ef4f5c01fd2"},
2121
"plug_cowboy": {:hex, :plug_cowboy, "2.6.0", "d1cf12ff96a1ca4f52207c5271a6c351a4733f413803488d75b70ccf44aebec2", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "073cf20b753ce6682ed72905cd62a2d4bd9bad1bf9f7feb02a1b8e525bd94fa6"},
22-
"plug_crypto": {:hex, :plug_crypto, "1.2.4", "34c380ef387cc7e8d537854ddd4b7096c79a4397d53587cb80419c782b03fdbc", [:mix], [], "hexpm", "4de415f03faec94d9da9be8c12cb51e9c98cbf66d732b6df669d4562d8e91acc"},
22+
"plug_crypto": {:hex, :plug_crypto, "2.0.0", "77515cc10af06645abbfb5e6ad7a3e9714f805ae118fa1a70205f80d2d70fe73", [:mix], [], "hexpm", "53695bae57cc4e54566d993eb01074e4d894b65a3766f1c43e2c61a1b0f45ea9"},
2323
"ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"},
2424
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
25-
"thousand_island": {:hex, :thousand_island, "0.6.2", "4b87f315b767ed6960d1d4b5aee015522d2d2ba12a14144a7b03e706d945e60b", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "84dde4cc8a876bc5993083153ec90a8c3f2feeb57b4a12b1a3206c929e75e226"},
25+
"thousand_island": {:hex, :thousand_island, "1.3.5", "6022b6338f1635b3d32406ff98d68b843ba73b3aa95cfc27154223244f3a6ca5", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "2be6954916fdfe4756af3239fb6b6d75d0b8063b5df03ba76fd8a4c87849e180"},
2626
"websock": {:hex, :websock, "0.5.3", "2f69a6ebe810328555b6fe5c831a851f485e303a7c8ce6c5f675abeb20ebdadc", [:mix], [], "hexpm", "6105453d7fac22c712ad66fab1d45abdf049868f253cf719b625151460b8b453"},
2727
}

test/websock_adapter/upgrade_validation_test.exs

+29-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ defmodule UpgradeValidationTest do
33

44
test "accepts well formed HTTP/1.1 requests" do
55
conn =
6-
%Plug.Conn{adapter: {Bandit.HTTP1.Adapter, %Bandit.HTTP1.Adapter{version: :"HTTP/1.1"}}}
6+
%Plug.Conn{
7+
adapter:
8+
{Bandit.Adapter,
9+
%Bandit.Adapter{
10+
transport: %Bandit.HTTP1.Socket{version: :"HTTP/1.1"},
11+
opts: %{websocket: []}
12+
}}
13+
}
714
|> Map.put(:method, "GET")
815
|> Map.update!(:req_headers, &[{"host", "server.example.com"} | &1])
916
|> Plug.Conn.put_req_header("upgrade", "WeBsOcKeT")
@@ -17,7 +24,7 @@ defmodule UpgradeValidationTest do
1724

1825
test "accepts well formed HTTP/2 requests" do
1926
conn =
20-
%Plug.Conn{adapter: {Plug.Cowboy.Conn, %{version: :"HTTP/2"}}}
27+
%Plug.Conn{adapter: {Bandit.Adapter, %Bandit.Adapter{transport: %Bandit.HTTP2.Stream{}}}}
2128
|> Map.put(:method, "CONNECT")
2229
|> Plug.Conn.put_req_header("sec-websocket-version", "13")
2330

@@ -27,7 +34,10 @@ defmodule UpgradeValidationTest do
2734

2835
test "does not accept HTTP/1.0 requests" do
2936
conn =
30-
%Plug.Conn{adapter: {Bandit.HTTP1.Adapter, %Bandit.HTTP1.Adapter{version: :"HTTP/1.0"}}}
37+
%Plug.Conn{
38+
adapter:
39+
{Bandit.Adapter, %Bandit.Adapter{transport: %Bandit.HTTP1.Socket{version: :"HTTP/1.0"}}}
40+
}
3141
|> Map.put(:method, "GET")
3242
|> Map.update!(:req_headers, &[{"host", "server.example.com"} | &1])
3343
|> Plug.Conn.put_req_header("upgrade", "WeBsOcKeT")
@@ -45,7 +55,10 @@ defmodule UpgradeValidationTest do
4555

4656
test "does not accept non-GET requests" do
4757
conn =
48-
%Plug.Conn{adapter: {Bandit.HTTP1.Adapter, %Bandit.HTTP1.Adapter{version: :"HTTP/1.1"}}}
58+
%Plug.Conn{
59+
adapter:
60+
{Bandit.Adapter, %Bandit.Adapter{transport: %Bandit.HTTP1.Socket{version: :"HTTP/1.1"}}}
61+
}
4962
|> Map.put(:method, "POST")
5063
|> Map.update!(:req_headers, &[{"host", "server.example.com"} | &1])
5164
|> Plug.Conn.put_req_header("upgrade", "WeBsOcKeT")
@@ -63,7 +76,10 @@ defmodule UpgradeValidationTest do
6376

6477
test "does not accept non-upgrade requests" do
6578
conn =
66-
%Plug.Conn{adapter: {Bandit.HTTP1.Adapter, %Bandit.HTTP1.Adapter{version: :"HTTP/1.1"}}}
79+
%Plug.Conn{
80+
adapter:
81+
{Bandit.Adapter, %Bandit.Adapter{transport: %Bandit.HTTP1.Socket{version: :"HTTP/1.1"}}}
82+
}
6783
|> Map.put(:method, "GET")
6884
|> Map.update!(:req_headers, &[{"host", "server.example.com"} | &1])
6985
|> Plug.Conn.put_req_header("upgrade", "WeBsOcKeT")
@@ -81,7 +97,10 @@ defmodule UpgradeValidationTest do
8197

8298
test "does not accept non-websocket upgrade requests" do
8399
conn =
84-
%Plug.Conn{adapter: {Bandit.HTTP1.Adapter, %Bandit.HTTP1.Adapter{version: :"HTTP/1.1"}}}
100+
%Plug.Conn{
101+
adapter:
102+
{Bandit.Adapter, %Bandit.Adapter{transport: %Bandit.HTTP1.Socket{version: :"HTTP/1.1"}}}
103+
}
85104
|> Map.put(:method, "GET")
86105
|> Map.update!(:req_headers, &[{"host", "server.example.com"} | &1])
87106
|> Plug.Conn.put_req_header("upgrade", "bogus")
@@ -99,7 +118,10 @@ defmodule UpgradeValidationTest do
99118

100119
test "does not accept HTTP/1.1 requests without a version of 13" do
101120
conn =
102-
%Plug.Conn{adapter: {Bandit.HTTP1.Adapter, %Bandit.HTTP1.Adapter{version: :"HTTP/1.1"}}}
121+
%Plug.Conn{
122+
adapter:
123+
{Bandit.Adapter, %Bandit.Adapter{transport: %Bandit.HTTP1.Socket{version: :"HTTP/1.1"}}}
124+
}
103125
|> Map.put(:method, "GET")
104126
|> Map.update!(:req_headers, &[{"host", "server.example.com"} | &1])
105127
|> Plug.Conn.put_req_header("upgrade", "WeBsOcKeT")

test/websock_adapter_test.exs

+28-7
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@ defmodule WebSockAdapterTest do
44
test "upgrades Bandit connections and handles all options" do
55
opts = [compress: true, timeout: 1, max_frame_size: 2, fullsweep_after: 3, other: :ok]
66

7-
%Plug.Conn{adapter: {Bandit.HTTP1.Adapter, adapter}} =
8-
%Plug.Conn{adapter: {Bandit.HTTP1.Adapter, %Bandit.HTTP1.Adapter{version: :"HTTP/1.1"}}}
7+
%Plug.Conn{adapter: {Bandit.Adapter, adapter}} =
8+
%Plug.Conn{
9+
adapter:
10+
{Bandit.Adapter,
11+
%Bandit.Adapter{
12+
transport: %Bandit.HTTP1.Socket{version: :"HTTP/1.1"},
13+
opts: %{websocket: []}
14+
}}
15+
}
916
|> Map.put(:method, "GET")
1017
|> Map.update!(:req_headers, &[{"host", "server.example.com"} | &1])
1118
|> Plug.Conn.put_req_header("upgrade", "WeBsOcKeT")
@@ -14,7 +21,7 @@ defmodule WebSockAdapterTest do
1421
|> Plug.Conn.put_req_header("sec-websocket-version", "13")
1522
|> WebSockAdapter.upgrade(:sock, :arg, opts)
1623

17-
assert adapter.upgrade == {:websocket, {:sock, :arg, opts}}
24+
assert adapter.upgrade == {:websocket, {:sock, :arg, opts}, []}
1825
end
1926

2027
test "upgrades Cowboy connections and handles all options" do
@@ -38,7 +45,14 @@ defmodule WebSockAdapterTest do
3845

3946
test "raises an error on invalid websocket upgrade requests" do
4047
assert_raise WebSockAdapter.UpgradeError, "HTTP method POST unsupported", fn ->
41-
%Plug.Conn{adapter: {Bandit.HTTP1.Adapter, %Bandit.HTTP1.Adapter{version: :"HTTP/1.1"}}}
48+
%Plug.Conn{
49+
adapter:
50+
{Bandit.Adapter,
51+
%Bandit.Adapter{
52+
transport: %Bandit.HTTP1.Socket{version: :"HTTP/1.1"},
53+
opts: %{websocket: []}
54+
}}
55+
}
4256
|> Map.put(:method, "POST")
4357
|> Map.update!(:req_headers, &[{"host", "server.example.com"} | &1])
4458
|> Plug.Conn.put_req_header("upgrade", "WeBsOcKeT")
@@ -50,8 +64,15 @@ defmodule WebSockAdapterTest do
5064
end
5165

5266
test "does not raise an error on invalid websocket upgrade requests if so configured" do
53-
%Plug.Conn{adapter: {Bandit.HTTP1.Adapter, adapter}} =
54-
%Plug.Conn{adapter: {Bandit.HTTP1.Adapter, %Bandit.HTTP1.Adapter{version: :"HTTP/1.1"}}}
67+
%Plug.Conn{adapter: {Bandit.Adapter, adapter}} =
68+
%Plug.Conn{
69+
adapter:
70+
{Bandit.Adapter,
71+
%Bandit.Adapter{
72+
transport: %Bandit.HTTP1.Socket{version: :"HTTP/1.1"},
73+
opts: %{websocket: []}
74+
}}
75+
}
5576
|> Map.put(:method, "POST")
5677
|> Map.update!(:req_headers, &[{"host", "server.example.com"} | &1])
5778
|> Plug.Conn.put_req_header("upgrade", "WeBsOcKeT")
@@ -60,7 +81,7 @@ defmodule WebSockAdapterTest do
6081
|> Plug.Conn.put_req_header("sec-websocket-version", "13")
6182
|> WebSockAdapter.upgrade(:sock, :arg, early_validate_upgrade: false)
6283

63-
assert adapter.upgrade == {:websocket, {:sock, :arg, early_validate_upgrade: false}}
84+
assert adapter.upgrade == {:websocket, {:sock, :arg, early_validate_upgrade: false}, []}
6485
end
6586

6687
test "raises an error on unknown adapter upgrade requests" do

0 commit comments

Comments
 (0)