Annotate

tests/test_core_stanza_router.lua @ 3682:d12141cbbaa0

net.server_select: Make changes required for sub-second timer precision.
author Waqas Hussain <waqas20@gmail.com>
date Thu, 02 Dec 2010 22:40:42 +0500
parent 3540:bc139431830b
child 5776:bd0ff8ae98a8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1523
841d61be198f Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
1 -- Prosody IM
2923
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 1973
diff changeset
2 -- Copyright (C) 2008-2010 Matthew Wild
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 1973
diff changeset
3 -- Copyright (C) 2008-2010 Waqas Hussain
519
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 302
diff changeset
4 --
758
b1885732e979 GPL->MIT!
Matthew Wild <mwild1@gmail.com>
parents: 615
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
b1885732e979 GPL->MIT!
Matthew Wild <mwild1@gmail.com>
parents: 615
diff changeset
6 -- COPYING file in the source package for more information.
519
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 302
diff changeset
7 --
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 302
diff changeset
8
1973
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
9 _G.prosody = { full_sessions = {}; bare_sessions = {}; hosts = {}; };
273
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10
1973
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
11 function core_process_stanza(core_process_stanza, u)
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
12 local stanza = require "util.stanza";
273
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 local s2sout_session = { to_host = "remotehost", from_host = "localhost", type = "s2sout" }
786
f2dc6118b3f4 Correct tests for stanza routing IQs to bare JIDs
Matthew Wild <mwild1@gmail.com>
parents: 760
diff changeset
14 local s2sin_session = { from_host = "remotehost", to_host = "localhost", type = "s2sin", hosts = { ["remotehost"] = { authed = true } } }
f2dc6118b3f4 Correct tests for stanza routing IQs to bare JIDs
Matthew Wild <mwild1@gmail.com>
parents: 760
diff changeset
15 local local_host_session = { host = "localhost", type = "local", s2sout = { ["remotehost"] = s2sout_session } }
273
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 local local_user_session = { username = "user", host = "localhost", resource = "resource", full_jid = "user@localhost/resource", type = "c2s" }
1973
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
17
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
18 _G.prosody.hosts["localhost"] = local_host_session;
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
19 _G.prosody.full_sessions["user@localhost/resource"] = local_user_session;
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
20 _G.prosody.bare_sessions["user@localhost"] = { sessions = { resource = local_user_session } };
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
21
273
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 -- Test message routing
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 local function test_message_full_jid()
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 local env = testlib_new_env();
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 local msg = stanza.stanza("message", { to = "user@localhost/resource", type = "chat" }):tag("body"):text("Hello world");
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 local target_routed;
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28
1973
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
29 function env.core_post_stanza(p_origin, p_stanza)
273
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 assert_equal(p_origin, local_user_session, "origin of routed stanza is not correct");
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 assert_equal(p_stanza, msg, "routed stanza is not correct one: "..p_stanza:pretty_print());
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 target_routed = true;
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 end
1973
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
34
273
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 env.hosts = hosts;
1973
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
36 env.prosody = { hosts = hosts };
273
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 setfenv(core_process_stanza, env);
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 assert_equal(core_process_stanza(local_user_session, msg), nil, "core_process_stanza returned incorrect value");
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 assert_equal(target_routed, true, "stanza was not routed successfully");
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 end
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 local function test_message_bare_jid()
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 local env = testlib_new_env();
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 local msg = stanza.stanza("message", { to = "user@localhost", type = "chat" }):tag("body"):text("Hello world");
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 local target_routed;
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47
1973
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
48 function env.core_post_stanza(p_origin, p_stanza)
273
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 assert_equal(p_origin, local_user_session, "origin of routed stanza is not correct");
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 assert_equal(p_stanza, msg, "routed stanza is not correct one: "..p_stanza:pretty_print());
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 target_routed = true;
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 end
1973
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
53
273
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 env.hosts = hosts;
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 setfenv(core_process_stanza, env);
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56 assert_equal(core_process_stanza(local_user_session, msg), nil, "core_process_stanza returned incorrect value");
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57 assert_equal(target_routed, true, "stanza was not routed successfully");
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58 end
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
59
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60 local function test_message_no_to()
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61 local env = testlib_new_env();
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62 local msg = stanza.stanza("message", { type = "chat" }):tag("body"):text("Hello world");
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64 local target_handled;
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
65
1973
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
66 function env.core_post_stanza(p_origin, p_stanza)
273
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
67 assert_equal(p_origin, local_user_session, "origin of handled stanza is not correct");
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
68 assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print());
3540
bc139431830b Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents: 2923
diff changeset
69 target_handled = true;
273
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
70 end
1973
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
71
273
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
72 env.hosts = hosts;
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
73 setfenv(core_process_stanza, env);
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
74 assert_equal(core_process_stanza(local_user_session, msg), nil, "core_process_stanza returned incorrect value");
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
75 assert_equal(target_handled, true, "stanza was not handled successfully");
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
76 end
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
77
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
78 local function test_message_to_remote_bare()
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
79 local env = testlib_new_env();
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
80 local msg = stanza.stanza("message", { to = "user@remotehost", type = "chat" }):tag("body"):text("Hello world");
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
81
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
82 local target_routed;
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
83
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
84 function env.core_route_stanza(p_origin, p_stanza)
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
85 assert_equal(p_origin, local_user_session, "origin of handled stanza is not correct");
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
86 assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print());
3540
bc139431830b Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents: 2923
diff changeset
87 target_routed = true;
273
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
88 end
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
89
1973
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
90 function env.core_post_stanza(...) env.core_route_stanza(...); end
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
91
273
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
92 env.hosts = hosts;
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
93 setfenv(core_process_stanza, env);
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
94 assert_equal(core_process_stanza(local_user_session, msg), nil, "core_process_stanza returned incorrect value");
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
95 assert_equal(target_routed, true, "stanza was not routed successfully");
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
96 end
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
97
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
98 local function test_message_to_remote_server()
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
99 local env = testlib_new_env();
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
100 local msg = stanza.stanza("message", { to = "remotehost", type = "chat" }):tag("body"):text("Hello world");
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
101
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
102 local target_routed;
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
103
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
104 function env.core_route_stanza(p_origin, p_stanza)
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
105 assert_equal(p_origin, local_user_session, "origin of handled stanza is not correct");
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
106 assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print());
3540
bc139431830b Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents: 2923
diff changeset
107 target_routed = true;
273
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
108 end
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
109
1973
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
110 function env.core_post_stanza(...)
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
111 env.core_route_stanza(...);
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
112 end
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
113
273
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
114 env.hosts = hosts;
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
115 setfenv(core_process_stanza, env);
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
116 assert_equal(core_process_stanza(local_user_session, msg), nil, "core_process_stanza returned incorrect value");
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
117 assert_equal(target_routed, true, "stanza was not routed successfully");
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
118 end
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
119
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
120 --IQ tests
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
121
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
122
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
123 local function test_iq_to_remote_server()
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
124 local env = testlib_new_env();
1973
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
125 local msg = stanza.stanza("iq", { to = "remotehost", type = "get", id = "id" }):tag("body"):text("Hello world");
273
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
126
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
127 local target_routed;
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
128
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
129 function env.core_route_stanza(p_origin, p_stanza)
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
130 assert_equal(p_origin, local_user_session, "origin of handled stanza is not correct");
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
131 assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print());
3540
bc139431830b Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents: 2923
diff changeset
132 target_routed = true;
273
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
133 end
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
134
1973
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
135 function env.core_post_stanza(...)
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
136 env.core_route_stanza(...);
273
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
137 end
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
138
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
139 env.hosts = hosts;
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
140 setfenv(core_process_stanza, env);
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
141 assert_equal(core_process_stanza(local_user_session, msg), nil, "core_process_stanza returned incorrect value");
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
142 assert_equal(target_routed, true, "stanza was not routed successfully");
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
143 end
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
144
302
8aedb3766ec7 You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents: 273
diff changeset
145 local function test_iq_error_to_local_user()
8aedb3766ec7 You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents: 273
diff changeset
146 local env = testlib_new_env();
1973
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
147 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' });
302
8aedb3766ec7 You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents: 273
diff changeset
148
8aedb3766ec7 You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents: 273
diff changeset
149 local target_routed;
8aedb3766ec7 You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents: 273
diff changeset
150
8aedb3766ec7 You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents: 273
diff changeset
151 function env.core_route_stanza(p_origin, p_stanza)
8aedb3766ec7 You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents: 273
diff changeset
152 assert_equal(p_origin, s2sin_session, "origin of handled stanza is not correct");
8aedb3766ec7 You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents: 273
diff changeset
153 assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print());
3540
bc139431830b Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents: 2923
diff changeset
154 target_routed = true;
302
8aedb3766ec7 You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents: 273
diff changeset
155 end
8aedb3766ec7 You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents: 273
diff changeset
156
1973
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
157 function env.core_post_stanza(...)
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
158 env.core_route_stanza(...);
302
8aedb3766ec7 You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents: 273
diff changeset
159 end
8aedb3766ec7 You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents: 273
diff changeset
160
8aedb3766ec7 You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents: 273
diff changeset
161 env.hosts = hosts;
8aedb3766ec7 You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents: 273
diff changeset
162 setfenv(core_process_stanza, env);
8aedb3766ec7 You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents: 273
diff changeset
163 assert_equal(core_process_stanza(s2sin_session, msg), nil, "core_process_stanza returned incorrect value");
8aedb3766ec7 You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents: 273
diff changeset
164 assert_equal(target_routed, true, "stanza was not routed successfully");
8aedb3766ec7 You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents: 273
diff changeset
165 end
8aedb3766ec7 You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents: 273
diff changeset
166
788
b85b1dee4f4b Add test to check for incorrect handling of iq from c2s to local bare JIDs
Matthew Wild <mwild1@gmail.com>
parents: 786
diff changeset
167 local function test_iq_to_local_bare()
b85b1dee4f4b Add test to check for incorrect handling of iq from c2s to local bare JIDs
Matthew Wild <mwild1@gmail.com>
parents: 786
diff changeset
168 local env = testlib_new_env();
1973
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
169 local msg = stanza.stanza("iq", { to = "user@localhost", from = "user@localhost", type = "get", id = "id" }):tag("ping", { xmlns = "urn:xmpp:ping:0" });
788
b85b1dee4f4b Add test to check for incorrect handling of iq from c2s to local bare JIDs
Matthew Wild <mwild1@gmail.com>
parents: 786
diff changeset
170
b85b1dee4f4b Add test to check for incorrect handling of iq from c2s to local bare JIDs
Matthew Wild <mwild1@gmail.com>
parents: 786
diff changeset
171 local target_handled;
b85b1dee4f4b Add test to check for incorrect handling of iq from c2s to local bare JIDs
Matthew Wild <mwild1@gmail.com>
parents: 786
diff changeset
172
1973
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
173 function env.core_post_stanza(p_origin, p_stanza)
788
b85b1dee4f4b Add test to check for incorrect handling of iq from c2s to local bare JIDs
Matthew Wild <mwild1@gmail.com>
parents: 786
diff changeset
174 assert_equal(p_origin, local_user_session, "origin of handled stanza is not correct");
b85b1dee4f4b Add test to check for incorrect handling of iq from c2s to local bare JIDs
Matthew Wild <mwild1@gmail.com>
parents: 786
diff changeset
175 assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print());
3540
bc139431830b Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents: 2923
diff changeset
176 target_handled = true;
788
b85b1dee4f4b Add test to check for incorrect handling of iq from c2s to local bare JIDs
Matthew Wild <mwild1@gmail.com>
parents: 786
diff changeset
177 end
b85b1dee4f4b Add test to check for incorrect handling of iq from c2s to local bare JIDs
Matthew Wild <mwild1@gmail.com>
parents: 786
diff changeset
178
b85b1dee4f4b Add test to check for incorrect handling of iq from c2s to local bare JIDs
Matthew Wild <mwild1@gmail.com>
parents: 786
diff changeset
179 env.hosts = hosts;
b85b1dee4f4b Add test to check for incorrect handling of iq from c2s to local bare JIDs
Matthew Wild <mwild1@gmail.com>
parents: 786
diff changeset
180 setfenv(core_process_stanza, env);
b85b1dee4f4b Add test to check for incorrect handling of iq from c2s to local bare JIDs
Matthew Wild <mwild1@gmail.com>
parents: 786
diff changeset
181 assert_equal(core_process_stanza(local_user_session, msg), nil, "core_process_stanza returned incorrect value");
b85b1dee4f4b Add test to check for incorrect handling of iq from c2s to local bare JIDs
Matthew Wild <mwild1@gmail.com>
parents: 786
diff changeset
182 assert_equal(target_handled, true, "stanza was not handled successfully");
b85b1dee4f4b Add test to check for incorrect handling of iq from c2s to local bare JIDs
Matthew Wild <mwild1@gmail.com>
parents: 786
diff changeset
183 end
b85b1dee4f4b Add test to check for incorrect handling of iq from c2s to local bare JIDs
Matthew Wild <mwild1@gmail.com>
parents: 786
diff changeset
184
273
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
185 runtest(test_message_full_jid, "Messages with full JID destinations get routed");
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
186 runtest(test_message_bare_jid, "Messages with bare JID destinations get routed");
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
187 runtest(test_message_no_to, "Messages with no destination are handled by the server");
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
188 runtest(test_message_to_remote_bare, "Messages to a remote user are routed by the server");
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
189 runtest(test_message_to_remote_server, "Messages to a remote server's JID are routed");
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
190
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
191 runtest(test_iq_to_remote_server, "iq to a remote server's JID are routed");
788
b85b1dee4f4b Add test to check for incorrect handling of iq from c2s to local bare JIDs
Matthew Wild <mwild1@gmail.com>
parents: 786
diff changeset
192 runtest(test_iq_to_local_bare, "iq from a local user to a local user's bare JID are handled");
302
8aedb3766ec7 You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents: 273
diff changeset
193 runtest(test_iq_error_to_local_user, "iq type=error to a local user's JID are routed");
858
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
194 end
273
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
195
858
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
196 function core_route_stanza(core_route_stanza)
1973
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
197 local stanza = require "util.stanza";
858
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
198 local s2sout_session = { to_host = "remotehost", from_host = "localhost", type = "s2sout" }
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
199 local s2sin_session = { from_host = "remotehost", to_host = "localhost", type = "s2sin", hosts = { ["remotehost"] = { authed = true } } }
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
200 local local_host_session = { host = "localhost", type = "local", s2sout = { ["remotehost"] = s2sout_session }, sessions = {} }
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
201 local local_user_session = { username = "user", host = "localhost", resource = "resource", full_jid = "user@localhost/resource", type = "c2s" }
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
202 local hosts = {
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
203 ["localhost"] = local_host_session;
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
204 }
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
205
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
206 local function test_iq_result_to_offline_user()
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
207 local env = testlib_new_env();
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
208 local msg = stanza.stanza("iq", { to = "user@localhost/foo", from = "user@localhost", type = "result" }):tag("ping", { xmlns = "urn:xmpp:ping:0" });
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
209 local msg2 = stanza.stanza("iq", { to = "user@localhost/foo", from = "user@localhost", type = "error" }):tag("ping", { xmlns = "urn:xmpp:ping:0" });
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
210 --package.loaded["core.usermanager"] = { user_exists = function (user, host) print("RAR!") return true or user == "user" and host == "localhost" and true; end };
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
211 local target_handled, target_replied;
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
212
1973
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
213 function env.core_post_stanza(p_origin, p_stanza)
858
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
214 target_handled = true;
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
215 end
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
216
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
217 function local_user_session.send(data)
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
218 --print("Replying with: ", tostring(data));
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
219 --print(debug.traceback())
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
220 target_replied = true;
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
221 end
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
222
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
223 env.hosts = hosts;
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
224 setfenv(core_route_stanza, env);
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
225 assert_equal(core_route_stanza(local_user_session, msg), nil, "core_route_stanza returned incorrect value");
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
226 assert_equal(target_handled, nil, "stanza was handled and not dropped");
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
227 assert_equal(target_replied, nil, "stanza was replied to and not dropped");
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
228 package.loaded["core.usermanager"] = nil;
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
229 end
dddc63818c3d tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents: 788
diff changeset
230
1973
7eea682989d3 tests: Fix stanza_router tests to work with the new routing code, finally all tests pass again \o/
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
231 --runtest(test_iq_result_to_offline_user, "iq type=result|error to an offline user are not replied to");
273
b4c6b124c06f Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
232 end