Skip to content

Commit e50bf70

Browse files
committed
Web-STOMP: Add a test for HTTP/2 Websocket
1 parent 3bad41f commit e50bf70

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

deps/rabbitmq_web_stomp/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,20 @@ define PROJECT_APP_EXTRA_KEYS
2020
endef
2121

2222
DEPS = cowboy rabbit_common rabbit rabbitmq_stomp
23-
TEST_DEPS = rabbitmq_ct_helpers rabbitmq_ct_client_helpers
23+
TEST_DEPS = gun rabbitmq_ct_helpers rabbitmq_ct_client_helpers
2424

2525
PLT_APPS += cowlib
2626

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

31+
dep_gun = hex 2.2.0
32+
3133
DEP_EARLY_PLUGINS = rabbit_common/mk/rabbitmq-early-plugin.mk
3234
DEP_PLUGINS = rabbit_common/mk/rabbitmq-plugin.mk
3335

3436
include ../../rabbitmq-components.mk
3537
include ../../erlang.mk
3638

37-
CT_HOOKS = rabbit_ct_hook
39+
CT_HOOKS = rabbit_ct_hook

deps/rabbitmq_web_stomp/test/cowboy_websocket_SUITE.erl

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ groups() ->
2727
pubsub_binary,
2828
sub_non_existent,
2929
disconnect,
30-
http_auth
30+
http_auth,
31+
wss_http2
3132
]},
3233
%% rabbitmq/rabbitmq-web-stomp#110
3334
{default_login_enabled, [],
@@ -48,7 +49,25 @@ init_per_suite(Config) ->
4849
[{rmq_nodename_suffix, ?MODULE},
4950
{protocol, "ws"}]),
5051
rabbit_ct_helpers:log_environment(),
51-
rabbit_ct_helpers:run_setup_steps(Config1,
52+
Config2 = rabbit_ct_helpers:run_setup_steps(Config1),
53+
{rmq_certsdir, CertsDir} = proplists:lookup(rmq_certsdir, Config2),
54+
Config3 = rabbit_ct_helpers:merge_app_env(
55+
Config2,
56+
{rabbitmq_web_stomp,
57+
[{ssl_config,
58+
[{cacertfile, filename:join([CertsDir, "testca", "cacert.pem"])},
59+
{certfile, filename:join([CertsDir, "server", "cert.pem"])},
60+
{keyfile, filename:join([CertsDir, "server", "key.pem"])},
61+
%% We only want to ensure HTTP/2 Websocket is working.
62+
{fail_if_no_peer_cert, false},
63+
{versions, ['tlsv1.3']},
64+
%% We hard code this port number here because it will be computed later by
65+
%% rabbit_ct_broker_helpers:init_tcp_port_numbers/3 when we start the broker.
66+
%% (The alternative is to first start the broker, stop the rabbitmq_web_amqp app,
67+
%% configure tls_config, and then start the app again.)
68+
{port, 21014}
69+
]}]}),
70+
rabbit_ct_helpers:run_setup_steps(Config3,
5271
rabbit_ct_broker_helpers:setup_steps()).
5372

5473
end_per_suite(Config) ->
@@ -286,3 +305,23 @@ Protocol = ?config(protocol, Config),
286305
{close, _} = rfc6455_client:close(WS3),
287306

288307
ok.
308+
309+
wss_http2(Config) ->
310+
{ok, _} = application:ensure_all_started(gun),
311+
Port = rabbit_ct_broker_helpers:get_node_config(Config, 0, tcp_port_web_stomp_tls),
312+
{ok, ConnPid} = gun:open("localhost", Port, #{
313+
transport => tls,
314+
tls_opts => [{verify, verify_none}],
315+
protocols => [http2],
316+
http2_opts => #{notify_settings_changed => true},
317+
ws_opts => #{protocols => [{<<"v12.stomp">>, gun_ws_h}]}
318+
}),
319+
{ok, http2} = gun:await_up(ConnPid),
320+
{notify, settings_changed, #{enable_connect_protocol := true}}
321+
= gun:await(ConnPid, undefined),
322+
StreamRef = gun:ws_upgrade(ConnPid, "/ws", []),
323+
{upgrade, [<<"websocket">>], _} = gun:await(ConnPid, StreamRef),
324+
gun:ws_send(ConnPid, StreamRef, {text, stomp:marshal("CONNECT", [{"login","guest"}, {"passcode", "guest"}])}),
325+
{ws, {text, P}} = gun:await(ConnPid, StreamRef),
326+
{<<"CONNECTED">>, _, <<>>} = stomp:unmarshal(P),
327+
ok.

0 commit comments

Comments
 (0)