Skip to content

Commit

Permalink
Merge pull request #4303 from esl/escalus-ws-changes
Browse files Browse the repository at this point in the history
MongooseIM using new version of escalus
  • Loading branch information
chrzaszcz authored Jul 23, 2024
2 parents 074de4f + 78a1893 commit 65aadba
Show file tree
Hide file tree
Showing 7 changed files with 526 additions and 446 deletions.
3 changes: 2 additions & 1 deletion big_tests/rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
{proper, "1.4.0"},
{gun, "2.1.0"},
{fusco, "0.1.1"},
{escalus, "4.2.12"},
{escalus, {git, "[email protected]:esl/escalus.git", {branch, "ws-stream-management"}}},
% {escalus, "4.2.12"},
{cowboy, "2.12.0"},
{csv, "3.0.3", {pkg, csve}},
{amqp_client, "3.12.14"},
Expand Down
7 changes: 4 additions & 3 deletions big_tests/rebar.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
{pkg,<<"credentials_obfuscation">>,<<"3.4.0">>},
1},
{<<"csv">>,{pkg,<<"csve">>,<<"3.0.3">>},0},
{<<"escalus">>,{pkg,<<"escalus">>,<<"4.2.12">>},0},
{<<"escalus">>,
{git,"[email protected]:esl/escalus.git",
{ref,"f99d6efe1028f645d8a17c9ab3fb8e4adab69a76"}},
0},
{<<"esip">>,{pkg,<<"esip">>,<<"1.0.52">>},0},
{<<"exml">>,{pkg,<<"hexml">>,<<"3.4.1">>},0},
{<<"fast_pbkdf2">>,{pkg,<<"fast_pbkdf2">>,<<"1.0.5">>},2},
Expand Down Expand Up @@ -41,7 +44,6 @@
{<<"cowlib">>, <<"DB8F7505D8332D98EF50A3EF34B34C1AFDDEC7506E4EE4DD4A3A266285D282CA">>},
{<<"credentials_obfuscation">>, <<"34E18B126B3AEFD6E8143776FBE1CECEEA6792307C99AC5EE8687911F048CFD7">>},
{<<"csv">>, <<"69E7D9B3FDC72016644368762C6A3E6CBFEB85BCCADBF1BD99AB6C827E360E04">>},
{<<"escalus">>, <<"D0390EB227D4B19F5EA85CAE722F3BD9891DE054EBF1C154078D5203C07F7972">>},
{<<"esip">>, <<"A2840287C493A4280E6FBA57A257706843B025C315875E38B03FD07190E22DBA">>},
{<<"exml">>, <<"9581FE6512D9772C61BBE611CD4A8E5BB90B4D4481275325EC520F7A931A9393">>},
{<<"fast_pbkdf2">>, <<"6045138C4C209FC8222A0B18B2CB1D7BD7407EF4ADAD0F14C5E0F7F4726E3E41">>},
Expand Down Expand Up @@ -73,7 +75,6 @@
{<<"cowlib">>, <<"E1E1284DC3FC030A64B1AD0D8382AE7E99DA46C3246B815318A4B848873800A4">>},
{<<"credentials_obfuscation">>, <<"738ACE0ED5545D2710D3F7383906FC6F6B582D019036E5269C4DBD85DBCED566">>},
{<<"csv">>, <<"741D1A55AABADAA3E0FE13051050101A73E90C4570B9F9403A939D9546813521">>},
{<<"escalus">>, <<"BE52DAAEDE0D920F100BA1AAA43220ECA070F41E1BB52472C192F2973C9B424D">>},
{<<"esip">>, <<"6F00165395900500AA262CE0297162D93931C78C1464D89FD0EDC6E3D6BC011F">>},
{<<"exml">>, <<"D8E7894E2544402B4986EEB2443C15B51B14F686266F091DBF2777D1D99A2FA2">>},
{<<"fast_pbkdf2">>, <<"BC3B5A3CAB47AD114FF8BB815FEDE62A6187ACD14D8B37412F2AF8236A089CEF">>},
Expand Down
5 changes: 2 additions & 3 deletions big_tests/tests/sasl_external_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,10 @@ generate_user(C, User, Transport) ->
{versions, ['tlsv1.2']},
{certfile, maps:get(cert, UserCert)},
{keyfile, maps:get(key, UserCert)}]}],
Common ++ transport_specific_options(Transport)
++ [{port, ct:get_config({hosts, mim, c2s_port})}].
Common ++ transport_specific_options(Transport).

