Skip to content

Commit f31e9d1

Browse files
authored
Merge pull request #4545 from esl/pep-native-bookmarks
XEP-0402 PEP Native Bookmarks
2 parents 65ae76a + 813cbb7 commit f31e9d1

File tree

6 files changed

+109
-89
lines changed

6 files changed

+109
-89
lines changed

big_tests/rebar.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
{proper, "1.4.0"},
1414
{gun, "2.1.0"},
1515
{fusco, "0.1.1"},
16-
{escalus, "4.5.1"},
16+
{escalus, "4.5.3"},
1717
{ranch, "2.2.0"},
1818
{cowboy, "2.13.0"},
1919
{csv, "3.0.3", {pkg, csve}},

big_tests/rebar.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
{<<"ct_groups_summary_hook">>,
1111
{pkg,<<"ct_groups_summary_hook">>,<<"0.1.1">>},
1212
0},
13-
{<<"escalus">>,{pkg,<<"escalus">>,<<"4.5.1">>},0},
13+
{<<"escalus">>,{pkg,<<"escalus">>,<<"4.5.3">>},0},
1414
{<<"esip">>,{pkg,<<"esip">>,<<"1.0.57">>},0},
1515
{<<"exml">>,{pkg,<<"hexml">>,<<"4.1.2">>},0},
1616
{<<"fast_pbkdf2">>,{pkg,<<"fast_pbkdf2">>,<<"2.0.0">>},2},
@@ -42,7 +42,7 @@
4242
{<<"credentials_obfuscation">>, <<"34E18B126B3AEFD6E8143776FBE1CECEEA6792307C99AC5EE8687911F048CFD7">>},
4343
{<<"csv">>, <<"69E7D9B3FDC72016644368762C6A3E6CBFEB85BCCADBF1BD99AB6C827E360E04">>},
4444
{<<"ct_groups_summary_hook">>, <<"21B94902B6CF2D345F4D790D34B49654E71CB8E570DCCC9C1C3616DAE720A7AA">>},
45-
{<<"escalus">>, <<"A79B93BC013219078C13C004766287CC97045D75A8BF893163B8FF7E5DD521CD">>},
45+
{<<"escalus">>, <<"A6BC39DD7648E56FB4514E323FC566C59B8B4F53A40ED6E89811BD4E5325DA53">>},
4646
{<<"esip">>, <<"4B14E4832D08B9FFC10D855B5D10B3083232B1D53DEB4C046679496CE85569C4">>},
4747
{<<"exml">>, <<"4EA6B95AF18922F94FD67BBDEAA325A75CCE04487083C786E7417BA862D590E5">>},
4848
{<<"fast_pbkdf2">>, <<"72CDEE3C10C6B9B40E31194DE946A883CEEF6CF1F37D7FC9FD1A9D87502723F5">>},
@@ -73,7 +73,7 @@
7373
{<<"credentials_obfuscation">>, <<"738ACE0ED5545D2710D3F7383906FC6F6B582D019036E5269C4DBD85DBCED566">>},
7474
{<<"csv">>, <<"741D1A55AABADAA3E0FE13051050101A73E90C4570B9F9403A939D9546813521">>},
7575
{<<"ct_groups_summary_hook">>, <<"997CDE48FEB0C398989E4091A341D4FFF43CFA06CDB8FB2E80CC4A0E0362691C">>},
76-
{<<"escalus">>, <<"FE4BACC8E6875334341872C188A5C68CD749DB362F189617D3520F6D25C7B145">>},
76+
{<<"escalus">>, <<"34559C804CC44F2ADC2B8B466153E023A4C9D76AE97D18CA5F5447C1D4F85D07">>},
7777
{<<"esip">>, <<"19C357E1817B1E04792EF359BF900400F3E6D0E5ADE929FD72F88EA9B44AF2ED">>},
7878
{<<"exml">>, <<"03883AE3E27970E9DAC204B27CE330B54A6C2772455E43FE2319349DFF40B1DC">>},
7979
{<<"fast_pbkdf2">>, <<"74159FD09FB8BF5E97D25137C6C83C28E2CF7E97D7C127D83310DFD0904BD732">>},

