]> granicus.if.org Git - ejabberd/commitdiff
Port mod_admin_extra test to work with new API
authorMickael Remond <mremond@process-one.net>
Thu, 31 Mar 2016 20:01:57 +0000 (22:01 +0200)
committerMickael Remond <mremond@process-one.net>
Thu, 31 Mar 2016 20:01:57 +0000 (22:01 +0200)
test/ejabberd_auth_mock.exs
test/elixir_SUITE.erl
test/mod_admin_extra_test.exs
test/mod_last_mock.exs
test/mod_roster_mock.exs

index 495c527f296254744612c3b2e79b843b5e71e965..bbe905142b59a6201d6c0d5588001b9dced2323f 100644 (file)
@@ -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)
index f92f750aa500299a3850fb5e2ecfe3ccbedb07e8..2d8c3c52d3bc51d5939d40654e65bd520b6fd553 100644 (file)
@@ -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(),
index 7fa39eef1af9705c719dbac79d75b580f508f8f4..d90aa045885d2ce9099f2f7cb96d9220851215ee 100644 (file)
@@ -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,
index 7e3dc5a1d19ef564fe8742cc3a5eb8fe1143479d..4f8da36665172b452a912eb6f45fb95d3e679ed3 100644 (file)
@@ -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
index b4991cfdeb3d78e34471efc4900823156bdfb889..b1251ba863cbe30bc6c6c4c35bb52918f650b58e 100644 (file)
@@ -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,