Skip to content

Commit

Permalink
Merge pull request #3239 from esl/fix/run_undefined_host_type
Browse files Browse the repository at this point in the history
Fix run hook(xmpp_send_element) with undefined host_type for c2s
  • Loading branch information
chrzaszcz authored Sep 2, 2021
2 parents d808448 + 5705f6f commit fb06cf1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ejabberd_c2s.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1651,6 +1651,9 @@ send_element_from_server_jid(Acc, StateData, #xmlel{} = El) ->

%% @doc This is the termination point - from here stanza is sent to the user
-spec send_element(mongoose_acc:t(), exml:element(), state()) -> mongoose_acc:t().
send_element(Acc, El, #state{host_type = undefined} = StateData) ->
Res = do_send_element(El, StateData),
mongoose_acc:set(c2s, send_result, Res, Acc);
send_element(Acc, El, #state{host_type = HostType} = StateData) ->
Acc1 = mongoose_hooks:xmpp_send_element(HostType, Acc, El),
Res = do_send_element(El, StateData),
Expand Down
4 changes: 4 additions & 0 deletions test/ejabberd_c2s_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@ c2s_start_stop_test(_) ->


stream_error_when_invalid_domain(_) ->
ok = meck:new(mongoose_hooks, [passthrough]),
{ok, C2SPid} = given_c2s_started(),

C2Sactions = when_stream_is_opened(C2SPid, stream_header(<<"badhost">>)),
[StreamStart, StreamError, StreamEnd, CloseSocket] = C2Sactions,
History = meck:history(mongoose_hooks),
HookRes = [ok || {_, {mongoose_hooks, xmpp_send_element, [undefined, #{host_type := undefined} | _]}, _} <- History],
?am([], HookRes),
?am({send, [_P,
<<"<?xml version='1.0'?>",
"<stream:stream xmlns='jabber:client' ",
Expand Down

0 comments on commit fb06cf1

Please sign in to comment.