Skip to content

Commit

Permalink
Test that it returns an error if invalid CSI request
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides committed Jan 4, 2023
1 parent f7cd5c1 commit a356ac5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 9 additions & 1 deletion big_tests/tests/xep_0352_csi_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ all_tests() ->
alice_gets_buffered_messages_after_reconnection_with_sm,
alice_gets_buffered_messages_after_stream_resumption,
bob_gets_msgs_from_inactive_alice,
alice_is_inactive_but_sends_sm_req_and_recives_ack
alice_is_inactive_but_sends_sm_req_and_recives_ack,
invalid_csi_request_returns_error
].

suite() ->
Expand Down Expand Up @@ -65,6 +66,13 @@ server_announces_csi(Config) ->
{ok, _Client, Features} = escalus_connection:start(Spec, Steps),
true = proplists:get_value(client_state_indication, Features).

invalid_csi_request_returns_error(Config) ->
escalus:fresh_story(Config, [{alice, 1}], fun(Alice) ->
escalus:send(Alice, csi_stanza(<<"invalid">>)),
Stanza = escalus:wait_for_stanza(Alice),
escalus:assert(is_error, [<<"modify">>, <<"bad-request">>], Stanza)
end).

alice_is_inactive_and_no_stanza_arrived(Config) ->
escalus:fresh_story(Config, [{alice, 1}, {bob, 1}], fun(Alice, Bob) ->
given_client_is_inactive_and_no_messages_arrive(Alice),
Expand Down
7 changes: 6 additions & 1 deletion src/mod_csi.erl
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,12 @@ reroute_unacked_messages(Acc, #{c2s_data := C2SData}, _) ->
handle_csi_request(Acc, Params, #xmlel{name = <<"inactive">>}) ->
handle_inactive_request(Acc, Params);
handle_csi_request(Acc, Params, #xmlel{name = <<"active">>}) ->
handle_active_request(Acc, Params).
handle_active_request(Acc, Params);
handle_csi_request(Acc, _, _) ->
{From, To, El} = mongoose_acc:packet(Acc),
Error = jlib:make_error_reply(El, mongoose_xmpp_errors:bad_request()),
ErrorAcc = mongoose_acc:update_stanza(#{from_jid => From, to_jid => To, element => Error }, Acc),
mongoose_c2s_acc:to_acc(Acc, route, ErrorAcc).

-spec handle_inactive_request(mongoose_acc:t(), mongoose_c2s_hooks:params()) -> mongoose_acc:t().
handle_inactive_request(Acc, #{c2s_data := C2SData} = _Params) ->
Expand Down

0 comments on commit a356ac5

Please sign in to comment.