13
13
-include_lib (" exml/include/exml.hrl" ).
14
14
-include_lib (" eunit/include/eunit.hrl" ).
15
15
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 ]).
47
17
48
18
-import (distributed_helper , [mim /0 ,
49
19
require_rpc_nodes /1 ,
@@ -85,7 +55,8 @@ groups() ->
85
55
delayed_receive_with_sm ,
86
56
h_ok_after_notify_test ,
87
57
authorize_access_model ,
88
- unsubscribe_after_presence_unsubscription
58
+ unsubscribe_after_presence_unsubscription ,
59
+ native_bookmarks_test
89
60
]
90
61
},
91
62
{cache_tests , [parallel ],
@@ -233,6 +204,42 @@ pep_caps_test(Config) ->
233
204
send_caps_disco_result (Bob , DiscoRequest , NodeNS )
234
205
end ).
235
206
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
+
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
+
236
243
publish_and_notify_test (Config ) ->
237
244
Config1 = set_caps (Config ),
238
245
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) ->
591
598
end , Options ).
592
599
593
600
set_caps (Config ) ->
601
+ set_caps (Config , random_node_ns ()).
602
+
603
+ set_caps (Config , NS ) ->
594
604
[{escalus_overrides , [{start_ready_clients , {? MODULE , start_caps_clients }}]},
595
- {node_ns , random_node_ns () } | Config ].
605
+ {node_ns , NS } | Config ].
596
606
597
607
% % Implemented only for one resource per client, because it is enough
598
608
start_caps_clients (Config , [{UserSpec , Resource }]) ->
@@ -622,7 +632,7 @@ caps(PEPNodeNS) ->
622
632
# xmlel {name = <<" c" >>,
623
633
attrs = #{<<" xmlns" >> => ? NS_CAPS ,
624
634
<<" hash" >> => <<" sha-1" >>,
625
- <<" node" >> => caps_node_name (),
635
+ <<" node" >> => random_name (),
626
636
<<" ver" >> => caps_hash (PEPNodeNS )}}.
627
637
628
638
features (PEPNodeNS ) ->
@@ -637,14 +647,14 @@ ns_notify(NS) ->
637
647
<<NS /binary , " +notify" >>.
638
648
639
649
random_node_ns () ->
650
+ random_name ().
651
+
652
+ random_name () ->
640
653
base64 :encode (crypto :strong_rand_bytes (16 )).
641
654
642
655
caps_hash (PEPNodeNS ) ->
643
656
rpc (mim (), mod_caps , make_disco_hash , [feature_elems (PEPNodeNS ), sha1 ]).
644
657
645
- caps_node_name () ->
646
- <<" http://www.chatopus.com" >>.
647
-
648
658
send_presence (From , Type , To ) ->
649
659
ToJid = escalus_client :short_jid (To ),
650
660
Stanza = escalus_stanza :presence_direct (ToJid , Type ),
0 commit comments