aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2008-11-15 19:12:23 +0000
committerMatthew Wild <mwild1@gmail.com>2008-11-15 19:12:23 +0000
commitb1bc21f5f08013fe2aaa4c5a7323c384280d47d1 (patch)
treeda0f9f661adae90ca187d4add2b11a6bbd9b06d0
parent94373484f76e1a369641aa114e8ca00b1b868769 (diff)
downloadprosody-b1bc21f5f08013fe2aaa4c5a7323c384280d47d1.tar.gz
prosody-b1bc21f5f08013fe2aaa4c5a7323c384280d47d1.zip
Add tests for core.stanza_router
-rw-r--r--tests/test_core_stanza_router.lua134
1 files changed, 134 insertions, 0 deletions
diff --git a/tests/test_core_stanza_router.lua b/tests/test_core_stanza_router.lua
new file mode 100644
index 00000000..49c1f90f
--- /dev/null
+++ b/tests/test_core_stanza_router.lua
@@ -0,0 +1,134 @@
+
+function core_process_stanza(core_process_stanza)
+ local s2sout_session = { to_host = "remotehost", from_host = "localhost", type = "s2sout" }
+ local local_host_session = { host = "localhost", type = "local" }
+ local local_user_session = { username = "user", host = "localhost", resource = "resource", full_jid = "user@localhost/resource", type = "c2s" }
+ local hosts = {
+ ["localhost"] = local_host_session;
+ }
+
+ -- Test message routing
+ 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_route_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;
+ setfenv(core_process_stanza, env);
+ assert_equal(core_process_stanza(local_user_session, msg), nil, "core_process_stanza returned incorrect value");
+ assert_equal(target_routed, true, "stanza was not routed successfully");
+ end
+
+ 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_route_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;
+ setfenv(core_process_stanza, env);
+ assert_equal(core_process_stanza(local_user_session, msg), nil, "core_process_stanza returned incorrect value");
+ assert_equal(target_routed, true, "stanza was not routed successfully");
+ end
+
+ 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_route_stanza(p_origin, p_stanza)
+ end
+
+ function env.core_handle_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;
+ 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");
+ assert_equal(target_handled, true, "stanza was not handled successfully");
+ end
+
+ 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;
+ 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");
+ assert_equal(target_routed, true, "stanza was not routed successfully");
+ end
+
+ 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;
+ 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");
+ assert_equal(target_routed, true, "stanza was not routed successfully");
+ end
+
+ --IQ tests
+
+
+ local function test_iq_to_remote_server()
+ local env = testlib_new_env();
+ local msg = stanza.stanza("iq", { 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;
+ end
+
+ function env.core_handle_stanza(p_origin, p_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");
+ assert_equal(target_routed, true, "stanza was not routed successfully");
+ end
+
+ runtest(test_message_full_jid, "Messages with full JID destinations get routed");
+ runtest(test_message_bare_jid, "Messages with bare JID destinations get routed");
+ runtest(test_message_no_to, "Messages with no destination are handled by the server");
+ runtest(test_message_to_remote_bare, "Messages to a remote user are routed by the server");
+ runtest(test_message_to_remote_server, "Messages to a remote server's JID are routed");
+
+ runtest(test_iq_to_remote_server, "iq to a remote server's JID are routed");
+
+end