Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions deps/rabbitmq_web_mqtt/test/web_mqtt_proxy_protocol_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
-include_lib("rabbitmq_ct_helpers/include/rabbit_assert.hrl").

suite() ->
[
Expand Down Expand Up @@ -87,9 +88,8 @@ proxy_protocol_v1(Config) ->
{ok, _} = rfc6455_client:open(WS),
rfc6455_client:send_binary(WS, rabbit_ws_test_util:mqtt_3_1_1_connect_packet()),
{binary, _P} = rfc6455_client:recv(WS),
ConnectionName = rabbit_ct_broker_helpers:rpc(Config, 0,
?MODULE, connection_name, []),
match = re:run(ConnectionName, <<"^192.168.1.1:80 -> 192.168.1.2:81$">>, [{capture, none}]),
await_connection_name_match(
Config, <<"^192.168.1.1:80 -> 192.168.1.2:81$">>),
{close, _} = rfc6455_client:close(WS),
ok.

Expand All @@ -107,14 +107,28 @@ proxy_protocol_v2_local(Config) ->
{ok, _} = rfc6455_client:open(WS),
rfc6455_client:send_binary(WS, rabbit_ws_test_util:mqtt_3_1_1_connect_packet()),
{binary, _P} = rfc6455_client:recv(WS),
ConnectionName = rabbit_ct_broker_helpers:rpc(Config, 0,
?MODULE, connection_name, []),
match = re:run(ConnectionName, <<"^127.0.0.1:\\d+ -> 127.0.0.1:\\d+$">>, [{capture, none}]),
await_connection_name_match(
Config, <<"^127.0.0.1:\\d+ -> 127.0.0.1:\\d+$">>),
{close, _} = rfc6455_client:close(WS),
ok.

connection_name() ->
%% The `connection_created' ETS table is populated asynchronously by
%% the management agent; wait for an entry whose `name' matches the
%% pattern.
await_connection_name_match(Config, Pattern) ->
?awaitMatch(true,
rabbit_ct_broker_helpers:rpc(
Config, 0, ?MODULE, has_connection_name_matching, [Pattern]),
30_000).

has_connection_name_matching(Pattern) ->
Connections = ets:tab2list(connection_created),
{_Key, Values} = lists:nth(1, Connections),
{_, Name} = lists:keyfind(name, 1, Values),
Name.
lists:any(
fun({_Key, Values}) ->
case lists:keyfind(name, 1, Values) of
{_, Name} ->
re:run(Name, Pattern, [{capture, none}]) =:= match;
false ->
false
end
end, Connections).
34 changes: 24 additions & 10 deletions deps/rabbitmq_web_stomp/test/proxy_protocol_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
-include_lib("common_test/include/ct.hrl").

-include_lib("eunit/include/eunit.hrl").
-include_lib("rabbitmq_ct_helpers/include/rabbit_assert.hrl").

suite() ->
[
Expand Down Expand Up @@ -93,9 +94,8 @@ proxy_protocol_v1(Config) ->
Frame = stomp:marshal("CONNECT", [{"login","proxy_test"}, {"passcode", "proxy_test"}], <<>>),
rfc6455_client:send(WS, Frame),
{ok, _P} = rfc6455_client:recv(WS),
ConnectionName = rabbit_ct_broker_helpers:rpc(Config, 0,
?MODULE, connection_name, []),
match = re:run(ConnectionName, <<"^192.168.1.1:80 -> 192.168.1.2:81$">>, [{capture, none}]),
await_connection_name_match(
Config, <<"^192.168.1.1:80 -> 192.168.1.2:81$">>),
{close, _} = rfc6455_client:close(WS),
ok.

Expand All @@ -115,14 +115,28 @@ proxy_protocol_v2_local(Config) ->
Frame = stomp:marshal("CONNECT", [{"login","proxy_test"}, {"passcode", "proxy_test"}], <<>>),
rfc6455_client:send(WS, Frame),
{ok, _P} = rfc6455_client:recv(WS),
ConnectionName = rabbit_ct_broker_helpers:rpc(Config, 0,
?MODULE, connection_name, []),
match = re:run(ConnectionName, <<"^127.0.0.1:\\d+ -> 127.0.0.1:\\d+$">>, [{capture, none}]),
await_connection_name_match(
Config, <<"^127.0.0.1:\\d+ -> 127.0.0.1:\\d+$">>),
{close, _} = rfc6455_client:close(WS),
ok.

connection_name() ->
%% The `connection_created' ETS table is populated asynchronously by
%% the management agent; wait for an entry whose `name' matches the
%% pattern.
await_connection_name_match(Config, Pattern) ->
?awaitMatch(true,
rabbit_ct_broker_helpers:rpc(
Config, 0, ?MODULE, has_connection_name_matching, [Pattern]),
30_000).

has_connection_name_matching(Pattern) ->
Connections = ets:tab2list(connection_created),
{_Key, Values} = lists:nth(1, Connections),
{_, Name} = lists:keyfind(name, 1, Values),
Name.
lists:any(
fun({_Key, Values}) ->
case lists:keyfind(name, 1, Values) of
{_, Name} ->
re:run(Name, Pattern, [{capture, none}]) =:= match;
false ->
false
end
end, Connections).
Loading