mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-28 16:34:13 +01:00
Improve tests for mod_private
This commit is contained in:
parent
a84be928ef
commit
207c0eebe4
@ -401,7 +401,7 @@ db_tests(riak) ->
|
|||||||
presence_broadcast,
|
presence_broadcast,
|
||||||
last,
|
last,
|
||||||
roster_tests:single_cases(),
|
roster_tests:single_cases(),
|
||||||
private,
|
%%private_tests:single_cases(),
|
||||||
privacy_tests:single_cases(),
|
privacy_tests:single_cases(),
|
||||||
vcard_tests:single_cases(),
|
vcard_tests:single_cases(),
|
||||||
muc_tests:single_cases(),
|
muc_tests:single_cases(),
|
||||||
@ -424,7 +424,7 @@ db_tests(DB) when DB == mnesia; DB == redis ->
|
|||||||
presence_broadcast,
|
presence_broadcast,
|
||||||
last,
|
last,
|
||||||
roster_tests:single_cases(),
|
roster_tests:single_cases(),
|
||||||
private,
|
private_tests:single_cases(),
|
||||||
privacy_tests:single_cases(),
|
privacy_tests:single_cases(),
|
||||||
vcard_tests:single_cases(),
|
vcard_tests:single_cases(),
|
||||||
pubsub_tests:single_cases(),
|
pubsub_tests:single_cases(),
|
||||||
@ -455,7 +455,7 @@ db_tests(_) ->
|
|||||||
presence_broadcast,
|
presence_broadcast,
|
||||||
last,
|
last,
|
||||||
roster_tests:single_cases(),
|
roster_tests:single_cases(),
|
||||||
private,
|
private_tests:single_cases(),
|
||||||
privacy_tests:single_cases(),
|
privacy_tests:single_cases(),
|
||||||
vcard_tests:single_cases(),
|
vcard_tests:single_cases(),
|
||||||
pubsub_tests:single_cases(),
|
pubsub_tests:single_cases(),
|
||||||
@ -978,33 +978,6 @@ disco(Config) ->
|
|||||||
end, Items),
|
end, Items),
|
||||||
disconnect(Config).
|
disconnect(Config).
|
||||||
|
|
||||||
private(Config) ->
|
|
||||||
Conference = #bookmark_conference{name = <<"Some name">>,
|
|
||||||
autojoin = true,
|
|
||||||
jid = jid:make(
|
|
||||||
<<"some">>,
|
|
||||||
<<"some.conference.org">>,
|
|
||||||
<<>>)},
|
|
||||||
Storage = #bookmark_storage{conference = [Conference]},
|
|
||||||
StorageXMLOut = xmpp:encode(Storage),
|
|
||||||
WrongEl = #xmlel{name = <<"wrong">>},
|
|
||||||
#iq{type = error} =
|
|
||||||
send_recv(Config, #iq{type = get,
|
|
||||||
sub_els = [#private{sub_els = [WrongEl]}]}),
|
|
||||||
#iq{type = result, sub_els = []} =
|
|
||||||
send_recv(
|
|
||||||
Config, #iq{type = set,
|
|
||||||
sub_els = [#private{sub_els = [WrongEl, StorageXMLOut]}]}),
|
|
||||||
#iq{type = result,
|
|
||||||
sub_els = [#private{sub_els = [StorageXMLIn]}]} =
|
|
||||||
send_recv(
|
|
||||||
Config,
|
|
||||||
#iq{type = get,
|
|
||||||
sub_els = [#private{sub_els = [xmpp:encode(
|
|
||||||
#bookmark_storage{})]}]}),
|
|
||||||
Storage = xmpp:decode(StorageXMLIn),
|
|
||||||
disconnect(Config).
|
|
||||||
|
|
||||||
last(Config) ->
|
last(Config) ->
|
||||||
true = is_feature_advertised(Config, ?NS_LAST),
|
true = is_feature_advertised(Config, ?NS_LAST),
|
||||||
#iq{type = result, sub_els = [#last{}]} =
|
#iq{type = result, sub_els = [#last{}]} =
|
||||||
|
105
test/private_tests.erl
Normal file
105
test/private_tests.erl
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
%%%-------------------------------------------------------------------
|
||||||
|
%%% Author : Evgeny Khramtsov <ekhramtsov@process-one.net>
|
||||||
|
%%% Created : 23 Nov 2018 by Evgeny Khramtsov <ekhramtsov@process-one.net>
|
||||||
|
%%%
|
||||||
|
%%%
|
||||||
|
%%% ejabberd, Copyright (C) 2002-2018 ProcessOne
|
||||||
|
%%%
|
||||||
|
%%% This program is free software; you can redistribute it and/or
|
||||||
|
%%% modify it under the terms of the GNU General Public License as
|
||||||
|
%%% published by the Free Software Foundation; either version 2 of the
|
||||||
|
%%% License, or (at your option) any later version.
|
||||||
|
%%%
|
||||||
|
%%% This program is distributed in the hope that it will be useful,
|
||||||
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
%%% General Public License for more details.
|
||||||
|
%%%
|
||||||
|
%%% You should have received a copy of the GNU General Public License along
|
||||||
|
%%% with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
%%%
|
||||||
|
%%%-------------------------------------------------------------------
|
||||||
|
-module(private_tests).
|
||||||
|
|
||||||
|
%% API
|
||||||
|
-compile(export_all).
|
||||||
|
-import(suite, [my_jid/1, is_feature_advertised/3,
|
||||||
|
send_recv/2, disconnect/1]).
|
||||||
|
|
||||||
|
-include("suite.hrl").
|
||||||
|
|
||||||
|
%%%===================================================================
|
||||||
|
%%% API
|
||||||
|
%%%===================================================================
|
||||||
|
%%%===================================================================
|
||||||
|
%%% Single user tests
|
||||||
|
%%%===================================================================
|
||||||
|
single_cases() ->
|
||||||
|
{private_single, [sequence],
|
||||||
|
[single_test(test_features),
|
||||||
|
single_test(test_no_namespace),
|
||||||
|
single_test(test_set_get),
|
||||||
|
single_test(test_published)]}.
|
||||||
|
|
||||||
|
test_features(Config) ->
|
||||||
|
MyJID = my_jid(Config),
|
||||||
|
true = is_feature_advertised(Config, ?NS_BOOKMARKS_CONVERSION_0,
|
||||||
|
jid:remove_resource(MyJID)),
|
||||||
|
disconnect(Config).
|
||||||
|
|
||||||
|
test_no_namespace(Config) ->
|
||||||
|
WrongEl = #xmlel{name = <<"wrong">>},
|
||||||
|
#iq{type = error} =
|
||||||
|
send_recv(Config, #iq{type = get,
|
||||||
|
sub_els = [#private{sub_els = [WrongEl]}]}),
|
||||||
|
disconnect(Config).
|
||||||
|
|
||||||
|
test_set_get(Config) ->
|
||||||
|
Storage = bookmark_storage(),
|
||||||
|
StorageXMLOut = xmpp:encode(Storage),
|
||||||
|
#iq{type = result, sub_els = []} =
|
||||||
|
send_recv(
|
||||||
|
Config, #iq{type = set,
|
||||||
|
sub_els = [#private{sub_els = [StorageXMLOut]}]}),
|
||||||
|
#iq{type = result,
|
||||||
|
sub_els = [#private{sub_els = [StorageXMLIn]}]} =
|
||||||
|
send_recv(
|
||||||
|
Config,
|
||||||
|
#iq{type = get,
|
||||||
|
sub_els = [#private{sub_els = [xmpp:encode(
|
||||||
|
#bookmark_storage{})]}]}),
|
||||||
|
Storage = xmpp:decode(StorageXMLIn),
|
||||||
|
disconnect(Config).
|
||||||
|
|
||||||
|
test_published(Config) ->
|
||||||
|
Storage = bookmark_storage(),
|
||||||
|
Node = xmpp:get_ns(Storage),
|
||||||
|
#iq{type = result,
|
||||||
|
sub_els = [#pubsub{items = #ps_items{node = Node, items = Items}}]} =
|
||||||
|
send_recv(
|
||||||
|
Config,
|
||||||
|
#iq{type = get,
|
||||||
|
sub_els = [#pubsub{items = #ps_items{node = Node}}]}),
|
||||||
|
[#ps_item{sub_els = [StorageXMLIn]}] = Items,
|
||||||
|
Storage = xmpp:decode(StorageXMLIn),
|
||||||
|
#iq{type = result, sub_els = []} =
|
||||||
|
send_recv(Config,
|
||||||
|
#iq{type = set,
|
||||||
|
sub_els = [#pubsub_owner{delete = {Node, <<>>}}]}),
|
||||||
|
disconnect(Config).
|
||||||
|
|
||||||
|
%%%===================================================================
|
||||||
|
%%% Internal functions
|
||||||
|
%%%===================================================================
|
||||||
|
single_test(T) ->
|
||||||
|
list_to_atom("private_" ++ atom_to_list(T)).
|
||||||
|
|
||||||
|
conference_bookmark() ->
|
||||||
|
#bookmark_conference{
|
||||||
|
name = <<"Some name">>,
|
||||||
|
autojoin = true,
|
||||||
|
jid = jid:make(<<"some">>, <<"some.conference.org">>)}.
|
||||||
|
|
||||||
|
bookmark_storage() ->
|
||||||
|
#bookmark_storage{conference = [conference_bookmark()]}.
|
Loading…
Reference in New Issue
Block a user