mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-22 17:28:25 +01:00
Add baisc tests for webadmin
This commit is contained in:
parent
f17d4c0adc
commit
a2d1ffffe6
@ -259,6 +259,8 @@ init_per_testcase(TestCase, OrigConfig) ->
|
|||||||
case Test of
|
case Test of
|
||||||
"test_connect" ++ _ ->
|
"test_connect" ++ _ ->
|
||||||
Config;
|
Config;
|
||||||
|
"webadmin_" ++ _ ->
|
||||||
|
Config;
|
||||||
"test_legacy_auth_feature" ->
|
"test_legacy_auth_feature" ->
|
||||||
connect(Config);
|
connect(Config);
|
||||||
"test_legacy_auth" ++ _ ->
|
"test_legacy_auth" ++ _ ->
|
||||||
@ -372,6 +374,7 @@ db_tests(DB) when DB == mnesia; DB == redis ->
|
|||||||
auth_md5,
|
auth_md5,
|
||||||
presence_broadcast,
|
presence_broadcast,
|
||||||
last,
|
last,
|
||||||
|
webadmin_tests:single_cases(),
|
||||||
roster_tests:single_cases(),
|
roster_tests:single_cases(),
|
||||||
private_tests:single_cases(),
|
private_tests:single_cases(),
|
||||||
privacy_tests:single_cases(),
|
privacy_tests:single_cases(),
|
||||||
@ -401,6 +404,7 @@ db_tests(DB) ->
|
|||||||
auth_md5,
|
auth_md5,
|
||||||
presence_broadcast,
|
presence_broadcast,
|
||||||
last,
|
last,
|
||||||
|
webadmin_tests:single_cases(),
|
||||||
roster_tests:single_cases(),
|
roster_tests:single_cases(),
|
||||||
private_tests:single_cases(),
|
private_tests:single_cases(),
|
||||||
privacy_tests:single_cases(),
|
privacy_tests:single_cases(),
|
||||||
|
@ -66,6 +66,8 @@ access_rules:
|
|||||||
acl:
|
acl:
|
||||||
local:
|
local:
|
||||||
user_regexp: ""
|
user_regexp: ""
|
||||||
|
admin:
|
||||||
|
user: "admin"
|
||||||
language: en
|
language: en
|
||||||
listen:
|
listen:
|
||||||
-
|
-
|
||||||
@ -84,6 +86,7 @@ listen:
|
|||||||
port: WEB_PORT
|
port: WEB_PORT
|
||||||
module: ejabberd_http
|
module: ejabberd_http
|
||||||
request_handlers:
|
request_handlers:
|
||||||
|
"/admin": ejabberd_web_admin
|
||||||
"/api": mod_http_api
|
"/api": mod_http_api
|
||||||
"/upload": mod_http_upload
|
"/upload": mod_http_upload
|
||||||
"/captcha": ejabberd_captcha
|
"/captcha": ejabberd_captcha
|
||||||
|
73
test/webadmin_tests.erl
Normal file
73
test/webadmin_tests.erl
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
%%%-------------------------------------------------------------------
|
||||||
|
%%% Author : Pawel Chmielowski <pawel@process-one.net>
|
||||||
|
%%% Created : 23 Mar 2020 by Pawel Chmielowski <pawel@process-one.net>
|
||||||
|
%%%
|
||||||
|
%%%
|
||||||
|
%%% ejabberd, Copyright (C) 2002-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(webadmin_tests).
|
||||||
|
|
||||||
|
%% API
|
||||||
|
-compile(export_all).
|
||||||
|
-import(suite, [disconnect/1, is_feature_advertised/3, upload_jid/1,
|
||||||
|
my_jid/1, wait_for_slave/1, wait_for_master/1,
|
||||||
|
send_recv/2, put_event/2, get_event/1]).
|
||||||
|
|
||||||
|
-include("suite.hrl").
|
||||||
|
-include_lib("stdlib/include/assert.hrl").
|
||||||
|
|
||||||
|
%%%===================================================================
|
||||||
|
%%% API
|
||||||
|
%%%===================================================================
|
||||||
|
%%%===================================================================
|
||||||
|
%%% Single user tests
|
||||||
|
%%%===================================================================
|
||||||
|
single_cases() ->
|
||||||
|
{webadmin_single, [sequence],
|
||||||
|
[single_test(login_page),
|
||||||
|
single_test(welcome_page)]}.
|
||||||
|
|
||||||
|
login_page(Config) ->
|
||||||
|
Headers = ?match({ok, {{"HTTP/1.1", 401, _}, Headers, _}},
|
||||||
|
httpc:request(get, {page(Config, ""), []}, [],
|
||||||
|
[{body_format, binary}]),
|
||||||
|
Headers),
|
||||||
|
?match("basic realm=\"ejabberd\"", proplists:get_value("www-authenticate", Headers, none)).
|
||||||
|
|
||||||
|
welcome_page(Config) ->
|
||||||
|
Body = ?match({ok, {{"HTTP/1.1", 200, _}, _, Body}},
|
||||||
|
httpc:request(get, {page(Config, ""), [basic_auth_header(Config)]}, [],
|
||||||
|
[{body_format, binary}]),
|
||||||
|
Body),
|
||||||
|
?match({_, _}, binary:match(Body, <<"ejabberd Web Admin">>)).
|
||||||
|
|
||||||
|
%%%===================================================================
|
||||||
|
%%% Internal functions
|
||||||
|
%%%===================================================================
|
||||||
|
single_test(T) ->
|
||||||
|
list_to_atom("webadmin_" ++ atom_to_list(T)).
|
||||||
|
|
||||||
|
basic_auth_header(Config) ->
|
||||||
|
Server = ?config(server, Config),
|
||||||
|
ejabberd_auth:try_register(<<"admin">>, Server, <<"pass">>),
|
||||||
|
{"authorization", "Basic "++base64:encode_to_string(<<"admin@", Server/binary, ":pass">>)}.
|
||||||
|
|
||||||
|
page(Config, Tail) ->
|
||||||
|
Server = ?config(server_host, Config),
|
||||||
|
Port = ct:get_config(web_port, 5280),
|
||||||
|
"http://" ++ Server ++ ":" ++ integer_to_list(Port) ++ "/admin/" ++ Tail.
|
Loading…
Reference in New Issue
Block a user