Software /
code /
prosody
Annotate
tests/test_core_stanza_router.lua @ 1027:fe2e3d3dba6a
util.array: Add array.collect() to collect results from iterators into an array, and use module() to correctly set the module name
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 22 Apr 2009 17:46:17 +0100 |
parent | 896:2c0b9e3c11c3 |
child | 1523:841d61be198f |
rev | line source |
---|---|
896 | 1 -- Prosody IM v0.4 |
760
90ce865eebd8
Update copyright notices for 2009
Matthew Wild <mwild1@gmail.com>
parents:
759
diff
changeset
|
2 -- Copyright (C) 2008-2009 Matthew Wild |
90ce865eebd8
Update copyright notices for 2009
Matthew Wild <mwild1@gmail.com>
parents:
759
diff
changeset
|
3 -- Copyright (C) 2008-2009 Waqas Hussain |
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
302
diff
changeset
|
4 -- |
758 | 5 -- This project is MIT/X11 licensed. Please see the |
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 |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
302
diff
changeset
|
9 |
273
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 function core_process_stanza(core_process_stanza) |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 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
|
13 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
|
14 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
|
15 local local_user_session = { username = "user", host = "localhost", resource = "resource", full_jid = "user@localhost/resource", type = "c2s" } |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 local hosts = { |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 ["localhost"] = local_host_session; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 } |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 -- Test message routing |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 local function test_message_full_jid() |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 local env = testlib_new_env(); |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 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
|
24 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 local target_routed; |
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 function env.core_route_stanza(p_origin, p_stanza) |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 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
|
29 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
|
30 target_routed = true; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 end |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 env.hosts = hosts; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 setfenv(core_process_stanza, env); |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 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
|
35 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
|
36 end |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 local function test_message_bare_jid() |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 local env = testlib_new_env(); |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 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
|
41 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 local target_routed; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 function env.core_route_stanza(p_origin, p_stanza) |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 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
|
46 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
|
47 target_routed = true; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 end |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 env.hosts = hosts; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 setfenv(core_process_stanza, env); |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 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
|
52 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
|
53 end |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 local function test_message_no_to() |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 local env = testlib_new_env(); |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 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
|
58 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 local target_handled; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 function env.core_route_stanza(p_origin, p_stanza) |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 end |
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 function env.core_handle_stanza(p_origin, p_stanza) |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 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
|
66 assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print()); |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 target_handled = true; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 end |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 env.hosts = hosts; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 setfenv(core_process_stanza, env); |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 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
|
72 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
|
73 end |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 local function test_message_to_remote_bare() |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 local env = testlib_new_env(); |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 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
|
78 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 local target_routed; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 function env.core_route_stanza(p_origin, p_stanza) |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 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
|
83 assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print()); |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 target_routed = true; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 end |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 env.hosts = hosts; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 setfenv(core_process_stanza, env); |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 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
|
90 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
|
91 end |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 local function test_message_to_remote_server() |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 local env = testlib_new_env(); |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 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
|
96 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 local target_routed; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
98 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 function env.core_route_stanza(p_origin, p_stanza) |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 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
|
101 assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print()); |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 target_routed = true; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 end |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 env.hosts = hosts; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 setfenv(core_process_stanza, env); |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 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
|
108 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
|
109 end |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 --IQ tests |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 local function test_iq_to_remote_server() |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 local env = testlib_new_env(); |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 local msg = stanza.stanza("iq", { to = "remotehost", type = "chat" }):tag("body"):text("Hello world"); |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 local target_routed; |
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 function env.core_route_stanza(p_origin, p_stanza) |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 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
|
122 assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print()); |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 target_routed = true; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 end |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 function env.core_handle_stanza(p_origin, p_stanza) |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 end |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 env.hosts = hosts; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 setfenv(core_process_stanza, env); |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 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
|
133 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
|
134 end |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 |
302
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
136 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
|
137 local env = testlib_new_env(); |
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
138 local msg = stanza.stanza("iq", { to = "user@localhost/resource", from = "user@remotehost", type = "error" }):tag("error", { type = 'cancel' }):tag("item-not-found", { xmlns='urn:ietf:params:xml:ns:xmpp-stanzas' }); |
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
139 |
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
140 local target_routed; |
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
141 |
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
142 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
|
143 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
|
144 assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print()); |
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
145 target_routed = true; |
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
146 end |
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
147 |
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
148 function env.core_handle_stanza(p_origin, p_stanza) |
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
149 |
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
150 end |
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
151 |
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
152 env.hosts = hosts; |
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
153 setfenv(core_process_stanza, env); |
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
154 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
|
155 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
|
156 end |
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
157 |
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
|
158 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
|
159 local env = testlib_new_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
|
160 local msg = stanza.stanza("iq", { to = "user@localhost", from = "user@localhost", type = "get" }):tag("ping", { xmlns = "urn:xmpp:ping:0" }); |
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
|
161 |
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
|
162 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
|
163 |
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
|
164 function env.core_handle_stanza(p_origin, p_stanza) |
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
|
165 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
|
166 assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print()); |
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 target_handled = true; |
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 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
|
169 |
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 function env.core_route_stanza(p_origin, p_stanza) |
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 |
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 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
|
173 |
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 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
|
175 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
|
176 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
|
177 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
|
178 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
|
179 |
273
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
180 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
|
181 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
|
182 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
|
183 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
|
184 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
|
185 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
186 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
|
187 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
|
188 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
|
189 end |
273
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
190 |
858
dddc63818c3d
tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents:
788
diff
changeset
|
191 function core_route_stanza(core_route_stanza) |
dddc63818c3d
tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents:
788
diff
changeset
|
192 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
|
193 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
|
194 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
|
195 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
|
196 local hosts = { |
dddc63818c3d
tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents:
788
diff
changeset
|
197 ["localhost"] = local_host_session; |
dddc63818c3d
tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents:
788
diff
changeset
|
198 } |
dddc63818c3d
tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents:
788
diff
changeset
|
199 |
dddc63818c3d
tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents:
788
diff
changeset
|
200 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
|
201 local env = testlib_new_env(); |
dddc63818c3d
tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents:
788
diff
changeset
|
202 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
|
203 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
|
204 --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
|
205 local target_handled, target_replied; |
dddc63818c3d
tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents:
788
diff
changeset
|
206 |
dddc63818c3d
tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents:
788
diff
changeset
|
207 function env.core_handle_stanza(p_origin, p_stanza) |
dddc63818c3d
tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents:
788
diff
changeset
|
208 target_handled = true; |
dddc63818c3d
tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents:
788
diff
changeset
|
209 end |
dddc63818c3d
tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents:
788
diff
changeset
|
210 |
dddc63818c3d
tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents:
788
diff
changeset
|
211 function local_user_session.send(data) |
dddc63818c3d
tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents:
788
diff
changeset
|
212 --print("Replying with: ", tostring(data)); |
dddc63818c3d
tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents:
788
diff
changeset
|
213 --print(debug.traceback()) |
dddc63818c3d
tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents:
788
diff
changeset
|
214 target_replied = 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 env.hosts = hosts; |
dddc63818c3d
tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents:
788
diff
changeset
|
218 setfenv(core_route_stanza, env); |
dddc63818c3d
tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents:
788
diff
changeset
|
219 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
|
220 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
|
221 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
|
222 package.loaded["core.usermanager"] = nil; |
dddc63818c3d
tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents:
788
diff
changeset
|
223 end |
dddc63818c3d
tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents:
788
diff
changeset
|
224 |
dddc63818c3d
tests: Add test for iq error replies
Matthew Wild <mwild1@gmail.com>
parents:
788
diff
changeset
|
225 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
|
226 end |