mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-24 17:29:28 +01:00
Port mod_admin_extra test to work with new API
This commit is contained in:
parent
ef2e2e45b3
commit
97d345d287
@ -1,5 +1,22 @@
|
||||
# ejabberd_auth mock
|
||||
######################
|
||||
# ----------------------------------------------------------------------
|
||||
#
|
||||
# ejabberd, Copyright (C) 2002-2016 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.
|
||||
#
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
defmodule EjabberdAuthMock do
|
||||
|
||||
@ -24,7 +41,7 @@ defmodule EjabberdAuthMock do
|
||||
Agent.get(@agent, fn users -> Map.get(users, {user, domain}, "") end )
|
||||
end)
|
||||
mock(:ejabberd_auth, :check_password,
|
||||
fn (user, domain, password) ->
|
||||
fn (user, authzid, domain, password) ->
|
||||
Agent.get(@agent, fn users ->
|
||||
Map.get(users, {user, domain}) end) == password
|
||||
end)
|
||||
|
@ -69,6 +69,13 @@ run_elixir_test(Func) ->
|
||||
%% Elixir tests can be tagged as follow to be ignored (place before test start)
|
||||
%% @tag pending: true
|
||||
'Elixir.ExUnit':start([{exclude, [{pending, true}]}]),
|
||||
|
||||
filelib:fold_files(test_dir(), ".*mock\.exs\$", true,
|
||||
fun (File, N) ->
|
||||
'Elixir.Code':load_file(list_to_binary(File)),
|
||||
N+1
|
||||
end, 0),
|
||||
|
||||
'Elixir.Code':load_file(list_to_binary(filename:join(test_dir(), atom_to_list(Func)))),
|
||||
%% I did not use map syntax, so that this file can still be build under R16
|
||||
ResultMap = 'Elixir.ExUnit':run(),
|
||||
|
@ -21,6 +21,8 @@
|
||||
defmodule EjabberdModAdminExtraTest do
|
||||
use ExUnit.Case, async: false
|
||||
|
||||
require EjabberdAuthMock
|
||||
|
||||
@author "jsautret@process-one.net"
|
||||
|
||||
@user "user"
|
||||
@ -29,11 +31,11 @@ defmodule EjabberdModAdminExtraTest do
|
||||
@resource "resource"
|
||||
|
||||
require Record
|
||||
Record.defrecord :jid, Record.extract(:jid,
|
||||
from: "jlib.hrl")
|
||||
Record.defrecord :jid, Record.extract(:jid, from_lib: "ejabberd/include/jlib.hrl")
|
||||
|
||||
setup_all do
|
||||
try do
|
||||
:jid.start
|
||||
:stringprep.start
|
||||
:mnesia.start
|
||||
:p1_sha.load_nif
|
||||
@ -71,13 +73,13 @@ defmodule EjabberdModAdminExtraTest do
|
||||
EjabberdAuthMock.create_user @user, @domain, @password
|
||||
|
||||
assert :ejabberd_commands.execute_command(:check_password,
|
||||
[@user, @domain, @password])
|
||||
[@user, <<"">>, @domain, @password])
|
||||
refute :ejabberd_commands.execute_command(:check_password,
|
||||
[@user, @domain, "bad_password"])
|
||||
[@user, <<"">>, @domain, "bad_password"])
|
||||
refute :ejabberd_commands.execute_command(:check_password,
|
||||
[@user, "bad_domain", @password])
|
||||
[@user, <<"">>, "bad_domain", @password])
|
||||
refute :ejabberd_commands.execute_command(:check_password,
|
||||
["bad_user", @domain, @password])
|
||||
["bad_user", <<"">>, @domain, @password])
|
||||
|
||||
assert :meck.validate :ejabberd_auth
|
||||
|
||||
@ -115,9 +117,9 @@ defmodule EjabberdModAdminExtraTest do
|
||||
assert :ejabberd_commands.execute_command(:change_password,
|
||||
[@user, @domain, "new_password"])
|
||||
refute :ejabberd_commands.execute_command(:check_password,
|
||||
[@user, @domain, @password])
|
||||
[@user, <<"">>, @domain, @password])
|
||||
assert :ejabberd_commands.execute_command(:check_password,
|
||||
[@user, @domain, "new_password"])
|
||||
[@user, <<"">>, @domain, "new_password"])
|
||||
assert {:not_found, 'unknown_user'} ==
|
||||
catch_throw :ejabberd_commands.execute_command(:change_password,
|
||||
["bad_user", @domain,
|
||||
|
@ -1,15 +1,29 @@
|
||||
# mod_last mock
|
||||
######################
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
#
|
||||
# ejabberd, Copyright (C) 2002-2016 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.
|
||||
#
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
defmodule ModLastMock do
|
||||
|
||||
require Record
|
||||
Record.defrecord :session, Record.extract(:session,
|
||||
from: "ejabberd_sm.hrl")
|
||||
Record.defrecord :jid, Record.extract(:jid,
|
||||
from: "jlib.hrl")
|
||||
|
||||
Record.defrecord :session, Record.extract(:session, from_lib: "ejabberd/include/ejabberd_sm.hrl")
|
||||
Record.defrecord :jid, Record.extract(:jid, from_lib: "ejabberd/include/jlib.hrl")
|
||||
|
||||
@author "jsautret@process-one.net"
|
||||
@agent __MODULE__
|
||||
|
||||
@ -19,9 +33,9 @@ defmodule ModLastMock do
|
||||
catch
|
||||
:exit, _e -> :ok
|
||||
end
|
||||
|
||||
|
||||
{:ok, _pid} = Agent.start_link(fn -> %{} end, name: @agent)
|
||||
|
||||
|
||||
mock(:mod_last, :get_last_info,
|
||||
fn (user, domain) ->
|
||||
Agent.get(@agent, fn last ->
|
||||
@ -32,11 +46,11 @@ defmodule ModLastMock do
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
def set_last(user, domain, status) do
|
||||
set_last(user, domain, status, now)
|
||||
end
|
||||
|
||||
|
||||
def set_last(user, domain, status, timestamp) do
|
||||
Agent.update(@agent, fn last ->
|
||||
Map.put(last, {user, domain}, {timestamp, status})
|
||||
@ -50,7 +64,7 @@ defmodule ModLastMock do
|
||||
{megasecs, secs, _microsecs} = :os.timestamp
|
||||
megasecs * 1000000 + secs
|
||||
end
|
||||
|
||||
|
||||
# TODO refactor: Move to ejabberd_test_mock
|
||||
def mock(module, function, fun) do
|
||||
try do
|
||||
|
@ -1,12 +1,28 @@
|
||||
# mod_roster mock
|
||||
######################
|
||||
# ----------------------------------------------------------------------
|
||||
#
|
||||
# ejabberd, Copyright (C) 2002-2016 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.
|
||||
#
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
defmodule ModRosterMock do
|
||||
@author "jsautret@process-one.net"
|
||||
|
||||
require Record
|
||||
Record.defrecord :roster, Record.extract(:roster,
|
||||
from: "mod_roster.hrl")
|
||||
Record.defrecord :roster, Record.extract(:roster, from_lib: "ejabberd/include/mod_roster.hrl")
|
||||
|
||||
@agent __MODULE__
|
||||
|
||||
@ -75,7 +91,7 @@ defmodule ModRosterMock do
|
||||
|
||||
:moka.replace(roster_mock, :del_roster_t,
|
||||
fn (user, domain, jid) ->
|
||||
remove_roster_item(user, domain, :jlib.jid_to_string(jid))
|
||||
remove_roster_item(user, domain, :jid.to_string(jid))
|
||||
end)
|
||||
|
||||
:moka.load(roster_mock)
|
||||
@ -163,7 +179,7 @@ defmodule ModRosterMock do
|
||||
def to_record({{user, domain, jid}, r}) do
|
||||
roster(usj: {user, domain, jid},
|
||||
us: {user, domain},
|
||||
jid: :jlib.string_to_usr(jid),
|
||||
jid: :jid.from_string(jid),
|
||||
subscription: r.subs,
|
||||
ask: r.ask,
|
||||
groups: r.groups,
|
||||
|
Loading…
Reference in New Issue
Block a user