25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-20 16:15:59 +01:00

Adopt tests to changes introduced by b54e1e49ba

This commit is contained in:
Paweł Chmielowski 2017-12-27 16:16:15 +01:00
parent e6d1ff85f1
commit d59d4e27ec

View File

@ -311,19 +311,19 @@ deny_sub_both_master(Config) ->
deny_master(Config, {subscription, <<"both">>}). deny_master(Config, {subscription, <<"both">>}).
deny_sub_both_slave(Config) -> deny_sub_both_slave(Config) ->
deny_slave(Config). deny_slave(Config, 2).
deny_sub_from_master(Config) -> deny_sub_from_master(Config) ->
deny_master(Config, {subscription, <<"from">>}). deny_master(Config, {subscription, <<"from">>}).
deny_sub_from_slave(Config) -> deny_sub_from_slave(Config) ->
deny_slave(Config). deny_slave(Config, 1).
deny_sub_to_master(Config) -> deny_sub_to_master(Config) ->
deny_master(Config, {subscription, <<"to">>}). deny_master(Config, {subscription, <<"to">>}).
deny_sub_to_slave(Config) -> deny_sub_to_slave(Config) ->
deny_slave(Config). deny_slave(Config, 2).
deny_sub_none_master(Config) -> deny_sub_none_master(Config) ->
deny_master(Config, {subscription, <<"none">>}). deny_master(Config, {subscription, <<"none">>}).
@ -389,7 +389,8 @@ deny_master(Config, {Type, Value}) ->
false -> send_messages(Config) false -> send_messages(Config)
end, end,
case is_other_blocked(Opts) of case is_other_blocked(Opts) of
true -> check_other_blocked(Config, 'not-acceptable'); true ->
check_other_blocked(Config, 'not-acceptable', Value);
false -> ok false -> ok
end, end,
ct:comment("Waiting for slave to finish processing our stanzas"), ct:comment("Waiting for slave to finish processing our stanzas"),
@ -401,12 +402,16 @@ deny_master(Config, {Type, Value}) ->
clean_up(disconnect(Config)). clean_up(disconnect(Config)).
deny_slave(Config) -> deny_slave(Config) ->
set_roster(Config, both, []), deny_slave(Config, 0).
deny_slave(Config, get_event(Config)).
deny_slave(Config, disconnect) -> deny_slave(Config, RosterPushesCount) ->
set_roster(Config, both, []),
deny_slave(Config, RosterPushesCount, get_event(Config)).
deny_slave(Config, RosterPushesCount, disconnect) ->
recv_roster_pushes(Config, RosterPushesCount),
clean_up(disconnect(Config)); clean_up(disconnect(Config));
deny_slave(Config, Opts) -> deny_slave(Config, RosterPushesCount, Opts) ->
send_presences(Config), send_presences(Config),
case is_iq_in_blocked(Opts) of case is_iq_in_blocked(Opts) of
true -> check_iq_blocked(Config, 'service-unavailable'); true -> check_iq_blocked(Config, 'service-unavailable');
@ -426,7 +431,7 @@ deny_slave(Config, Opts) ->
false -> recv_messages(Config) false -> recv_messages(Config)
end, end,
put_event(Config, done), put_event(Config, done),
deny_slave(Config, get_event(Config)). deny_slave(Config, RosterPushesCount, get_event(Config)).
deny_offline_master(Config) -> deny_offline_master(Config) ->
set_roster(Config, both, []), set_roster(Config, both, []),
@ -457,7 +462,7 @@ block_master(Config) ->
check_presence_blocked(Config, 'not-acceptable'), check_presence_blocked(Config, 'not-acceptable'),
check_iq_blocked(Config, 'not-acceptable'), check_iq_blocked(Config, 'not-acceptable'),
check_message_blocked(Config, 'not-acceptable'), check_message_blocked(Config, 'not-acceptable'),
check_other_blocked(Config, 'not-acceptable'), check_other_blocked(Config, 'not-acceptable', other),
%% We should always be able to communicate with our home server %% We should always be able to communicate with our home server
server_send_iqs(Config), server_send_iqs(Config),
server_recv_iqs(Config), server_recv_iqs(Config),
@ -700,16 +705,52 @@ check_presence_blocked(Config, Reason) ->
#stanza_error{reason = Reason} = xmpp:get_error(Err) #stanza_error{reason = Reason} = xmpp:get_error(Err)
end, [available, unavailable]). end, [available, unavailable]).
check_other_blocked(Config, Reason) -> recv_roster_pushes(Config, 0) ->
ok;
recv_roster_pushes(Config, Count) ->
receive
#iq{type = set, sub_els = [#roster_query{}]} ->
recv_roster_pushes(Config, Count - 1)
end.
recv_err_and_roster_pushes(Config, Count) ->
PeerJID = ?config(master, Config),
recv_roster_pushes(Config, Count),
recv_presence(Config).
check_other_blocked(Config, Reason, Subscription) ->
PeerJID = ?config(peer, Config), PeerJID = ?config(peer, Config),
ct:comment("Checking if subscriptions and presence-errors are blocked"), ct:comment("Checking if subscriptions and presence-errors are blocked"),
send(Config, #presence{type = error, to = PeerJID}), send(Config, #presence{type = error, to = PeerJID}),
{ErrorFor, PushFor} = case Subscription of
<<"both">> ->
{[subscribe, subscribed],
[unsubscribe, unsubscribed]};
<<"from">> ->
{[subscribe, subscribed, unsubscribe],
[subscribe, unsubscribe, unsubscribed]};
<<"to">> ->
{[unsubscribe],
[subscribed, unsubscribe, unsubscribed]};
<<"none">> ->
{[subscribe, subscribed, unsubscribe, unsubscribed],
[subscribe, unsubscribe]};
_ ->
{[subscribe, subscribed, unsubscribe, unsubscribed],
[unsubscribe, unsubscribed]}
end,
lists:foreach( lists:foreach(
fun(Type) -> fun(Type) ->
#presence{type = error} = Err = send(Config, #presence{type = Type, to = PeerJID}),
send_recv(Config, #presence{type = Type, to = PeerJID}), Count = case lists:member(Type, PushFor) of true -> 1; _ -> 0 end,
#stanza_error{reason = Reason} = xmpp:get_error(Err) case lists:member(Type, ErrorFor) of
end, [subscribe, subscribed, unsubscribe, unsubscribed]). true ->
Err = recv_err_and_roster_pushes(Config, Count),
#stanza_error{reason = Reason} = xmpp:get_error(Err);
_ ->
recv_roster_pushes(Config, Count)
end
end, [subscribe, subscribed, unsubscribe, unsubscribed]).
send_presences(Config) -> send_presences(Config) ->
PeerJID = ?config(peer, Config), PeerJID = ?config(peer, Config),
@ -770,7 +811,7 @@ is_message_in_blocked(Opts) ->
is_message_out_blocked(Opts) -> is_message_out_blocked(Opts) ->
match_all(Opts). match_all(Opts).
is_iq_in_blocked(Opts) -> is_iq_in_blocked(Opts) ->
proplists:get_bool(iq, Opts) or match_all(Opts). proplists:get_bool(iq, Opts) or match_all(Opts).
is_iq_out_blocked(Opts) -> is_iq_out_blocked(Opts) ->