mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-20 17:27:00 +01:00
Add tests for mod_stun_disco
This commit is contained in:
parent
69d1d62add
commit
9cd47d7085
@ -361,6 +361,7 @@ no_db_tests() ->
|
|||||||
muc_tests:master_slave_cases(),
|
muc_tests:master_slave_cases(),
|
||||||
proxy65_tests:single_cases(),
|
proxy65_tests:single_cases(),
|
||||||
proxy65_tests:master_slave_cases(),
|
proxy65_tests:master_slave_cases(),
|
||||||
|
stundisco_tests:single_cases(),
|
||||||
replaced_tests:master_slave_cases(),
|
replaced_tests:master_slave_cases(),
|
||||||
upload_tests:single_cases(),
|
upload_tests:single_cases(),
|
||||||
carbons_tests:single_cases(),
|
carbons_tests:single_cases(),
|
||||||
|
@ -90,6 +90,12 @@ listen:
|
|||||||
"/api": mod_http_api
|
"/api": mod_http_api
|
||||||
"/upload": mod_http_upload
|
"/upload": mod_http_upload
|
||||||
"/captcha": ejabberd_captcha
|
"/captcha": ejabberd_captcha
|
||||||
|
-
|
||||||
|
port: STUN_PORT
|
||||||
|
module: ejabberd_stun
|
||||||
|
transport: udp
|
||||||
|
use_turn: true
|
||||||
|
turn_ip: "203.0.113.3"
|
||||||
-
|
-
|
||||||
port: COMPONENT_PORT
|
port: COMPONENT_PORT
|
||||||
module: ejabberd_service
|
module: ejabberd_service
|
||||||
@ -124,6 +130,12 @@ Welcome to this XMPP server."
|
|||||||
mod_stream_mgmt:
|
mod_stream_mgmt:
|
||||||
max_ack_queue: 10
|
max_ack_queue: 10
|
||||||
resume_timeout: 3
|
resume_timeout: 3
|
||||||
|
mod_stun_disco:
|
||||||
|
secret: "cryptic"
|
||||||
|
services:
|
||||||
|
-
|
||||||
|
host: "example.com"
|
||||||
|
type: turns
|
||||||
mod_time: []
|
mod_time: []
|
||||||
mod_version: []
|
mod_version: []
|
||||||
mod_http_upload:
|
mod_http_upload:
|
||||||
|
@ -4,6 +4,7 @@ define_macro:
|
|||||||
C2S_PORT: @@c2s_port@@
|
C2S_PORT: @@c2s_port@@
|
||||||
S2S_PORT: @@s2s_port@@
|
S2S_PORT: @@s2s_port@@
|
||||||
WEB_PORT: @@web_port@@
|
WEB_PORT: @@web_port@@
|
||||||
|
STUN_PORT: @@stun_port@@
|
||||||
COMPONENT_PORT: @@component_port@@
|
COMPONENT_PORT: @@component_port@@
|
||||||
PROXY_PORT: @@proxy_port@@
|
PROXY_PORT: @@proxy_port@@
|
||||||
PASSWORD: >-
|
PASSWORD: >-
|
||||||
|
192
test/stundisco_tests.erl
Normal file
192
test/stundisco_tests.erl
Normal file
@ -0,0 +1,192 @@
|
|||||||
|
%%%-------------------------------------------------------------------
|
||||||
|
%%% Author : Holger Weiss <holger@zedat.fu-berlin.de>
|
||||||
|
%%% Created : 22 Apr 2020 by Holger Weiss <holger@zedat.fu-berlin.de>
|
||||||
|
%%%
|
||||||
|
%%%
|
||||||
|
%%% ejabberd, Copyright (C) 2020 ProcessOne
|
||||||
|
%%%
|
||||||
|
%%% This program is free software; you can redistribute it and/or
|
||||||
|
%%% modify it under the terms of the GNU General Public License as
|
||||||
|
%%% published by the Free Software Foundation; either version 2 of the
|
||||||
|
%%% License, or (at your option) any later version.
|
||||||
|
%%%
|
||||||
|
%%% This program is distributed in the hope that it will be useful,
|
||||||
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
%%% General Public License for more details.
|
||||||
|
%%%
|
||||||
|
%%% You should have received a copy of the GNU General Public License along
|
||||||
|
%%% with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
%%%
|
||||||
|
%%%----------------------------------------------------------------------
|
||||||
|
|
||||||
|
-module(stundisco_tests).
|
||||||
|
|
||||||
|
%% API
|
||||||
|
-compile(export_all).
|
||||||
|
-import(suite, [send_recv/2, disconnect/1, is_feature_advertised/2,
|
||||||
|
server_jid/1]).
|
||||||
|
|
||||||
|
-include("suite.hrl").
|
||||||
|
|
||||||
|
%%%===================================================================
|
||||||
|
%%% API
|
||||||
|
%%%===================================================================
|
||||||
|
%%%===================================================================
|
||||||
|
%%% Single user tests
|
||||||
|
%%%===================================================================
|
||||||
|
single_cases() ->
|
||||||
|
{stundisco_single, [sequence],
|
||||||
|
[single_test(feature_enabled),
|
||||||
|
single_test(stun_service),
|
||||||
|
single_test(turn_service),
|
||||||
|
single_test(turns_service),
|
||||||
|
single_test(turn_credentials),
|
||||||
|
single_test(turns_credentials)]}.
|
||||||
|
|
||||||
|
feature_enabled(Config) ->
|
||||||
|
true = is_feature_advertised(Config, ?NS_EXTDISCO_2),
|
||||||
|
disconnect(Config).
|
||||||
|
|
||||||
|
stun_service(Config) ->
|
||||||
|
ServerJID = server_jid(Config),
|
||||||
|
Host = {203, 0, 113, 3},
|
||||||
|
Port = ct:get_config(stun_port, 3478),
|
||||||
|
Type = stun,
|
||||||
|
Transport = udp,
|
||||||
|
Request = #services{type = Type},
|
||||||
|
#iq{type = result,
|
||||||
|
sub_els = [#services{
|
||||||
|
type = undefined,
|
||||||
|
list = [#service{host = Host,
|
||||||
|
port = Port,
|
||||||
|
type = Type,
|
||||||
|
transport = Transport,
|
||||||
|
restricted = false,
|
||||||
|
username = <<>>,
|
||||||
|
password = <<>>,
|
||||||
|
expires = undefined,
|
||||||
|
action = undefined,
|
||||||
|
xdata = undefined}]}]} =
|
||||||
|
send_recv(Config, #iq{type = get, to = ServerJID, sub_els = [Request]}),
|
||||||
|
disconnect(Config).
|
||||||
|
|
||||||
|
turn_service(Config) ->
|
||||||
|
ServerJID = server_jid(Config),
|
||||||
|
Host = {203, 0, 113, 3},
|
||||||
|
Port = ct:get_config(stun_port, 3478),
|
||||||
|
Type = turn,
|
||||||
|
Transport = udp,
|
||||||
|
Request = #services{type = Type},
|
||||||
|
#iq{type = result,
|
||||||
|
sub_els = [#services{
|
||||||
|
type = undefined,
|
||||||
|
list = [#service{host = Host,
|
||||||
|
port = Port,
|
||||||
|
type = Type,
|
||||||
|
transport = Transport,
|
||||||
|
restricted = true,
|
||||||
|
username = Username,
|
||||||
|
password = Password,
|
||||||
|
expires = Expires,
|
||||||
|
action = undefined,
|
||||||
|
xdata = undefined}]}]} =
|
||||||
|
send_recv(Config, #iq{type = get, to = ServerJID, sub_els = [Request]}),
|
||||||
|
true = check_password(Username, Password),
|
||||||
|
true = check_expires(Expires),
|
||||||
|
disconnect(Config).
|
||||||
|
|
||||||
|
turns_service(Config) ->
|
||||||
|
ServerJID = server_jid(Config),
|
||||||
|
Host = <<"example.com">>,
|
||||||
|
Port = 5349,
|
||||||
|
Type = turns,
|
||||||
|
Transport = tcp,
|
||||||
|
Request = #services{type = Type},
|
||||||
|
#iq{type = result,
|
||||||
|
sub_els = [#services{
|
||||||
|
type = undefined,
|
||||||
|
list = [#service{host = Host,
|
||||||
|
port = Port,
|
||||||
|
type = Type,
|
||||||
|
transport = Transport,
|
||||||
|
restricted = true,
|
||||||
|
username = Username,
|
||||||
|
password = Password,
|
||||||
|
expires = Expires,
|
||||||
|
action = undefined,
|
||||||
|
xdata = undefined}]}]} =
|
||||||
|
send_recv(Config, #iq{type = get, to = ServerJID, sub_els = [Request]}),
|
||||||
|
true = check_password(Username, Password),
|
||||||
|
true = check_expires(Expires),
|
||||||
|
disconnect(Config).
|
||||||
|
|
||||||
|
turn_credentials(Config) ->
|
||||||
|
ServerJID = server_jid(Config),
|
||||||
|
Host = {203, 0, 113, 3},
|
||||||
|
Port = ct:get_config(stun_port, 3478),
|
||||||
|
Type = turn,
|
||||||
|
Transport = udp,
|
||||||
|
Request = #credentials{services = [#service{host = Host,
|
||||||
|
port = Port,
|
||||||
|
type = Type}]},
|
||||||
|
#iq{type = result,
|
||||||
|
sub_els = [#services{
|
||||||
|
type = undefined,
|
||||||
|
list = [#service{host = Host,
|
||||||
|
port = Port,
|
||||||
|
type = Type,
|
||||||
|
transport = Transport,
|
||||||
|
restricted = true,
|
||||||
|
username = Username,
|
||||||
|
password = Password,
|
||||||
|
expires = Expires,
|
||||||
|
action = undefined,
|
||||||
|
xdata = undefined}]}]} =
|
||||||
|
send_recv(Config, #iq{type = get, to = ServerJID, sub_els = [Request]}),
|
||||||
|
true = check_password(Username, Password),
|
||||||
|
true = check_expires(Expires),
|
||||||
|
disconnect(Config).
|
||||||
|
|
||||||
|
turns_credentials(Config) ->
|
||||||
|
ServerJID = server_jid(Config),
|
||||||
|
Host = <<"example.com">>,
|
||||||
|
Port = 5349,
|
||||||
|
Type = turns,
|
||||||
|
Transport = tcp,
|
||||||
|
Request = #credentials{services = [#service{host = Host,
|
||||||
|
port = Port,
|
||||||
|
type = Type}]},
|
||||||
|
#iq{type = result,
|
||||||
|
sub_els = [#services{
|
||||||
|
type = undefined,
|
||||||
|
list = [#service{host = Host,
|
||||||
|
port = Port,
|
||||||
|
type = Type,
|
||||||
|
transport = Transport,
|
||||||
|
restricted = true,
|
||||||
|
username = Username,
|
||||||
|
password = Password,
|
||||||
|
expires = Expires,
|
||||||
|
action = undefined,
|
||||||
|
xdata = undefined}]}]} =
|
||||||
|
send_recv(Config, #iq{type = get, to = ServerJID, sub_els = [Request]}),
|
||||||
|
true = check_password(Username, Password),
|
||||||
|
true = check_expires(Expires),
|
||||||
|
disconnect(Config).
|
||||||
|
|
||||||
|
%%%===================================================================
|
||||||
|
%%% Internal functions
|
||||||
|
%%%===================================================================
|
||||||
|
single_test(T) ->
|
||||||
|
list_to_atom("stundisco_" ++ atom_to_list(T)).
|
||||||
|
|
||||||
|
check_password(Username, Password) ->
|
||||||
|
Secret = <<"cryptic">>,
|
||||||
|
Password == base64:encode(crypto:hmac(sha, Secret, Username)).
|
||||||
|
|
||||||
|
check_expires({_, _, _} = Expires) ->
|
||||||
|
Now = {MegaSecs, Secs, MicroSecs} = erlang:timestamp(),
|
||||||
|
Later = {MegaSecs + 1, Secs, MicroSecs},
|
||||||
|
(Expires > Now) and (Expires < Later).
|
@ -60,6 +60,7 @@ init_config(Config) ->
|
|||||||
{loglevel, 4},
|
{loglevel, 4},
|
||||||
{new_schema, false},
|
{new_schema, false},
|
||||||
{s2s_port, 5269},
|
{s2s_port, 5269},
|
||||||
|
{stun_port, 3478},
|
||||||
{component_port, 5270},
|
{component_port, 5270},
|
||||||
{web_port, 5280},
|
{web_port, 5280},
|
||||||
{proxy_port, 7777},
|
{proxy_port, 7777},
|
||||||
|
Loading…
Reference in New Issue
Block a user