big_tests/tests/pep_SUITE.erl

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,7 @@
1313
-include_lib("exml/include/exml.hrl").
1414
-include_lib("eunit/include/eunit.hrl").
1515

16-
-export([suite/0, all/0, groups/0]).
17-
-export([init_per_suite/1, end_per_suite/1,
18-
init_per_group/2, end_per_group/2,
19-
init_per_testcase/2, end_per_testcase/2]).
20-
21-
-export([
22-
disco_test/1,
23-
disco_sm_test/1,
24-
disco_sm_node_test/1,
25-
disco_sm_items_test/1,
26-
disco_sm_items_node_test/1,
27-
pep_caps_test/1,
28-
publish_and_notify_test/1,
29-
auto_create_with_publish_options_test/1,
30-
publish_options_success_test/1,
31-
publish_options_fail_unknown_option_story/1,
32-
publish_options_fail_wrong_value_story/1,
33-
publish_options_fail_wrong_form/1,
34-
send_caps_after_login_test/1,
35-
delayed_receive/1,
36-
delayed_receive_with_sm/1,
37-
h_ok_after_notify_test/1,
38-
authorize_access_model/1,
39-
unsubscribe_after_presence_unsubscription/1
40-
]).
41-
42-
-export([
43-
start_caps_clients/2,
44-
send_initial_presence_with_caps/2,
45-
add_config_to_create_node_request/1
46-
]).
16+
-compile([export_all, nowarn_export_all]).
4717

4818
-import(distributed_helper, [mim/0,
4919
require_rpc_nodes/1,
@@ -85,7 +55,8 @@ groups() ->
8555
delayed_receive_with_sm,
8656
h_ok_after_notify_test,
8757
authorize_access_model,
88-
unsubscribe_after_presence_unsubscription
58+
unsubscribe_after_presence_unsubscription,
59+
native_bookmarks_test
8960
]
9061
},
9162
{cache_tests, [parallel],
@@ -233,6 +204,42 @@ pep_caps_test(Config) ->
233204
send_caps_disco_result(Bob, DiscoRequest, NodeNS)
234205
end).
235206

207+
native_bookmarks_test(Config) ->
208+
Config1 = set_caps(Config, ?NS_PEP_BOOKMARKS),
209+
escalus:fresh_story_with_config(Config1, [{bob, 1}], fun native_bookmarks_story/2).
210+
211+
%% Minimal test for XEP-0402
212+
native_bookmarks_story(Config, Bob) ->
213+
NodeNS = ?config(node_ns, Config),
214+
PublishOptions = [{<<"pubsub#persist_items">>, <<"true">>},
215+
{<<"pubsub#max_items">>, <<"max">>},
216+
{<<"pubsub#send_last_published_item">>, <<"never">>},
217+
{<<"pubsub#access_model">>, <<"whitelist">>}],
218+
Options = [{with_payload, {true, bookmark_element()}}],
219+
Id = <<"[email protected]">>,
220+
BobJid = escalus_utils:get_short_jid(Bob),
221+
222+
%% Example 6. Client adds a new bookmark
223+
pubsub_tools:publish_with_options(Bob, Id, {pep, NodeNS}, Options, PublishOptions),
224+
225+
%% Example 12. Client receives a new bookmark notification
226+
pubsub_tools:receive_item_notification(Bob, Id, {BobJid, NodeNS}, []),
227+
228+
%% Example 4. Client retrieves all bookmarks
229+
pubsub_tools:get_all_items(Bob, {pep, NodeNS}, [{expected_result, [Id]}]),
230+
231+
%% Example 10. Client removes a bookmark
232+
pubsub_tools:retract_item(Bob, {pep, NodeNS}, Id, [{notify, true}]),
233+
234+
%% Example 14. Client receives a bookmark retraction notification
235+
pubsub_tools:receive_retract_notification(Bob, Id, {BobJid, NodeNS}, []),
236+
237+
pubsub_tools:get_all_items(Bob, {pep, NodeNS}, [{expected_result, []}]).
238+
239+
bookmark_element() ->
240+
#xmlel{name = <<"conference">>,
241+
attrs = #{<<"xmlns">> => ?NS_PEP_BOOKMARKS}}.
242+
236243
publish_and_notify_test(Config) ->
237244
Config1 = set_caps(Config),
238245
escalus:fresh_story_with_config(Config1, [{alice, 1}, {bob, 1}], fun publish_and_notify_story/3).
@@ -591,8 +598,11 @@ verify_publish_options(FullNodeConfig, Options) ->
591598
end, Options).
592599

593600
set_caps(Config) ->
601+
set_caps(Config, random_node_ns()).
602+
603+
set_caps(Config, NS) ->
594604
[{escalus_overrides, [{start_ready_clients, {?MODULE, start_caps_clients}}]},
595-
{node_ns, random_node_ns()} | Config].
605+
{node_ns, NS} | Config].
596606

597607
%% Implemented only for one resource per client, because it is enough
598608
start_caps_clients(Config, [{UserSpec, Resource}]) ->
@@ -622,7 +632,7 @@ caps(PEPNodeNS) ->
622632
#xmlel{name = <<"c">>,
623633
attrs = #{<<"xmlns">> => ?NS_CAPS,
624634
<<"hash">> => <<"sha-1">>,
625-
<<"node">> => caps_node_name(),
635+
<<"node">> => random_name(),
626636
<<"ver">> => caps_hash(PEPNodeNS)}}.
627637

628638
features(PEPNodeNS) ->
@@ -637,14 +647,14 @@ ns_notify(NS) ->
637647
<<NS/binary, "+notify">>.
638648

639649
random_node_ns() ->
650+
random_name().
651+
652+
random_name() ->
640653
base64:encode(crypto:strong_rand_bytes(16)).
641654

642655
caps_hash(PEPNodeNS) ->
643656
rpc(mim(), mod_caps, make_disco_hash, [feature_elems(PEPNodeNS), sha1]).
644657

645-
caps_node_name() ->
646-
<<"http://www.chatopus.com">>.
647-
648658
send_presence(From, Type, To) ->
649659
ToJid = escalus_client:short_jid(To),
650660
Stanza = escalus_stanza:presence_direct(ToJid, Type),

big_tests/tests/pubsub_SUITE.erl

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ publish_with_max_items_test(Config) ->
483483
%% would always arrive before a retraction notification for an old item
484484
pubsub_tools:publish(Alice, <<"item2">>, Node, []),
485485
pubsub_tools:receive_item_notification(Bob, <<"item2">>, Node, []),
486-
verify_item_retract(Node, <<"item1">>, escalus:wait_for_stanza(Bob)),
486+
pubsub_tools:receive_retract_notification(Bob, <<"item1">>, Node, []),
487487

488488
pubsub_tools:delete_node(Alice, Node, [])
489489
end).
@@ -604,7 +604,7 @@ retract_test(Config) ->
604604
[{<<"pubsub#notify_retract">>, <<"1">>}], []),
605605
pubsub_tools:subscribe(Bob, Node, []),
606606
pubsub_tools:retract_item(Alice, Node, <<"item2">>, []),
607-
verify_item_retract(Node, <<"item2">>, escalus:wait_for_stanza(Bob)),
607+
pubsub_tools:receive_retract_notification(Bob, <<"item2">>, Node, []),
608608
pubsub_tools:get_all_items(Bob, Node, [{expected_result, []}]),
609609

610610
pubsub_tools:delete_node(Alice, Node, [])
@@ -1985,18 +1985,6 @@ default_config() ->
19851985
{<<"pubsub#type">>, <<>>},
19861986
{<<"pubsub#collection">>, []}].
19871987

