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(websockets_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: %%-------------------------------------------------------------------- 24: %% Suite configuration 25: %%-------------------------------------------------------------------- 26: 27: -define(REGISTRATION_TIMEOUT, 2). %% seconds 28: 29: all() -> 30: [{group, ws_chat}, 31: {group, wss_chat}]. 32: 33: groups() -> 34: G = [{ws_chat, [sequence], test_cases()}, 35: {wss_chat, [sequence], test_cases()} 36: ], 37: ct_helper:repeat_all_until_all_ok(G). 38: 39: test_cases() -> 40: [chat_msg, 41: escape_chat_msg, 42: escape_attrs]. 43: 44: suite() -> 45: escalus:suite(). 46: 47: %%-------------------------------------------------------------------- 48: %% Init & teardown 49: %%-------------------------------------------------------------------- 50: 51: init_per_suite(Config) -> 52: escalus:init_per_suite(Config). 53: 54: end_per_suite(Config) -> 55: escalus:end_per_suite(Config). 56: 57: init_per_group(GroupName, Config) -> 58: Config1 = escalus:create_users(Config, escalus:get_users([alice, geralt, geralt_s, carol])), 59: case GroupName of 60: wss_chat -> 61: [{user, geralt_s} | Config1]; 62: _ -> 63: [{user, geralt} | Config1] 64: end. 65: 66: 67: end_per_group(_GroupName, Config) -> 68: escalus:delete_users(Config, escalus:get_users([alice, geralt, geralt_s, carol])). 69: 70: init_per_testcase(CaseName, Config) -> 71: escalus:init_per_testcase(CaseName, Config). 72: 73: end_per_testcase(CaseName, Config) -> 74: escalus:end_per_testcase(CaseName, Config). 75: 76: %%-------------------------------------------------------------------- 77: %% Message tests 78: %%-------------------------------------------------------------------- 79: 80: chat_msg(Config) -> 81: escalus:story(Config, [{alice, 1}, {?config(user, Config), 1}, {carol, 1}], 82: fun(Alice, Geralt, Carol) -> 83: 84: escalus_client:send(Alice, escalus_stanza:chat_to(Geralt, <<"Hi!">>)), 85: FromAlice = escalus_client:wait_for_stanza(Geralt), 86: escalus:assert(is_chat_message, [<<"Hi!">>], FromAlice), 87: escalus:assert(has_ns, [<<"jabber:client">>], FromAlice), 88: 89: escalus_client:send(Geralt, escalus_stanza:chat_to(Alice, <<"Hello!">>)), 90: escalus:assert(is_chat_message, [<<"Hello!">>], escalus_client:wait_for_stanza(Alice)), 91: 92: escalus_client:send(Geralt, escalus_stanza:chat_to(Carol, <<"Hey!">>)), 93: escalus_assert:is_chat_message(<<"Hey!">>, escalus_client:wait_for_stanza(Carol)) 94: 95: end). 96: 97: escape_chat_msg(Config) -> 98: escalus:story(Config, [{alice, 1}, {?config(user, Config), 1}, {carol, 1}], 99: fun(Alice, Geralt, Carol) -> 100: special_chars_helper:check_cdata_from_to(Alice, Geralt, <<"Hi! & < >">>), 101: special_chars_helper:check_cdata_from_to(Geralt, Alice, <<"Hello! & < >">>), 102: special_chars_helper:check_cdata_from_to(Geralt, Carol, <<"Hey! & < >">>) 103: 104: end). 105: 106: escape_attrs(Config) -> 107: escalus:story(Config, [{alice, 1}, {?config(user, Config), 1}, {carol, 1}], 108: fun(Alice, Geralt, Carol) -> 109: special_chars_helper:check_attr_from_to(Alice, Geralt), 110: special_chars_helper:check_attr_from_to(Geralt, Alice), 111: special_chars_helper:check_attr_from_to(Geralt, Carol) 112: 113: end). 114: