Software /
code /
prosody
Comparison
tests/test_core_stanza_router.lua @ 858:dddc63818c3d
tests: Add test for iq error replies
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 03 Mar 2009 17:07:35 +0000 |
parent | 788:b85b1dee4f4b |
child | 896:2c0b9e3c11c3 |
comparison
equal
deleted
inserted
replaced
857:49298263f241 | 858:dddc63818c3d |
---|---|
184 runtest(test_message_to_remote_server, "Messages to a remote server's JID are routed"); | 184 runtest(test_message_to_remote_server, "Messages to a remote server's JID are routed"); |
185 | 185 |
186 runtest(test_iq_to_remote_server, "iq to a remote server's JID are routed"); | 186 runtest(test_iq_to_remote_server, "iq to a remote server's JID are routed"); |
187 runtest(test_iq_to_local_bare, "iq from a local user to a local user's bare JID are handled"); | 187 runtest(test_iq_to_local_bare, "iq from a local user to a local user's bare JID are handled"); |
188 runtest(test_iq_error_to_local_user, "iq type=error to a local user's JID are routed"); | 188 runtest(test_iq_error_to_local_user, "iq type=error to a local user's JID are routed"); |
189 | |
190 end | 189 end |
190 | |
191 function core_route_stanza(core_route_stanza) | |
192 local s2sout_session = { to_host = "remotehost", from_host = "localhost", type = "s2sout" } | |
193 local s2sin_session = { from_host = "remotehost", to_host = "localhost", type = "s2sin", hosts = { ["remotehost"] = { authed = true } } } | |
194 local local_host_session = { host = "localhost", type = "local", s2sout = { ["remotehost"] = s2sout_session }, sessions = {} } | |
195 local local_user_session = { username = "user", host = "localhost", resource = "resource", full_jid = "user@localhost/resource", type = "c2s" } | |
196 local hosts = { | |
197 ["localhost"] = local_host_session; | |
198 } | |
199 | |
200 local function test_iq_result_to_offline_user() | |
201 local env = testlib_new_env(); | |
202 local msg = stanza.stanza("iq", { to = "user@localhost/foo", from = "user@localhost", type = "result" }):tag("ping", { xmlns = "urn:xmpp:ping:0" }); | |
203 local msg2 = stanza.stanza("iq", { to = "user@localhost/foo", from = "user@localhost", type = "error" }):tag("ping", { xmlns = "urn:xmpp:ping:0" }); | |
204 --package.loaded["core.usermanager"] = { user_exists = function (user, host) print("RAR!") return true or user == "user" and host == "localhost" and true; end }; | |
205 local target_handled, target_replied; | |
206 | |
207 function env.core_handle_stanza(p_origin, p_stanza) | |
208 target_handled = true; | |
209 end | |
210 | |
211 function local_user_session.send(data) | |
212 --print("Replying with: ", tostring(data)); | |
213 --print(debug.traceback()) | |
214 target_replied = true; | |
215 end | |
216 | |
217 env.hosts = hosts; | |
218 setfenv(core_route_stanza, env); | |
219 assert_equal(core_route_stanza(local_user_session, msg), nil, "core_route_stanza returned incorrect value"); | |
220 assert_equal(target_handled, nil, "stanza was handled and not dropped"); | |
221 assert_equal(target_replied, nil, "stanza was replied to and not dropped"); | |
222 package.loaded["core.usermanager"] = nil; | |
223 end | |
224 | |
225 runtest(test_iq_result_to_offline_user, "iq type=result|error to an offline user are not replied to"); | |
226 end |