Merge 0.10->trunk
[prosody.git] / tests / test_core_stanza_router.lua
index 97dc2e19358c88c9504e988e958d4d5eef473fda..ca6b78fce385c26b166860e900aa6eb76dd58c90 100644 (file)
@@ -1,7 +1,7 @@
 -- Prosody IM
 -- Copyright (C) 2008-2010 Matthew Wild
 -- Copyright (C) 2008-2010 Waqas Hussain
--- 
+--
 -- This project is MIT/X11 licensed. Please see the
 -- COPYING file in the source package for more information.
 --
@@ -14,7 +14,7 @@ function core_process_stanza(core_process_stanza, u)
        local s2sin_session = { from_host = "remotehost", to_host = "localhost", type = "s2sin", hosts = { ["remotehost"] = { authed = true } } }
        local local_host_session = { host = "localhost", type = "local", s2sout = { ["remotehost"] = s2sout_session } }
        local local_user_session = { username = "user", host = "localhost", resource = "resource", full_jid = "user@localhost/resource", type = "c2s" }
-       
+
        _G.prosody.hosts["localhost"] = local_host_session;
        _G.prosody.full_sessions["user@localhost/resource"] = local_user_session;
        _G.prosody.bare_sessions["user@localhost"] = { sessions = { resource = local_user_session } };
@@ -23,15 +23,15 @@ function core_process_stanza(core_process_stanza, u)
        local function test_message_full_jid()
                local env = testlib_new_env();
                local msg = stanza.stanza("message", { to = "user@localhost/resource", type = "chat" }):tag("body"):text("Hello world");
-               
+
                local target_routed;
-               
+
                function env.core_post_stanza(p_origin, p_stanza)
                        assert_equal(p_origin, local_user_session, "origin of routed stanza is not correct");
                        assert_equal(p_stanza, msg, "routed stanza is not correct one: "..p_stanza:pretty_print());
                        target_routed = true;
                end
-               
+
                env.hosts = hosts;
                env.prosody = { hosts = hosts };
                setfenv(core_process_stanza, env);
@@ -42,9 +42,9 @@ function core_process_stanza(core_process_stanza, u)
        local function test_message_bare_jid()
                local env = testlib_new_env();
                local msg = stanza.stanza("message", { to = "user@localhost", type = "chat" }):tag("body"):text("Hello world");
-               
+
                local target_routed;
-               
+
                function env.core_post_stanza(p_origin, p_stanza)
                        assert_equal(p_origin, local_user_session, "origin of routed stanza is not correct");
                        assert_equal(p_stanza, msg, "routed stanza is not correct one: "..p_stanza:pretty_print());
@@ -60,13 +60,13 @@ function core_process_stanza(core_process_stanza, u)
        local function test_message_no_to()
                local env = testlib_new_env();
                local msg = stanza.stanza("message", { type = "chat" }):tag("body"):text("Hello world");
-               
+
                local target_handled;
-               
+
                function env.core_post_stanza(p_origin, p_stanza)
                        assert_equal(p_origin, local_user_session, "origin of handled stanza is not correct");
                        assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print());
-                       target_handled = true;          
+                       target_handled = true;
                end
 
                env.hosts = hosts;
@@ -78,17 +78,17 @@ function core_process_stanza(core_process_stanza, u)
        local function test_message_to_remote_bare()
                local env = testlib_new_env();
                local msg = stanza.stanza("message", { to = "user@remotehost", type = "chat" }):tag("body"):text("Hello world");
-               
+
                local target_routed;
-               
+
                function env.core_route_stanza(p_origin, p_stanza)
                        assert_equal(p_origin, local_user_session, "origin of handled stanza is not correct");
                        assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print());
-                       target_routed = true;           
+                       target_routed = true;
                end
 
                function env.core_post_stanza(...) env.core_route_stanza(...); end
-               
+
                env.hosts = hosts;
                setfenv(core_process_stanza, env);
                assert_equal(core_process_stanza(local_user_session, msg), nil, "core_process_stanza returned incorrect value");
@@ -98,13 +98,13 @@ function core_process_stanza(core_process_stanza, u)
        local function test_message_to_remote_server()
                local env = testlib_new_env();
                local msg = stanza.stanza("message", { to = "remotehost", type = "chat" }):tag("body"):text("Hello world");
-               
+
                local target_routed;
-               
+
                function env.core_route_stanza(p_origin, p_stanza)
                        assert_equal(p_origin, local_user_session, "origin of handled stanza is not correct");
                        assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print());
-                       target_routed = true;           
+                       target_routed = true;
                end
 
                function env.core_post_stanza(...)
@@ -123,13 +123,13 @@ function core_process_stanza(core_process_stanza, u)
        local function test_iq_to_remote_server()
                local env = testlib_new_env();
                local msg = stanza.stanza("iq", { to = "remotehost", type = "get", id = "id" }):tag("body"):text("Hello world");
-               
+
                local target_routed;
-               
+
                function env.core_route_stanza(p_origin, p_stanza)
                        assert_equal(p_origin, local_user_session, "origin of handled stanza is not correct");
                        assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print());
-                       target_routed = true;           
+                       target_routed = true;
                end
 
                function env.core_post_stanza(...)
@@ -145,13 +145,13 @@ function core_process_stanza(core_process_stanza, u)
        local function test_iq_error_to_local_user()
                local env = testlib_new_env();
                local msg = stanza.stanza("iq", { to = "user@localhost/resource", from = "user@remotehost", type = "error", id = "id" }):tag("error", { type = 'cancel' }):tag("item-not-found", { xmlns='urn:ietf:params:xml:ns:xmpp-stanzas' });
-               
+
                local target_routed;
-               
+
                function env.core_route_stanza(p_origin, p_stanza)
                        assert_equal(p_origin, s2sin_session, "origin of handled stanza is not correct");
                        assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print());
-                       target_routed = true;           
+                       target_routed = true;
                end
 
                function env.core_post_stanza(...)
@@ -167,13 +167,13 @@ function core_process_stanza(core_process_stanza, u)
        local function test_iq_to_local_bare()
                local env = testlib_new_env();
                local msg = stanza.stanza("iq", { to = "user@localhost", from = "user@localhost", type = "get", id = "id" }):tag("ping", { xmlns = "urn:xmpp:ping:0" });
-               
+
                local target_handled;
-               
+
                function env.core_post_stanza(p_origin, p_stanza)
                        assert_equal(p_origin, local_user_session, "origin of handled stanza is not correct");
                        assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print());
-                       target_handled = true;          
+                       target_handled = true;
                end
 
                env.hosts = hosts;
@@ -209,11 +209,11 @@ function core_route_stanza(core_route_stanza)
                local msg2 = stanza.stanza("iq", { to = "user@localhost/foo", from = "user@localhost", type = "error" }):tag("ping", { xmlns = "urn:xmpp:ping:0" });
                --package.loaded["core.usermanager"] = { user_exists = function (user, host) print("RAR!") return true or user == "user" and host == "localhost" and true; end };
                local target_handled, target_replied;
-               
+
                function env.core_post_stanza(p_origin, p_stanza)
                        target_handled = true;
                end
-               
+
                function local_user_session.send(data)
                        --print("Replying with: ", tostring(data));
                        --print(debug.traceback())