Skip to content

Commit

Permalink
Fixes mongooseimctl suite
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamil Waz committed Oct 4, 2022
1 parent 121cdf9 commit 44e943d
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion big_tests/default.spec
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
{suites, "tests", mod_version_SUITE}.
{suites, "tests", mongoose_cassandra_SUITE}.
{suites, "tests", mongoose_elasticsearch_SUITE}.
% {suites, "tests", mongooseimctl_SUITE}.
{suites, "tests", mongooseimctl_SUITE}.
% {suites, "tests", muc_SUITE}.
{suites, "tests", muc_http_api_SUITE}.
{suites, "tests", muc_light_SUITE}.
Expand Down
2 changes: 1 addition & 1 deletion big_tests/dynamic_domains.spec
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@

% {suites, "tests", mod_version_SUITE}.

% {suites, "tests", mongooseimctl_SUITE}.
{suites, "tests", mongooseimctl_SUITE}.

% {suites, "tests", muc_SUITE}.
% {skip_groups, "tests", muc_SUITE,
Expand Down
6 changes: 4 additions & 2 deletions big_tests/tests/mongooseimctl_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,10 @@ ban_account(Config) ->

{ok, Mike} = escalus_client:start_for(Config, mike, <<"newres">>),
{_, 0} = mongooseimctl("ban_account", [User, Domain, "SomeReason"], Config),
Res = escalus:wait_for_stanza(Mike),
io:format("Res ~p~n", [Res]),
escalus:assert(is_stream_error, [<<"conflict">>, <<"SomeReason">>],
escalus:wait_for_stanza(Mike)),
Res),
{error, {connection_step_failed, _, _}} = escalus_client:start_for(Config, mike, <<"newres2">>),
mongooseimctl("change_password", [User, Domain, Pass], Config),
escalus_connection:wait_for_close(Mike, 1000),
Expand Down Expand Up @@ -1071,7 +1073,7 @@ send_stanza(Config) ->
BobJID = <<BobName/binary, $@, Domain/binary, $/,
(escalus_client:resource(Bob))/binary>>,

Stanza = Stanza = create_stanza(Alice, BobJID),
Stanza = create_stanza(Alice, BobJID),
{_, 0} = mongooseimctl("send_stanza_c2s",
[BobName, Domain, Resource, Stanza],
Config),
Expand Down
3 changes: 1 addition & 2 deletions src/admin_extra/service_admin_extra_stanza.erl
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,9 @@ send_stanza_c2s(Username, Host, Resource, Stanza) ->
_ ->
case exml:parse(Stanza) of
{ok, XmlEl} ->
p1_fsm_old:send_event(C2sPid, {xmlstreamelement, XmlEl}),
C2sPid ! XmlEl,
{ok, "Stanza has been sent"};
{error, _} ->
{bad_stanza, "Stanza is incorrect"}
end
end.

15 changes: 13 additions & 2 deletions src/c2s/mongoose_c2s.erl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
-export([start_link/2]).
-export([get_host_type/1, get_lserver/1, get_sid/1, get_jid/1,
get_mod_state/2, remove_mod_state/2,
get_ip/1, get_socket/1, get_lang/1, get_stream_id/1]).
get_ip/1, get_socket/1, get_lang/1, get_stream_id/1,
terminate_session/2]).
-export([filter_mechanism/2, c2s_stream_error/2, maybe_retry_state/1,
reroute/2, stop/2, merge_states/2]).

Expand Down Expand Up @@ -489,6 +490,8 @@ maybe_retry_state(StateData = #c2s_data{listener_opts = LOpts}, C2SState) ->
end.

-spec handle_info(c2s_data(), c2s_state(), term()) -> fsm_res().
handle_info(StateData, C2SState, #xmlel{} = El) ->
handle_c2s_packet(StateData, C2SState, El);
handle_info(StateData, C2SState, {route, Acc}) ->
handle_stanza_to_client(StateData, C2SState, Acc);
handle_info(StateData, C2SState, {route, _From, _To, Acc}) ->
Expand All @@ -508,7 +511,7 @@ handle_info(StateData, _C2SState, replaced) ->
send_trailer(StateData),
{stop, {shutdown, replaced}};
handle_info(StateData, _C2SState, {exit, Reason}) ->
StreamConflict = mongoose_xmpp_errors:stream_conflict(),
StreamConflict = mongoose_xmpp_errors:stream_conflict(StateData#c2s_data.lang, Reason),
send_element_from_server_jid(StateData, StreamConflict),
send_trailer(StateData),
{stop, {shutdown, Reason}};
Expand Down Expand Up @@ -914,3 +917,11 @@ merge_states(S0 = #c2s_data{},
jid = S0#c2s_data.jid,
state_mod = S0#c2s_data.state_mod
}.

-spec terminate_session(jid:jid() | pid() | none, binary()) -> {exit, binary()} | no_session.
terminate_session(none, _Reason) ->
no_session;
terminate_session(#jid{} = Jid, Reason) ->
terminate_session(ejabberd_sm:get_session_pid(Jid), Reason);
terminate_session(Pid, Reason) ->
Pid ! {exit, Reason}.
6 changes: 3 additions & 3 deletions src/ejabberd_sm.erl
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,9 @@ get_vh_session_list(Server) ->

-spec get_node_sessions_number() -> non_neg_integer().
get_node_sessions_number() ->
{value, {active, Active}} = lists:keysearch(active, 1,
supervisor:count_children(ejabberd_c2s_sup)),
Active.
Children = supervisor:which_children(mongoose_listener_sup),
Listeners = [Ref || {Ref, _, _, [mongoose_c2s_listener]} <- Children],
lists:sum([maps:get(active_connections, ranch:info(Ref)) || Ref <- Listeners]).


-spec get_full_session_list() -> [session()].
Expand Down
2 changes: 1 addition & 1 deletion src/mongoose_session_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ kick_session(User, Server, Resource, ReasonText) ->

-spec kick_session(jid:jid(), binary()) -> kick_session_result().
kick_session(JID, ReasonText) ->
case ejabberd_c2s:terminate_session(JID, prepare_reason(ReasonText)) of
case mongoose_c2s:terminate_session(JID, prepare_reason(ReasonText)) of
no_session ->
{no_session, <<"No active session">>};
{exit, ReasonText} ->
Expand Down

0 comments on commit 44e943d

Please sign in to comment.