Software /
code /
prosody
Annotate
tests/test_core_stanza_router.lua @ 577:22f54a04471f
Fix add_event_hook in module API
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 06 Dec 2008 19:51:10 +0000 |
parent | 519:cccd610a0ef9 |
child | 615:4ae3e81513f3 |
rev | line source |
---|---|
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
302
diff
changeset
|
1 -- Prosody IM v0.1 |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
302
diff
changeset
|
2 -- Copyright (C) 2008 Matthew Wild |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
302
diff
changeset
|
3 -- Copyright (C) 2008 Waqas Hussain |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
302
diff
changeset
|
4 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
302
diff
changeset
|
5 -- This program is free software; you can redistribute it and/or |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
302
diff
changeset
|
6 -- modify it under the terms of the GNU General Public License |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
302
diff
changeset
|
7 -- as published by the Free Software Foundation; either version 2 |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
302
diff
changeset
|
8 -- of the License, or (at your option) any later version. |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
302
diff
changeset
|
9 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
302
diff
changeset
|
10 -- This program is distributed in the hope that it will be useful, |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
302
diff
changeset
|
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
302
diff
changeset
|
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
302
diff
changeset
|
13 -- GNU General Public License for more details. |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
302
diff
changeset
|
14 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
302
diff
changeset
|
15 -- You should have received a copy of the GNU General Public License |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
302
diff
changeset
|
16 -- along with this program; if not, write to the Free Software |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
302
diff
changeset
|
17 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
302
diff
changeset
|
18 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
302
diff
changeset
|
19 |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
302
diff
changeset
|
20 |
273
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 function core_process_stanza(core_process_stanza) |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 local s2sout_session = { to_host = "remotehost", from_host = "localhost", type = "s2sout" } |
302
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
24 local s2sin_session = { from_host = "remotehost", to_host = "localhost", type = "s2sin" } |
273
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 local local_host_session = { host = "localhost", type = "local" } |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 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
|
27 local hosts = { |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 ["localhost"] = local_host_session; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 } |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 -- Test message routing |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 local function test_message_full_jid() |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 local env = testlib_new_env(); |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 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
|
35 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 local target_routed; |
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 function env.core_route_stanza(p_origin, p_stanza) |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 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
|
40 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
|
41 target_routed = true; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 end |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 env.hosts = hosts; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 setfenv(core_process_stanza, env); |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 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
|
46 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
|
47 end |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 local function test_message_bare_jid() |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 local env = testlib_new_env(); |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 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
|
52 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 local target_routed; |
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 function env.core_route_stanza(p_origin, p_stanza) |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 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
|
57 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
|
58 target_routed = true; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 end |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 env.hosts = hosts; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 setfenv(core_process_stanza, env); |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 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
|
63 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
|
64 end |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 local function test_message_no_to() |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 local env = testlib_new_env(); |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 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
|
69 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 local target_handled; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 function env.core_route_stanza(p_origin, p_stanza) |
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 function env.core_handle_stanza(p_origin, p_stanza) |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 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
|
77 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
|
78 target_handled = true; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 end |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 env.hosts = hosts; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 setfenv(core_process_stanza, env); |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 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
|
83 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
|
84 end |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 local function test_message_to_remote_bare() |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 local env = testlib_new_env(); |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 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
|
89 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 local target_routed; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 function env.core_route_stanza(p_origin, p_stanza) |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 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
|
94 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
|
95 target_routed = true; |
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 env.hosts = hosts; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 setfenv(core_process_stanza, env); |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 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
|
101 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
|
102 end |
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 local function test_message_to_remote_server() |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 local env = testlib_new_env(); |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 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
|
107 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 local target_routed; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 function env.core_route_stanza(p_origin, p_stanza) |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 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
|
112 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
|
113 target_routed = true; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 end |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 env.hosts = hosts; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 setfenv(core_process_stanza, env); |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 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
|
119 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
|
120 end |
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 --IQ tests |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 local function test_iq_to_remote_server() |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 local env = testlib_new_env(); |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 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
|
128 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 local target_routed; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 function env.core_route_stanza(p_origin, p_stanza) |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 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
|
133 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
|
134 target_routed = true; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 end |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 function env.core_handle_stanza(p_origin, p_stanza) |
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 end |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
140 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 env.hosts = hosts; |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
142 setfenv(core_process_stanza, env); |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
143 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
|
144 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
|
145 end |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
146 |
302
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
147 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
|
148 local env = testlib_new_env(); |
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
149 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
|
150 |
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
151 local target_routed; |
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
152 |
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
153 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
|
154 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
|
155 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
|
156 target_routed = true; |
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
157 end |
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
158 |
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
159 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
|
160 |
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
161 end |
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
162 |
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
163 env.hosts = hosts; |
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
164 setfenv(core_process_stanza, env); |
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
165 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
|
166 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
|
167 end |
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
168 |
273
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
169 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
|
170 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
|
171 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
|
172 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
|
173 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
|
174 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
175 runtest(test_iq_to_remote_server, "iq to a remote server's JID are routed"); |
302
8aedb3766ec7
You can never have too many tests
Matthew Wild <mwild1@gmail.com>
parents:
273
diff
changeset
|
176 runtest(test_iq_error_to_local_user, "iq type=error to a local user's JID are routed"); |
273
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
177 |
b4c6b124c06f
Add tests for core.stanza_router
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
178 end |