1: %%============================================================================== 2: %% Copyright 2012 Erlang Solutions Ltd. 3: %% 4: %% Licensed under the Apache License, Version 2.0 (the "License"); 5: %% you may not use this file except in compliance with the License. 6: %% You may obtain a copy of the License at 7: %% 8: %% http://www.apache.org/licenses/LICENSE-2.0 9: %% 10: %% Unless required by applicable law or agreed to in writing, software 11: %% distributed under the License is distributed on an "AS IS" BASIS, 12: %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13: %% See the License for the specific language governing permissions and 14: %% limitations under the License. 15: %%============================================================================== 16: 17: -module(anonymous_SUITE). 18: -compile([export_all, nowarn_export_all]). 19: 20: -include_lib("escalus/include/escalus.hrl"). 21: -include_lib("eunit/include/eunit.hrl"). 22: 23: -import(distributed_helper, [mim/0, rpc/4]). 24: 25: %%-------------------------------------------------------------------- 26: %% Suite configuration 27: %%-------------------------------------------------------------------- 28: 29: all() -> 30: [{group, anonymous}]. 31: 32: groups() -> 33: [{anonymous, [sequence], all_tests()}]. 34: 35: all_tests() -> 36: [connection_is_registered_with_sasl_anon, 37: connection_is_registered_with_login, 38: messages_story]. 39: 40: suite() -> 41: escalus:suite(). 42: 43: %%-------------------------------------------------------------------- 44: %% Init & teardown 45: %%-------------------------------------------------------------------- 46: init_per_suite(Config) -> 47: escalus:init_per_suite(Config). 48: 49: end_per_suite(Config) -> 50: escalus:end_per_suite(Config). 51: 52: init_per_testcase(CaseName, Config0) -> 53: NewUsers = escalus_ct:get_config(escalus_anon_users), 54: Config = [{escalus_users, NewUsers}] ++ Config0, 55: escalus:init_per_testcase(CaseName, Config). 56: 57: end_per_testcase(CaseName, Config) -> 58: AnonJID = erlang:get(anon_user), 59: mongoose_helper:clear_last_activity(Config, AnonJID), 60: escalus:end_per_testcase(CaseName, Config). 61: 62: %%-------------------------------------------------------------------- 63: %% Anonymous tests 64: %%-------------------------------------------------------------------- 65: 66: connection_is_registered_with_sasl_anon(Config) -> 67: escalus:story(Config, [{jon, 1}], fun(Jon) -> 68: JID = jid:from_binary(escalus_client:short_jid(Jon)), 69: OrigName = escalus_users:get_username(Config, jon), 70: ?assertNotEqual(OrigName, JID#jid.user), 71: F = fun() -> rpc(mim(), ejabberd_auth, does_user_exist, [JID]) end, 72: true = F(), 73: escalus_connection:kill(Jon), 74: mongoose_helper:wait_until(F, false) 75: end). 76: 77: connection_is_registered_with_login(Config) -> 78: escalus:story(Config, [{anna, 1}], fun(Anna) -> 79: JID = jid:from_binary(escalus_client:short_jid(Anna)), 80: OrigName = escalus_users:get_username(Config, anna), 81: ?assertEqual(OrigName, JID#jid.user), 82: F = fun() -> rpc(mim(), ejabberd_auth, does_user_exist, [JID]) end, 83: true = F(), 84: escalus_connection:kill(Anna), 85: mongoose_helper:wait_until(F, false) 86: end). 87: 88: messages_story(Config) -> 89: escalus:story(Config, [{anna, 1}, {jon, 1}], fun(Anna, Jon) -> 90: erlang:put(anon_user, escalus_utils:get_jid(Jon)), 91: escalus_client:send(Jon, escalus_stanza:chat_to(Anna, <<"Hi!">>)), 92: Stanza = escalus_client:wait_for_stanza(Anna), 93: %% Below's dirty, but there is no other easy way... 94: escalus_assert:is_chat_message(<<"Hi!">>, Stanza) 95: end).