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("common_test/include/ct.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,
   37:      messages_story].
   38: 
   39: suite() ->
   40:     escalus:suite().
   41: 
   42: %%--------------------------------------------------------------------
   43: %% Init & teardown
   44: %%--------------------------------------------------------------------
   45: init_per_suite(Config) ->
   46:     escalus:init_per_suite(Config).
   47: 
   48: end_per_suite(Config) ->
   49:     escalus:end_per_suite(Config).
   50: 
   51: init_per_group(_GroupName, Config) ->
   52:     escalus:create_users(Config, escalus:get_users([alice])).
   53: 
   54: end_per_group(_GroupName, Config) ->
   55:     escalus:delete_users(Config, escalus:get_users([alice])).
   56: 
   57: init_per_testcase(CaseName, Config0) ->
   58:     NewUsers = proplists:get_value(escalus_users, Config0) ++ escalus_ct:get_config(escalus_anon_users),
   59:     Config = [{escalus_users, NewUsers}] ++ Config0,
   60:     escalus:init_per_testcase(CaseName, Config).
   61: 
   62: end_per_testcase(CaseName, Config) ->
   63:     AnonJID = erlang:get(anon_user),
   64:     mongoose_helper:clear_last_activity(Config, AnonJID),
   65:     escalus:end_per_testcase(CaseName, Config).
   66: 
   67: %%--------------------------------------------------------------------
   68: %% Anonymous tests
   69: %%--------------------------------------------------------------------
   70: 
   71: connection_is_registered(Config) ->
   72:     escalus:story(Config, [{jon, 1}], fun(Jon) ->
   73:         JID = jid:from_binary(escalus_client:short_jid(Jon)),
   74:         F = fun() -> rpc(mim(), ejabberd_auth, does_user_exist, [JID]) end,
   75:         true = F(),
   76:         escalus_connection:kill(Jon),
   77:         mongoose_helper:wait_until(F, false)
   78:     end).
   79: 
   80: messages_story(Config) ->
   81:     escalus:story(Config, [{alice, 1}, {jon, 1}], fun(Alice, Jon) ->
   82:         erlang:put(anon_user, escalus_utils:get_jid(Jon)),
   83:         escalus_client:send(Jon, escalus_stanza:chat_to(Alice, <<"Hi!">>)),
   84:         Stanza = escalus_client:wait_for_stanza(Alice),
   85:         %% Below's dirty, but there is no other easy way...
   86:         escalus_assert:is_chat_message(<<"Hi!">>, Stanza)
   87:     end).