1988-
verify_item_retract({NodeAddr, NodeName}, ItemId, Stanza) ->
1989-
escalus:assert(is_message, Stanza),
1990-
NodeAddr = exml_query:attr(Stanza, <<"from">>),
1991-
1992-
[#xmlel{ attrs = #{<<"xmlns">> := ?NS_PUBSUB_EVENT} } = Event]
1993-
= exml_query:subelements(Stanza, <<"event">>),
1994-
1995-
[#xmlel{ attrs = #{<<"node">> := NodeName} } = Items]
1996-
= exml_query:subelements(Event, <<"items">>),
1997-
1998-
[#xmlel{ attrs = #{<<"id">> := ItemId} }] = exml_query:subelements(Items, <<"retract">>).
1999-
20001988
verify_config_event({NodeAddr, NodeName}, ConfigChange, Stanza) ->
20011989
escalus:assert(is_message, Stanza),
20021990
NodeAddr = exml_query:attr(Stanza, <<"from">>),

big_tests/tests/pubsub_tools.erl

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ publish_request(Id, User, ItemId, Node, Options, PublishOptions) ->
143143

144144
retract_item(User, Node, ItemId, Options) ->
145145
Id = id(User, Node, <<"retract">>),
146-
Request = escalus_pubsub_stanza:retract(User, Id, Node, ItemId),
146+
Attrs = case proplists:get_value(notify, Options) of
147+
Bool when is_boolean(Bool) -> #{<<"notify">> => atom_to_binary(Bool)};
148+
undefined -> #{}
149+
end,
150+
Request = escalus_pubsub_stanza:retract(User, Id, Node, ItemId, Attrs),
147151
send_request_and_receive_response(User, Request, Id, Options).
148152

149153
get_all_items(User, {_, NodeName} = Node, Options) ->
@@ -257,6 +261,10 @@ receive_item_notification(User, ItemId, {NodeAddr, NodeName}, Options) ->
257261
Stanza = receive_notification(User, NodeAddr, Options),
258262
check_item_notification(Stanza, ItemId, {NodeAddr, NodeName}, Options).
259263

264+
receive_retract_notification(User, ItemId, {NodeAddr, NodeName}, Options) ->
265+
Stanza = receive_notification(User, NodeAddr, Options),
266+
check_retract_notification(Stanza, ItemId, {NodeAddr, NodeName}).
267+
260268
receive_subscription_notification(User, Subscription, {NodeAddr, NodeName}, Options) ->
261269
Stanza = receive_notification(User, NodeAddr, Options),
262270
check_subscription_notification(User, Stanza, Subscription, NodeName, Options).
@@ -389,15 +397,6 @@ check_node_creation_notification(Response, NodeName) ->
389397
Response.
390398

391399
check_item_notification(Response, ItemId, {NodeAddr, NodeName}, Options) ->
392-
try
393-
do_check_item_notification(Response, ItemId, {NodeAddr, NodeName}, Options)
394-
catch Class:Reason:StackTrace ->
395-
ct:pal("failed to check response=~p", [Response]),
396-
erlang:raise(Class, Reason, StackTrace)
397-
end,
398-
Response.
399-
400-
do_check_item_notification(Response, ItemId, {NodeAddr, NodeName}, Options) ->
401400
check_notification(Response, NodeAddr),
402401
true = escalus_pred:has_type(<<"headline">>, Response),
403402
Items = exml_query:path(Response, [{element, <<"event">>},
@@ -406,6 +405,17 @@ do_check_item_notification(Response, ItemId, {NodeAddr, NodeName}, Options) ->
406405
check_items(Items, [ItemId], NodeName),
407406
ok.
408407

408+
check_retract_notification(Response, ItemId, {NodeAddr, NodeName}) ->
409+
check_notification(Response, NodeAddr),
410+
true = escalus_pred:has_type(<<"headline">>, Response),
411+
[#xmlel{ attrs = #{<<"xmlns">> := ?NS_PUBSUB_EVENT} } = Event] =
412+
exml_query:subelements(Response, <<"event">>),
413+
[#xmlel{ attrs = #{<<"node">> := NodeName} } = Items] =
414+
exml_query:subelements(Event, <<"items">>),
415+
[#xmlel{ attrs = #{<<"id">> := ItemId} }] =
416+
exml_query:subelements(Items, <<"retract">>),
417+
ok.
418+
409419
send_request_and_receive_response(User, Request, Id, Options) ->
410420
send_request_and_receive_response(User, Request, Id, Options, fun(R) -> R end).
411421

0 commit comments

Comments
 (0)