Skip to content

Commit e3b9496

Browse files
lhoguinmergify[bot]
authored andcommitted
Web-MQTT: Add a test for HTTP/2 Websocket
(cherry picked from commit 3bad41f)
1 parent 7fa96f6 commit e3b9496

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

deps/rabbitmq_web_mqtt/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ export BUILD_WITHOUT_QUIC
1919

2020
LOCAL_DEPS = ssl
2121
DEPS = rabbit cowboy rabbitmq_mqtt
22-
TEST_DEPS = emqtt rabbitmq_ct_helpers rabbitmq_ct_client_helpers rabbitmq_management rabbitmq_stomp rabbitmq_consistent_hash_exchange
22+
TEST_DEPS = gun emqtt rabbitmq_ct_helpers rabbitmq_ct_client_helpers rabbitmq_management rabbitmq_stomp rabbitmq_consistent_hash_exchange
2323

2424
PLT_APPS += rabbitmq_cli elixir cowlib ssl
2525

2626
# FIXME: Add Ranch as a BUILD_DEPS to be sure the correct version is picked.
2727
# See rabbitmq-components.mk.
2828
BUILD_DEPS += ranch
2929

30+
dep_gun = hex 2.2.0
3031
dep_emqtt = git https://github.com/emqx/emqtt.git 1.14.6
3132

3233
DEP_EARLY_PLUGINS = rabbit_common/mk/rabbitmq-early-plugin.mk

deps/rabbitmq_web_mqtt/test/web_mqtt_system_SUITE.erl

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ groups() ->
2424
,unacceptable_data_type
2525
,handle_invalid_packets
2626
,duplicate_connect
27+
,wss_http2
2728
]}
2829
].
2930

@@ -36,7 +37,25 @@ init_per_suite(Config) ->
3637
{rmq_nodename_suffix, ?MODULE},
3738
{protocol, "ws"}
3839
]),
39-
rabbit_ct_helpers:run_setup_steps(Config1,
40+
Config2 = rabbit_ct_helpers:run_setup_steps(Config1),
41+
{rmq_certsdir, CertsDir} = proplists:lookup(rmq_certsdir, Config2),
42+
Config3 = rabbit_ct_helpers:merge_app_env(
43+
Config2,
44+
{rabbitmq_web_mqtt,
45+
[{ssl_config,
46+
[{cacertfile, filename:join([CertsDir, "testca", "cacert.pem"])},
47+
{certfile, filename:join([CertsDir, "server", "cert.pem"])},
48+
{keyfile, filename:join([CertsDir, "server", "key.pem"])},
49+
%% We only want to ensure HTTP/2 Websocket is working.
50+
{fail_if_no_peer_cert, false},
51+
{versions, ['tlsv1.3']},
52+
%% We hard code this port number here because it will be computed later by
53+
%% rabbit_ct_broker_helpers:init_tcp_port_numbers/3 when we start the broker.
54+
%% (The alternative is to first start the broker, stop the rabbitmq_web_amqp app,
55+
%% configure tls_config, and then start the app again.)
56+
{port, 21010}
57+
]}]}),
58+
rabbit_ct_helpers:run_setup_steps(Config3,
4059
rabbit_ct_broker_helpers:setup_steps() ++
4160
rabbit_ct_client_helpers:setup_steps()).
4261

@@ -114,6 +133,26 @@ duplicate_connect(Config) ->
114133
after 500 -> ct:fail("expected web socket to exit")
115134
end.
116135

136+
wss_http2(Config) ->
137+
{ok, _} = application:ensure_all_started(gun),
138+
Port = rabbit_ct_broker_helpers:get_node_config(Config, 0, tcp_port_web_mqtt_tls),
139+
{ok, ConnPid} = gun:open("localhost", Port, #{
140+
transport => tls,
141+
tls_opts => [{verify, verify_none}],
142+
protocols => [http2],
143+
http2_opts => #{notify_settings_changed => true},
144+
ws_opts => #{protocols => [{<<"mqtt">>, gun_ws_h}]}
145+
}),
146+
{ok, http2} = gun:await_up(ConnPid),
147+
{notify, settings_changed, #{enable_connect_protocol := true}}
148+
= gun:await(ConnPid, undefined),
149+
StreamRef = gun:ws_upgrade(ConnPid, "/ws", []),
150+
{upgrade, [<<"websocket">>], _} = gun:await(ConnPid, StreamRef),
151+
gun:ws_send(ConnPid, StreamRef, {binary, rabbit_ws_test_util:mqtt_3_1_1_connect_packet()}),
152+
{ws, {binary, _P}} = gun:await(ConnPid, StreamRef),
153+
eventually(?_assertEqual(1, num_mqtt_connections(Config, 0))),
154+
ok.
155+
117156
%% -------------------------------------------------------------------
118157
%% Internal helpers
119158
%% -------------------------------------------------------------------

0 commit comments

Comments
 (0)