Skip to content

Commit 249ba9e

Browse files
authored
Merge pull request #4475 from esl/pep-disco-fix
Properly handle Account Owner Service Discovery request
2 parents d2cd98a + ac003f9 commit 249ba9e

File tree

2 files changed

+55
-79
lines changed

2 files changed

+55
-79
lines changed

big_tests/tests/pep_SUITE.erl

+40-13
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
-export([
2222
disco_test/1,
2323
disco_sm_test/1,
24+
disco_sm_node_test/1,
2425
disco_sm_items_test/1,
26+
disco_sm_items_node_test/1,
2527
pep_caps_test/1,
2628
publish_and_notify_test/1,
2729
auto_create_with_publish_options_test/1,
@@ -68,7 +70,9 @@ groups() ->
6870
[
6971
disco_test,
7072
disco_sm_test,
73+
disco_sm_node_test,
7174
disco_sm_items_test,
75+
disco_sm_items_node_test,
7276
pep_caps_test,
7377
publish_and_notify_test,
7478
auto_create_with_publish_options_test,
@@ -148,20 +152,39 @@ disco_test(Config) ->
148152
end).
149153

150154
disco_sm_test(Config) ->
155+
disco_sm_test(Config, undefined).
156+
157+
disco_sm_node_test(Config) ->
158+
disco_sm_test(Config, random_node_ns()).
159+
160+
disco_sm_test(Config, Node) ->
151161
escalus:fresh_story(
152-
Config,
153-
[{alice, 1}],
154-
fun(Alice) ->
155-
AliceJid = escalus_client:short_jid(Alice),
156-
escalus:send(Alice, escalus_stanza:disco_info(AliceJid)),
157-
Stanza = escalus:wait_for_stanza(Alice),
158-
?assertNot(escalus_pred:has_identity(<<"pubsub">>, <<"service">>, Stanza)),
159-
escalus:assert(has_identity, [<<"pubsub">>, <<"pep">>], Stanza),
160-
escalus:assert(has_feature, [?NS_PUBSUB], Stanza),
161-
escalus:assert(is_stanza_from, [AliceJid], Stanza)
162-
end).
162+
Config,
163+
[{alice, 1}],
164+
fun(Alice) ->
165+
AliceJid = escalus_client:short_jid(Alice),
166+
Disco =
167+
case Node of
168+
undefined ->
169+
escalus_stanza:disco_info(AliceJid);
170+
_ ->
171+
escalus_stanza:disco_info(AliceJid, Node)
172+
end,
173+
escalus:send(Alice, Disco),
174+
Stanza = escalus:wait_for_stanza(Alice),
175+
?assertNot(escalus_pred:has_identity(<<"pubsub">>, <<"service">>, Stanza)),
176+
escalus:assert(has_identity, [<<"pubsub">>, <<"pep">>], Stanza),
177+
escalus:assert(has_feature, [?NS_PUBSUB], Stanza),
178+
escalus:assert(is_stanza_from, [AliceJid], Stanza)
179+
end).
163180

164181
disco_sm_items_test(Config) ->
182+
disco_sm_items_test(Config, false).
183+
184+
disco_sm_items_node_test(Config) ->
185+
disco_sm_items_test(Config, true).
186+
187+
disco_sm_items_test(Config, UseNode) ->
165188
NodeNS = random_node_ns(),
166189
escalus:fresh_story(
167190
Config,
@@ -170,7 +193,11 @@ disco_sm_items_test(Config) ->
170193
AliceJid = escalus_client:short_jid(Alice),
171194

172195
%% Node not present yet
173-
escalus:send(Alice, escalus_stanza:disco_items(AliceJid)),
196+
DiscoStanza = case UseNode of
197+
true -> escalus_stanza:disco_items(AliceJid, NodeNS);
198+
false -> escalus_stanza:disco_items(AliceJid)
199+
end,
200+
escalus:send(Alice, DiscoStanza),
174201
Stanza1 = escalus:wait_for_stanza(Alice),
175202
Query1 = exml_query:subelement(Stanza1, <<"query">>),
176203
?assertEqual(undefined, exml_query:subelement_with_attr(Query1, <<"node">>, NodeNS)),
@@ -180,7 +207,7 @@ disco_sm_items_test(Config) ->
180207
pubsub_tools:publish(Alice, <<"item1">>, {pep, NodeNS}, []),
181208

182209
%% Node present
183-
escalus:send(Alice, escalus_stanza:disco_items(AliceJid)),
210+
escalus:send(Alice, DiscoStanza),
184211
Stanza2 = escalus:wait_for_stanza(Alice),
185212
Query2 = exml_query:subelement(Stanza2, <<"query">>),
186213
Item = exml_query:subelement_with_attr(Query2, <<"node">>, NodeNS),

src/pubsub/mod_pubsub.erl

+15-66
Original file line numberDiff line numberDiff line change
@@ -650,34 +650,14 @@ disco_local_features(Acc, _, _) ->
650650
Acc :: mongoose_disco:identity_acc(),
651651
Params :: map(),
652652
Extra :: gen_hook:extra().
653-
disco_sm_identity(Acc = #{from_jid := From, to_jid := To, node := Node}, _, _) ->
654-
Identities = disco_identity(jid:to_lower(jid:to_bare(To)), Node, From),
653+
disco_sm_identity(Acc = #{from_jid := From, to_jid := To}, _, _) ->
654+
Identities = disco_identity(jid:to_lower(jid:to_bare(To)), From),
655655
{ok, mongoose_disco:add_identities(Identities, Acc)}.
656656

657-
disco_identity(error, _Node, _From) ->
657+
disco_identity(error, _From) ->
658658
[];
659-
disco_identity(_Host, <<>>, _From) ->
660-
[pep_identity()];
661-
disco_identity(Host, Node, From) ->
662-
Action = fun (#pubsub_node{id = Nidx, type = Type, options = Options, owners = Owners}) ->
663-
case get_allowed_items_call(Host, Nidx, From, Type, Options, Owners) of
664-
{result, _} ->
665-
{result, [pep_identity(), pep_identity(Options)]};
666-
_ ->
667-
{result, []}
668-
end
669-
end,
670-
case dirty(Host, Node, Action, ?FUNCTION_NAME) of
671-
{result, {_, Result}} -> Result;
672-
_ -> []
673-
end.
674-
675-
pep_identity(Options) ->
676-
Identity = pep_identity(),
677-
case get_option(Options, title) of
678-
false -> Identity;
679-
[Title] -> Identity#{name => Title}
680-
end.
659+
disco_identity(_Host, _From) ->
660+
[pep_identity()].
681661

682662
pep_identity() ->
683663
#{category => <<"pubsub">>, type => <<"pep">>}.
@@ -686,39 +666,26 @@ pep_identity() ->
686666
Acc :: mongoose_disco:feature_acc(),
687667
Params :: map(),
688668
Extra :: gen_hook:extra().
689-
disco_sm_features(Acc = #{from_jid := From, to_jid := To, node := Node}, _, _) ->
690-
Features = disco_features(jid:to_lower(jid:to_bare(To)), Node, From),
669+
disco_sm_features(Acc = #{from_jid := From, to_jid := To}, _, _) ->
670+
Features = disco_features(jid:to_lower(jid:to_bare(To)), From),
691671
{ok, mongoose_disco:add_features(Features, Acc)}.
692672

693-
-spec disco_features(error | jid:simple_jid(), binary(), jid:jid()) -> [mongoose_disco:feature()].
694-
disco_features(error, _Node, _From) ->
673+
-spec disco_features(error | jid:simple_jid(), jid:jid()) -> [mongoose_disco:feature()].
674+
disco_features(error, _From) ->
695675
[];
696-
disco_features(_Host, <<>>, _From) ->
697-
[?NS_PUBSUB | [feature(F) || F <- plugin_features(<<"pep">>)]];
698-
disco_features(Host, Node, From) ->
699-
Action = fun (#pubsub_node{id = Nidx, type = Type, options = Options, owners = Owners}) ->
700-
case get_allowed_items_call(Host, Nidx, From, Type, Options, Owners) of
701-
{result, _} ->
702-
{result, [?NS_PUBSUB | [feature(F) || F <- plugin_features(<<"pep">>)]]};
703-
_ ->
704-
{result, []}
705-
end
706-
end,
707-
case dirty(Host, Node, Action, ?FUNCTION_NAME) of
708-
{result, {_, Result}} -> Result;
709-
_ -> []
710-
end.
676+
disco_features(_Host, _From) ->
677+
[?NS_PUBSUB | [feature(F) || F <- plugin_features(<<"pep">>)]].
711678

712679
-spec disco_sm_items(Acc, Params, Extra) -> {ok, Acc} when
713680
Acc :: mongoose_disco:item_acc(),
714681
Params :: map(),
715682
Extra :: gen_hook:extra().
716-
disco_sm_items(Acc = #{from_jid := From, to_jid := To, node := Node}, _, _) ->
717-
Items = disco_items(jid:to_lower(jid:to_bare(To)), Node, From),
683+
disco_sm_items(Acc = #{from_jid := From, to_jid := To}, _, _) ->
684+
Items = disco_items(jid:to_lower(jid:to_bare(To)), From),
718685
{ok, mongoose_disco:add_items(Items, Acc)}.
719686

720-
-spec disco_items(mod_pubsub:host(), mod_pubsub:nodeId(), jid:jid()) -> [mongoose_disco:item()].
721-
disco_items(Host, <<>>, From) ->
687+
-spec disco_items(mod_pubsub:host(), jid:jid()) -> [mongoose_disco:item()].
688+
disco_items(Host, From) ->
722689
Action = fun (#pubsub_node{nodeid = {_, Node},
723690
options = Options, type = Type, id = Nidx, owners = Owners},
724691
Acc) ->
@@ -741,20 +708,6 @@ disco_items(Host, <<>>, From) ->
741708
case mod_pubsub_db_backend:dirty(NodeBloc, ErrorDebug) of
742709
{result, Items} -> Items;
743710
_ -> []
744-
end;
745-
disco_items(Host, Node, From) ->
746-
Action = fun (#pubsub_node{id = Nidx, type = Type, options = Options, owners = Owners}) ->
747-
case get_allowed_items_call(Host, Nidx, From, Type, Options, Owners) of
748-
{result, Items} ->
749-
{result, [disco_item(Host, ItemId) ||
750-
#pubsub_item{itemid = {ItemId, _}} <- Items]};
751-
_ ->
752-
{result, []}
753-
end
754-
end,
755-
case dirty(Host, Node, Action, ?FUNCTION_NAME) of
756-
{result, {_, Result}} -> Result;
757-
_ -> []
758711
end.
759712

760713
disco_item(Node, Host, Options) ->
@@ -765,10 +718,6 @@ disco_item(Node, Host, Options) ->
765718
[Title] -> Item#{name => Title}
766719
end.
767720

768-
disco_item(Host, ItemId) ->
769-
#{jid => jid:to_binary(Host),
770-
name => ItemId}.
771-
772721
%% -------
773722
%% callback that prevents routing subscribe authorizations back to the sender
774723
%%

0 commit comments

Comments
 (0)