transport_specific_options(escalus_tcp) ->
[{starttls, required}];
[{starttls, required}, {port, ct:get_config({hosts, mim, c2s_port})}];
transport_specific_options(_) ->
[{port, ct:get_config({hosts, mim, cowboy_secure_port})},
{ssl, true}].
Expand Down
931 changes: 496 additions & 435 deletions big_tests/tests/sm_SUITE.erl

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion big_tests/tests/sm_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,13 @@ send_initial_presence(User) ->

process_initial_stanza(User) ->
send_initial_presence(User),
escalus:assert(is_presence, escalus:wait_for_stanza(User)).
Stanza = escalus:wait_for_stanza(User),
case escalus_pred:is_iq(Stanza) of
true ->
Stanza2 = escalus:wait_for_stanza(User),
escalus:assert(is_presence, Stanza2);
false -> escalus:assert(is_presence, Stanza)
end.

send_messages(Bob, Alice, Texts) ->
[escalus:send(Bob, escalus_stanza:chat_to(Alice, Text))
Expand Down
4 changes: 2 additions & 2 deletions src/c2s/mongoose_c2s.erl
Original file line number Diff line number Diff line change
Expand Up @@ -637,10 +637,10 @@ handle_info(StateData, _C2SState, {TcpOrSSl, _Socket, _Packet} = SocketData)
when TcpOrSSl =:= tcp; TcpOrSSl =:= ssl ->
handle_socket_data(StateData, SocketData);
handle_info(StateData, C2SState, {Closed, _Socket} = SocketData)
when Closed =:= tcp_closed; Closed =:= ssl_closed ->
when Closed =:= tcp_closed; Closed =:= ssl_closed; Closed =:= websockets_closed ->
handle_socket_closed(StateData, C2SState, SocketData);
handle_info(StateData, C2SState, {Error, _Socket} = SocketData)
when Error =:= tcp_error; Error =:= ssl_error ->
when Error =:= tcp_error; Error =:= ssl_error; Error =:= websockets_error ->
handle_socket_error(StateData, C2SState, SocketData);
handle_info(StateData, C2SState, Info) ->
handle_foreign_event(StateData, C2SState, info, Info).
Expand Down
14 changes: 13 additions & 1 deletion src/mod_websockets.erl
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,19 @@ init(Req, Opts = #{timeout := Timeout}) ->
%% upgrade protocol
{cowboy_websocket, Req1, AllModOpts, #{idle_timeout => Timeout}}.

terminate(_Reason, _Req, _State) ->
terminate(_Reason, _Req, #ws_state{fsm_pid = undefined} = State) ->
ok;
terminate(Reason, _Req, #ws_state{fsm_pid = FSM} = State) when Reason =:= normal;
Reason =:= stop;
Reason =:= timeout;
Reason =:= remote ->
FSM ! {websockets_closed, undefined},
ok;
terminate({remote, _, _}, _Req, #ws_state{fsm_pid = FSM} = State) ->
FSM ! {websockets_closed, undefined},
ok;
terminate(Reason, _Req, #ws_state{fsm_pid = FSM} = State) ->
FSM ! {websockets_error, undefined},
ok.

%%--------------------------------------------------------------------
Expand Down

0 comments on commit 65aadba

Please sign in to comment.