mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
Fix mod_http_api_mock_test on 19.1
This commit is contained in:
parent
294d58a393
commit
68cf6845e1
@ -69,13 +69,17 @@ defmodule ModHttpApiMockTest do
|
|||||||
|
|
||||||
# Mock a simple command() -> :ok
|
# Mock a simple command() -> :ok
|
||||||
:meck.expect(:ejabberd_commands, :get_command_format,
|
:meck.expect(:ejabberd_commands, :get_command_format,
|
||||||
fn (@acommand, {@user, @domain, @userpass, false}, @version) ->
|
fn (@acommand, %{usr: {@user, @domain, _}}, @version) ->
|
||||||
{[], {:res, :rescode}}
|
{[], {:res, :rescode}}
|
||||||
end)
|
end)
|
||||||
:meck.expect(:ejabberd_commands, :get_command_policy_and_scope,
|
:meck.expect(:ejabberd_commands, :get_command_policy_and_scope,
|
||||||
fn (@acommand) -> {:ok, :user, [:erlang.atom_to_binary(@acommand,:utf8)]} end)
|
fn (@acommand) -> {:ok, :user, [:erlang.atom_to_binary(@acommand,:utf8)]} end)
|
||||||
:meck.expect(:ejabberd_commands, :get_exposed_commands,
|
:meck.expect(:ejabberd_commands, :get_exposed_commands,
|
||||||
fn () -> [@acommand] end)
|
fn () -> [@acommand] end)
|
||||||
|
:meck.expect(:ejabberd_commands, :execute_command2,
|
||||||
|
fn (@acommand, [], %{usr: {@user, @domain, _}}, @version) ->
|
||||||
|
:ok
|
||||||
|
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
|
||||||
@ -111,7 +115,7 @@ defmodule ModHttpApiMockTest do
|
|||||||
|
|
||||||
# Check that the command was executed only once
|
# Check that the command was executed only once
|
||||||
assert 1 ==
|
assert 1 ==
|
||||||
:meck.num_calls(:ejabberd_commands, :execute_command, :_)
|
:meck.num_calls(:ejabberd_commands, :execute_command2, :_)
|
||||||
|
|
||||||
assert :meck.validate :ejabberd_auth
|
assert :meck.validate :ejabberd_auth
|
||||||
assert :meck.validate :ejabberd_commands
|
assert :meck.validate :ejabberd_commands
|
||||||
@ -122,13 +126,21 @@ defmodule ModHttpApiMockTest do
|
|||||||
|
|
||||||
# Mock a simple command() -> :ok
|
# Mock a simple command() -> :ok
|
||||||
:meck.expect(:ejabberd_commands, :get_command_format,
|
:meck.expect(:ejabberd_commands, :get_command_format,
|
||||||
fn (@acommand, {@user, @domain, {:oauth, _token}, false}, @version) ->
|
fn (@acommand, %{usr: {@user, @domain, _}}, @version) ->
|
||||||
{[], {:res, :rescode}}
|
{[], {:res, :rescode}}
|
||||||
end)
|
end)
|
||||||
:meck.expect(:ejabberd_commands, :get_command_policy_and_scope,
|
:meck.expect(:ejabberd_commands, :get_command_policy_and_scope,
|
||||||
fn (@acommand) -> {:ok, :user, [:erlang.atom_to_binary(@acommand,:utf8), "ejabberd:user"]} end)
|
fn (@acommand) -> {:ok, :user, [:erlang.atom_to_binary(@acommand,:utf8), "ejabberd:user"]} end)
|
||||||
:meck.expect(:ejabberd_commands, :get_exposed_commands,
|
:meck.expect(:ejabberd_commands, :get_exposed_commands,
|
||||||
fn () -> [@acommand] end)
|
fn () -> [@acommand] end)
|
||||||
|
:meck.expect(:ejabberd_commands, :execute_command2,
|
||||||
|
fn (@acommand, [], %{usr: {@user, @domain, _}, oauth_scope: ["ejabberd:user"]}, @version) ->
|
||||||
|
:ok
|
||||||
|
(@acommand, [], %{usr: {@user, @domain, _}, oauth_scope: [@command]}, @version) ->
|
||||||
|
:ok
|
||||||
|
(@acommand, [], %{usr: {@user, @domain, _}, oauth_scope: _}, @version) ->
|
||||||
|
throw({:error, :access_rules_unauthorized})
|
||||||
|
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, _) ->
|
||||||
@ -197,14 +209,14 @@ defmodule ModHttpApiMockTest 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)
|
||||||
assert 401 == elem(result, 0) # HTTP code
|
assert 403 == elem(result, 0) # HTTP code
|
||||||
|
|
||||||
# Check that the command was executed twice
|
# Check that the command was executed twice
|
||||||
assert 2 ==
|
assert 3 ==
|
||||||
:meck.num_calls(:ejabberd_commands, :execute_command, :_)
|
:meck.num_calls(:ejabberd_commands, :execute_command2, :_)
|
||||||
|
|
||||||
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)
|
#assert :ok = :meck.history(:ejabberd_commands)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user