mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-28 16:34:13 +01:00
Fix tests, they are now running fine locally
This commit is contained in:
parent
a8f92ae767
commit
b5f1479763
@ -41,7 +41,7 @@ defmodule EjabberdAuthMock do
|
|||||||
Agent.get(@agent, fn users -> Map.get(users, {user, domain}, "") end )
|
Agent.get(@agent, fn users -> Map.get(users, {user, domain}, "") end )
|
||||||
end)
|
end)
|
||||||
mock(:ejabberd_auth, :check_password,
|
mock(:ejabberd_auth, :check_password,
|
||||||
fn (user, authzid, domain, password) ->
|
fn (user, _authzid, domain, password) ->
|
||||||
Agent.get(@agent, fn users ->
|
Agent.get(@agent, fn users ->
|
||||||
Map.get(users, {user, domain}) end) == password
|
Map.get(users, {user, domain}) end) == password
|
||||||
end)
|
end)
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
#
|
#
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
|
|
||||||
defmodule EjabberdCommandsTest do
|
defmodule EjabberdCommandsMockTest do
|
||||||
use ExUnit.Case, async: false
|
use ExUnit.Case, async: false
|
||||||
|
|
||||||
@author "jsautret@process-one.net"
|
@author "jsautret@process-one.net"
|
||||||
@ -35,8 +35,7 @@ defmodule EjabberdCommandsTest do
|
|||||||
@domain "domain"
|
@domain "domain"
|
||||||
|
|
||||||
require Record
|
require Record
|
||||||
Record.defrecord :ejabberd_commands, Record.extract(:ejabberd_commands,
|
Record.defrecord :ejabberd_commands, Record.extract(:ejabberd_commands, from_lib: "ejabberd/include/ejabberd_commands.hrl")
|
||||||
from: "ejabberd_commands.hrl")
|
|
||||||
|
|
||||||
setup_all do
|
setup_all do
|
||||||
try do
|
try do
|
||||||
|
@ -1,5 +1,22 @@
|
|||||||
# ejabberd_oauth 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 EjabberdOauthMock do
|
defmodule EjabberdOauthMock do
|
||||||
|
|
||||||
|
@ -1,14 +1,29 @@
|
|||||||
# ejabberd_sm 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 EjabberdSmMock do
|
defmodule EjabberdSmMock do
|
||||||
@author "jsautret@process-one.net"
|
@author "jsautret@process-one.net"
|
||||||
|
|
||||||
require Record
|
require Record
|
||||||
Record.defrecord :session, Record.extract(:session,
|
Record.defrecord :session, Record.extract(:session, from_lib: "ejabberd/include/ejabberd_sm.hrl")
|
||||||
from: "ejabberd_sm.hrl")
|
Record.defrecord :jid, Record.extract(:jid, from_lib: "ejabberd/include/jlib.hrl")
|
||||||
Record.defrecord :jid, Record.extract(:jid,
|
|
||||||
from: "jlib.hrl")
|
|
||||||
|
|
||||||
@agent __MODULE__
|
@agent __MODULE__
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
#
|
#
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
|
|
||||||
defmodule ModHttpApiTest do
|
defmodule ModHttpApiMockTest do
|
||||||
use ExUnit.Case, async: false
|
use ExUnit.Case, async: false
|
||||||
|
|
||||||
@author "jsautret@process-one.net"
|
@author "jsautret@process-one.net"
|
||||||
@ -38,12 +38,15 @@ defmodule ModHttpApiTest do
|
|||||||
@version 0
|
@version 0
|
||||||
|
|
||||||
require Record
|
require Record
|
||||||
Record.defrecord :request, Record.extract(:request,
|
Record.defrecord :request, Record.extract(:request, from_lib: "ejabberd/include/ejabberd_http.hrl")
|
||||||
from: "ejabberd_http.hrl")
|
|
||||||
|
|
||||||
setup_all do
|
setup_all do
|
||||||
try do
|
try do
|
||||||
|
:jid.start
|
||||||
|
:mnesia.start
|
||||||
:stringprep.start
|
:stringprep.start
|
||||||
|
:ejabberd_config.start([@domain], [])
|
||||||
|
:ejabberd_commands.init
|
||||||
rescue
|
rescue
|
||||||
_ -> :ok
|
_ -> :ok
|
||||||
end
|
end
|
||||||
@ -67,13 +70,16 @@ defmodule ModHttpApiTest do
|
|||||||
fn (@acommand, {@user, @domain, @userpass, false}, @version) ->
|
fn (@acommand, {@user, @domain, @userpass, false}, @version) ->
|
||||||
{[], {:res, :rescode}}
|
{[], {:res, :rescode}}
|
||||||
end)
|
end)
|
||||||
|
:meck.expect(:ejabberd_commands, :get_command_policy,
|
||||||
|
fn (@acommand) -> {:ok, :user} end)
|
||||||
|
:meck.expect(:ejabberd_commands, :get_commands,
|
||||||
|
fn () -> [@acommand] end)
|
||||||
:meck.expect(:ejabberd_commands, :execute_command,
|
:meck.expect(:ejabberd_commands, :execute_command,
|
||||||
fn (:undefined, {@user, @domain, @userpass, false}, @acommand, [], @version) ->
|
fn (:undefined, {@user, @domain, @userpass, false}, @acommand, [], @version) ->
|
||||||
:ok
|
:ok
|
||||||
end)
|
end)
|
||||||
|
|
||||||
#:ejabberd_logger.start
|
:ejabberd_config.add_local_option(:commands, [[{:add_commands, [@acommand]}]])
|
||||||
#:ejabberd_logger.set 5
|
|
||||||
|
|
||||||
# Correct Basic Auth call
|
# Correct Basic Auth call
|
||||||
req = request(method: :GET,
|
req = request(method: :GET,
|
||||||
@ -84,6 +90,9 @@ defmodule ModHttpApiTest do
|
|||||||
ip: {{127,0,0,1},60000},
|
ip: {{127,0,0,1},60000},
|
||||||
host: @domain)
|
host: @domain)
|
||||||
result = :mod_http_api.process([@command], req)
|
result = :mod_http_api.process([@command], req)
|
||||||
|
|
||||||
|
# history = :meck.history(:ejabberd_commands)
|
||||||
|
|
||||||
assert 200 == elem(result, 0) # HTTP code
|
assert 200 == elem(result, 0) # HTTP code
|
||||||
assert "0" == elem(result, 2) # command result
|
assert "0" == elem(result, 2) # command result
|
||||||
|
|
||||||
@ -104,10 +113,8 @@ defmodule ModHttpApiTest do
|
|||||||
|
|
||||||
assert :meck.validate :ejabberd_auth
|
assert :meck.validate :ejabberd_auth
|
||||||
assert :meck.validate :ejabberd_commands
|
assert :meck.validate :ejabberd_commands
|
||||||
#assert :ok = :meck.history(:ejabberd_commands)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
test "HTTP GET simple command call with OAuth" do
|
test "HTTP GET simple command call with OAuth" do
|
||||||
EjabberdAuthMock.create_user @user, @domain, @userpass
|
EjabberdAuthMock.create_user @user, @domain, @userpass
|
||||||
|
|
||||||
@ -116,14 +123,16 @@ defmodule ModHttpApiTest do
|
|||||||
fn (@acommand, {@user, @domain, {:oauth, _token}, false}, @version) ->
|
fn (@acommand, {@user, @domain, {:oauth, _token}, false}, @version) ->
|
||||||
{[], {:res, :rescode}}
|
{[], {:res, :rescode}}
|
||||||
end)
|
end)
|
||||||
|
:meck.expect(:ejabberd_commands, :get_command_policy,
|
||||||
|
fn (@acommand) -> {:ok, :user} end)
|
||||||
|
:meck.expect(:ejabberd_commands, :get_commands,
|
||||||
|
fn () -> [@acommand] end)
|
||||||
:meck.expect(:ejabberd_commands, :execute_command,
|
:meck.expect(:ejabberd_commands, :execute_command,
|
||||||
fn (:undefined, {@user, @domain, {:oauth, _token}, false},
|
fn (:undefined, {@user, @domain, {:oauth, _token}, false},
|
||||||
@acommand, [], @version) ->
|
@acommand, [], @version) ->
|
||||||
:ok
|
:ok
|
||||||
end)
|
end)
|
||||||
|
|
||||||
#:ejabberd_logger.start
|
|
||||||
#:ejabberd_logger.set 5
|
|
||||||
|
|
||||||
# Correct OAuth call
|
# Correct OAuth call
|
||||||
token = EjabberdOauthMock.get_token @user, @domain, @command
|
token = EjabberdOauthMock.get_token @user, @domain, @command
|
||||||
|
Loading…
Reference in New Issue
Block a user