Skip to content

Commit 47731ed

Browse files
authored
Merge pull request #4361 from esl/handle-privacy-iq-to-user
Treat privacy IQs send to users as regular stanzas
2 parents f7a862c + 5d2244a commit 47731ed

File tree

4 files changed

+60
-7
lines changed

4 files changed

+60
-7
lines changed

Diff for: big_tests/tests/mod_blocking_SUITE.erl

+21-4
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525

2626
-import(config_parser_helper, [mod_config_with_auto_backend/1]).
2727

28-
-define(SLEEP_TIME, 50).
29-
3028
%%--------------------------------------------------------------------
3129
%% Suite configuration
3230
%%--------------------------------------------------------------------
@@ -71,7 +69,8 @@ effect_test_cases() ->
7169
messages_from_any_blocked_resource_dont_arrive,
7270
blocking_doesnt_interfere,
7371
blocking_propagates_to_resources,
74-
iq_reply_doesnt_crash_user_process
72+
iq_reply_doesnt_crash_user_process,
73+
iq_with_to_attribute_is_treated_as_regular_one
7574
].
7675

7776
offline_test_cases() ->
@@ -84,7 +83,6 @@ offline_test_cases() ->
8483

8584
error_test_cases() ->
8685
[blocker_cant_send_to_blockee].
87-
8886
push_test_cases() ->
8987
[block_push_sent].
9088

@@ -412,6 +410,25 @@ blocker_cant_send_to_blockee(Config) ->
412410
client_gets_blocking_error(User1)
413411
end).
414412

413+
%% This test checks an edge case where a blocking IQ is sent to another user
414+
%% This isn't allowed by the XEP, but the test ensures MIM handles it correctly
415+
iq_with_to_attribute_is_treated_as_regular_one(Config) ->
416+
escalus:fresh_story(
417+
Config, [{alice, 1}, {bob, 1}, {kate, 1}],
418+
fun(User1, User2, User3) ->
419+
%% Alice sends a blocking IQ addressed to Bob
420+
Blockee = escalus_utils:jid_to_lower(escalus_client:short_jid(User3)),
421+
St = block_users_stanza([Blockee]),
422+
StanzaBlock = escalus_stanza:to(St, User2),
423+
escalus_client:send(User1, StanzaBlock),
424+
%% Bob should receive the blocking IQ sent by Alice
425+
StanzaReceived = escalus:wait_for_stanza(User2),
426+
escalus:assert(is_iq_set, StanzaReceived),
427+
%% Alice shouldn't receive any response from the server
428+
[] = escalus:wait_for_stanzas(User1, 1, 100),
429+
escalus_assert:has_no_stanzas(User1)
430+
end).
431+
415432
block_push_sent(Config) ->
416433
%% make sure privacy list push arrives to all the user's resources
417434
escalus:fresh_story(

Diff for: big_tests/tests/privacy_SUITE.erl

+21-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ blocking_test_cases() ->
7676
newly_blocked_presense_jid_by_new_list,
7777
newly_blocked_presense_jid_by_list_change,
7878
newly_blocked_presence_not_notify_self,
79-
iq_reply_doesnt_crash_user_process
79+
iq_reply_doesnt_crash_user_process,
80+
iq_with_to_attribute_is_treated_as_regular_one
8081
].
8182

8283
allowing_test_cases() ->
@@ -636,6 +637,25 @@ iq_reply_doesnt_crash_user_process(Config) ->
636637
<<"Hello, Alice">>)
637638
end).
638639

640+
%% This test checks an edge case where a privacy IQ is sent to another user
641+
%% This isn't allowed by the XEP, but the test ensures MIM handles it correctly
642+
iq_with_to_attribute_is_treated_as_regular_one(Config) ->
643+
escalus:fresh_story(
644+
Config, [{alice, 1}, {bob, 1}, {kate, 1}],
645+
fun(Alice, Bob, Kate) ->
646+
%% Alice sends a privacy IQ addressed to Bob
647+
St = escalus_stanza:privacy_set_list(
648+
privacy_helper:privacy_list({<<"deny_jid_all">>, Kate})),
649+
StanzaPriv = escalus_stanza:to(St, Bob),
650+
escalus_client:send(Alice, StanzaPriv),
651+
%% Bob should receive the privacy IQ sent by Alice
652+
StanzaReceived = escalus:wait_for_stanza(Bob),
653+
escalus:assert(is_iq_set, StanzaReceived),
654+
%% Alice shouldn't receive any response from the server
655+
[] = escalus:wait_for_stanzas(Alice, 1, 100),
656+
escalus_assert:has_no_stanzas(Alice)
657+
end).
658+
639659
block_jid_iq(Config) ->
640660
escalus:fresh_story(Config, [{alice, 1}, {bob, 1}], fun(Alice, Bob) ->
641661

Diff for: src/privacy/mod_blocking.erl

+9-1
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,19 @@ c2s_hooks(HostType) ->
6363
user_send_iq(Acc, #{c2s_data := StateData}, #{host_type := HostType}) ->
6464
case mongoose_iq:info(Acc) of
6565
{#iq{xmlns = ?NS_BLOCKING, type = Type} = IQ, Acc1} when Type == get; Type == set ->
66-
mod_privacy:do_user_send_iq(Acc1, StateData, HostType, IQ);
66+
handle_blocking_iq(Acc1, StateData, HostType, IQ);
6767
_ ->
6868
{ok, Acc}
6969
end.
7070

71+
handle_blocking_iq(Acc1, StateData, HostType, IQ) ->
72+
case exml_query:attr(mongoose_acc:element(Acc1), <<"to">>) of
73+
undefined ->
74+
mod_privacy:do_user_send_iq(Acc1, StateData, HostType, IQ);
75+
_ ->
76+
{ok, Acc1}
77+
end.
78+
7179
-spec foreign_event(mongoose_acc:t(), mongoose_c2s_hooks:params(), gen_hook:extra()) ->
7280
mongoose_c2s_hooks:result().
7381
foreign_event(Acc, #{c2s_data := StateData,

Diff for: src/privacy/mod_privacy.erl

+9-1
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,19 @@ user_send_message_or_presence(Acc, #{c2s_data := StateData}, _Extra) ->
133133
user_send_iq(Acc, #{c2s_data := StateData}, #{host_type := HostType}) ->
134134
case mongoose_iq:info(Acc) of
135135
{#iq{xmlns = ?NS_PRIVACY, type = Type} = IQ, Acc1} when Type == get; Type == set ->
136-
do_user_send_iq(Acc1, StateData, HostType, IQ);
136+
handle_privacy_iq(Acc1, StateData, HostType, IQ);
137137
_ ->
138138
do_privacy_check_send(Acc, StateData)
139139
end.
140140

141+
handle_privacy_iq(Acc1, StateData, HostType, IQ) ->
142+
case exml_query:attr(mongoose_acc:element(Acc1), <<"to">>) of
143+
undefined ->
144+
do_user_send_iq(Acc1, StateData, HostType, IQ);
145+
_ ->
146+
do_privacy_check_send(Acc1, StateData)
147+
end.
148+
141149
-spec user_receive_message(mongoose_acc:t(), mongoose_c2s_hooks:params(), gen_hook:extra()) ->
142150
mongoose_c2s_hooks:result().
143151
user_receive_message(Acc, #{c2s_data := StateData}, _Extra) ->

0 commit comments

Comments
 (0)