Software /
code /
prosody
Annotate
tests/test_util_multitable.lua @ 8791:8da11142fabf
muc: Allow clients to change multiple affiliations or roles at once (#345)
According to XEP-0045 sections 9.2, 9.5 and 9.8 affiliation lists and role
lists should allow mass-modification. Prosody however would just use the
first entry of the list and ignore the rest. This is fixed by introducing
a `for` loop to `set` stanzas of the respective `muc#admin` namespace.
In order for this loop to work, the error handling was changed a little.
Prosody no longer returns after the first error. Instead, an error reply
is sent for each malformed or otherwise wrong entry, but the loop keeps
going over the other entries. This may lead to multiple error messages
being sent for one client request. A notable exception from this is when
the XML Schema for `muc#admin` requests is violated. In that case the loop
is aborted with an error message to the client.
The change is a bit bigger than that in order to have the loop only for
`set` stanzas without changing the behaviour of the `get` stanzas. This is
now more in line with trunk, where there are separate methods for each
stanza type.
References: #345
author | Lennart Sauerbeck <devel@lennart.sauerbeck.org> |
---|---|
date | Sat, 18 Mar 2017 18:47:28 +0100 |
parent | 7511:ef6505962351 |
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:
1523
diff
changeset
|
2 -- Copyright (C) 2008-2010 Matthew Wild |
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
3 -- Copyright (C) 2008-2010 Waqas Hussain |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
3540
diff
changeset
|
4 -- |
797 | 5 -- This project is MIT/X11 licensed. Please see the |
6 -- COPYING file in the source package for more information. | |
7 -- | |
8 | |
9 | |
10 function new(new, multitable) | |
7472
8965ad0aed2c
test_util_multitable: make mt variable local [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents:
5776
diff
changeset
|
11 local mt = new(); |
797 | 12 assert_table(mt, "Multitable is a table"); |
13 assert_function(mt.add, "Multitable has method add"); | |
14 assert_function(mt.get, "Multitable has method get"); | |
15 assert_function(mt.remove, "Multitable has method remove"); | |
16 | |
17 get(mt.get, multitable); | |
18 end | |
19 | |
20 function get(get, multitable) | |
21 local function has_items(list, ...) | |
22 local should_have = {}; | |
23 if select('#', ...) > 0 then | |
24 assert_table(list, "has_items: list is table", 3); | |
25 else | |
26 assert_is_not(list and #list > 0, "No items, and no list"); | |
27 return true, "has-all"; | |
28 end | |
29 for n=1,select('#', ...) do should_have[select(n, ...)] = true; end | |
7511
ef6505962351
test_util_multitable: remove unused one-letter loop variable [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents:
7472
diff
changeset
|
30 for _, item in ipairs(list) do |
797 | 31 if not should_have[item] then return false, "too-many"; end |
32 should_have[item] = nil; | |
33 end | |
34 if next(should_have) then | |
3540
bc139431830b
Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents:
2923
diff
changeset
|
35 return false, "not-enough"; |
797 | 36 end |
37 return true, "has-all"; | |
38 end | |
39 local function assert_has_all(message, list, ...) | |
40 return assert_equal(select(2, has_items(list, ...)), "has-all", message or "List has all expected items, and no more", 2); | |
41 end | |
42 | |
7472
8965ad0aed2c
test_util_multitable: make mt variable local [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents:
5776
diff
changeset
|
43 local mt = multitable.new(); |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
3540
diff
changeset
|
44 |
797 | 45 local trigger1, trigger2, trigger3 = {}, {}, {}; |
46 local item1, item2, item3 = {}, {}, {}; | |
47 | |
48 assert_has_all("Has no items with trigger1", mt:get(trigger1)); | |
49 | |
50 | |
51 mt:add(1, 2, 3, item1); | |
52 | |
53 assert_has_all("Has item1 for 1, 2, 3", mt:get(1, 2, 3), item1); | |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
3540
diff
changeset
|
54 |
797 | 55 -- Doesn't support nil |
56 --[[ mt:add(nil, item1); | |
57 mt:add(nil, item2); | |
58 mt:add(nil, item3); | |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
3540
diff
changeset
|
59 |
797 | 60 assert_has_all("Has all items with (nil)", mt:get(nil), item1, item2, item3); |
61 ]] | |
62 end |