1: %%%=================================================================== 2: %%% @copyright (C) 2011, Erlang Solutions Ltd. 3: %%% @doc Suite for testing mod_sic module 4: %%% @end 5: %%%=================================================================== 6: 7: -module(sic_SUITE). 8: -compile([export_all, nowarn_export_all]). 9: 10: -include_lib("exml/include/exml.hrl"). 11: 12: -define(NS_SIC, <<"urn:xmpp:sic:1">>). 13: 14: -import(distributed_helper, [mim/0, 15: require_rpc_nodes/1, 16: rpc/4]). 17: 18: -import(domain_helper, [host_type/0]). 19: 20: %%%=================================================================== 21: %%% Suite configuration 22: %%%=================================================================== 23: 24: all() -> 25: [{group, mod_sic_tests}]. 26: 27: all_tests() -> 28: [user_sic, forbidden_user_sic]. 29: 30: groups() -> 31: [{mod_sic_tests, [sequence], all_tests()}]. 32: 33: suite() -> 34: require_rpc_nodes([mim]) ++ escalus:suite(). 35: 36: %%%=================================================================== 37: %%% Init & teardown 38: %%%=================================================================== 39: 40: init_per_suite(Config0) -> 41: Config1 = escalus:init_per_suite(Config0), 42: escalus:create_users(Config1, escalus:get_users([alice, bob])). 43: 44: end_per_suite(Config) -> 45: escalus:delete_users(Config, escalus:get_users([alice, bob])), 46: escalus:end_per_suite(Config). 47: 48: init_per_group(mod_sic_tests, Config) -> 49: Config1 = dynamic_modules:save_modules(host_type(), Config), 50: dynamic_modules:ensure_modules(host_type(), [{mod_sic, config_parser_helper:default_mod_config(mod_sic)}]), 51: Config1; 52: init_per_group(_GroupName, Config) -> 53: Config. 54: 55: end_per_group(mod_sic_tests, Config) -> 56: dynamic_modules:restore_modules(Config); 57: end_per_group(_GroupName, _Config) -> 58: ok. 59: 60: init_per_testcase(CaseName, Config) -> 61: escalus:init_per_testcase(CaseName, Config). 62: 63: end_per_testcase(CaseName, Config) -> 64: escalus:end_per_testcase(CaseName, Config). 65: 66: %%%=================================================================== 67: %%% offline tests 68: %%%=================================================================== 69: 70: %% Retrieve my IP 71: user_sic(Config) -> 72: escalus:story(Config, [{alice, 1}], fun(Alice) -> 73: %% Alice sends a SIC IQ stanza 74: escalus:send(Alice, sic_iq_get()), 75: %% Alice expects IQ result with client IP address 76: Stanza = escalus:wait_for_stanza(Alice), 77: escalus:assert(is_sic_response(), Stanza) 78: end). 79: 80: %% Try to retrieve other user's IP 81: forbidden_user_sic(Config) -> 82: escalus:story(Config, [{alice, 1}, {bob, 1}], fun(Alice, _Bob) -> 83: %% Alice sends a SIC IQ stanza to get Bob's IP 84: escalus:send(Alice, sic_iq_get(escalus_users:get_jid(Config, bob))), 85: %% Alice should get <forbidden/> error 86: Stanza = escalus:wait_for_stanza(Alice), 87: escalus:assert(is_error, [<<"auth">>, <<"forbidden">>], Stanza) 88: end). 89: 90: %%%=================================================================== 91: %%% Custom predicates 92: %%%=================================================================== 93: 94: is_sic_response() -> 95: fun(Stanza) -> 96: escalus_pred:is_iq(<<"result">>, Stanza) 97: andalso 98: ?NS_SIC == exml_query:path(Stanza, [{element, <<"address">>}, {attr, <<"xmlns">>}]) 99: andalso 100: <<"127.0.0.1">> == exml_query:path(Stanza, [{element, <<"address">>}, {element, <<"ip">>}, cdata]) 101: andalso 102: is_binary(exml_query:path(Stanza, [{element, <<"address">>}, {element, <<"port">>}, cdata])) 103: end. 104: 105: %%%=================================================================== 106: %%% Helpers 107: %%%=================================================================== 108: 109: sic_iq_get() -> 110: escalus_stanza:iq(<<"get">>, [#xmlel{ 111: name = <<"address">>, 112: attrs = [{<<"xmlns">>, ?NS_SIC}], 113: children = [] 114: }]). 115: 116: sic_iq_get(To) -> 117: escalus_stanza:to(sic_iq_get(), To).