diff options
author | Paweł Chmielowski <pchmielowski@process-one.net> | 2016-12-01 18:51:15 +0100 |
---|---|---|
committer | Paweł Chmielowski <pchmielowski@process-one.net> | 2016-12-01 18:51:23 +0100 |
commit | 68cf6845e153081c2bc6ad71a1e82085000d9fda (patch) | |
tree | 940d088f09cbcdc00cd1c687b502f169c2e72e0b /test | |
parent | Add more tests for digest-md5 cyrsasl (diff) |
Fix mod_http_api_mock_test on 19.1
Diffstat (limited to 'test')
-rw-r--r-- | test/mod_http_api_mock_test.exs | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/test/mod_http_api_mock_test.exs b/test/mod_http_api_mock_test.exs index 4809ecd5..9ab53bee 100644 --- a/test/mod_http_api_mock_test.exs +++ b/test/mod_http_api_mock_test.exs @@ -69,13 +69,17 @@ defmodule ModHttpApiMockTest do # Mock a simple command() -> :ok :meck.expect(:ejabberd_commands, :get_command_format, - fn (@acommand, {@user, @domain, @userpass, false}, @version) -> + fn (@acommand, %{usr: {@user, @domain, _}}, @version) -> {[], {:res, :rescode}} end) :meck.expect(:ejabberd_commands, :get_command_policy_and_scope, fn (@acommand) -> {:ok, :user, [:erlang.atom_to_binary(@acommand,:utf8)]} end) :meck.expect(:ejabberd_commands, :get_exposed_commands, fn () -> [@acommand] end) + :meck.expect(:ejabberd_commands, :execute_command2, + fn (@acommand, [], %{usr: {@user, @domain, _}}, @version) -> + :ok + end) :meck.expect(:ejabberd_commands, :execute_command, fn (:undefined, {@user, @domain, @userpass, false}, @acommand, [], @version, _) -> :ok @@ -111,7 +115,7 @@ defmodule ModHttpApiMockTest do # Check that the command was executed only once 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_commands @@ -122,13 +126,21 @@ defmodule ModHttpApiMockTest do # Mock a simple command() -> :ok :meck.expect(:ejabberd_commands, :get_command_format, - fn (@acommand, {@user, @domain, {:oauth, _token}, false}, @version) -> - {[], {:res, :rescode}} + fn (@acommand, %{usr: {@user, @domain, _}}, @version) -> + {[], {:res, :rescode}} end) :meck.expect(:ejabberd_commands, :get_command_policy_and_scope, fn (@acommand) -> {:ok, :user, [:erlang.atom_to_binary(@acommand,:utf8), "ejabberd:user"]} end) :meck.expect(:ejabberd_commands, :get_exposed_commands, 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, fn (:undefined, {@user, @domain, {:oauth, _token}, false}, @acommand, [], @version, _) -> @@ -197,14 +209,14 @@ defmodule ModHttpApiMockTest do ip: {{127,0,0,1},60000}, host: @domain) 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 - assert 2 == - :meck.num_calls(:ejabberd_commands, :execute_command, :_) + assert 3 == + :meck.num_calls(:ejabberd_commands, :execute_command2, :_) assert :meck.validate :ejabberd_auth - assert :meck.validate :ejabberd_commands + #assert :meck.validate :ejabberd_commands #assert :ok = :meck.history(:ejabberd_commands) end |