Annotate

tests/test_util_http.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 7514:ea58c0fe1cd7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4339
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 -- Prosody IM
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 -- Copyright (C) 2008-2010 Matthew Wild
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 -- Copyright (C) 2008-2010 Waqas Hussain
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 5604
diff changeset
4 --
4339
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 -- COPYING file in the source package for more information.
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 --
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 function urlencode(urlencode)
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 assert_equal(urlencode("helloworld123"), "helloworld123", "Normal characters not escaped");
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 assert_equal(urlencode("hello world"), "hello%20world", "Spaces escaped");
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 assert_equal(urlencode("This & that = something"), "This%20%26%20that%20%3d%20something", "Important URL chars escaped");
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 end
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 function urldecode(urldecode)
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 assert_equal("helloworld123", urldecode("helloworld123"), "Normal characters not escaped");
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 assert_equal("hello world", urldecode("hello%20world"), "Spaces escaped");
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 assert_equal("This & that = something", urldecode("This%20%26%20that%20%3d%20something"), "Important URL chars escaped");
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 assert_equal("This & that = something", urldecode("This%20%26%20that%20%3D%20something"), "Important URL chars escaped");
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 end
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 function formencode(formencode)
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 assert_equal(formencode({ { name = "one", value = "1"}, { name = "two", value = "2" } }), "one=1&two=2", "Form encoded");
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 assert_equal(formencode({ { name = "one two", value = "1"}, { name = "two one&", value = "2" } }), "one+two=1&two+one%26=2", "Form encoded");
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 end
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 function formdecode(formdecode)
7514
ea58c0fe1cd7 test_util_http: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 5776
diff changeset
28 do
ea58c0fe1cd7 test_util_http: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 5776
diff changeset
29 local t = formdecode("one=1&two=2");
ea58c0fe1cd7 test_util_http: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 5776
diff changeset
30 assert_table(t[1]);
ea58c0fe1cd7 test_util_http: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 5776
diff changeset
31 assert_equal(t[1].name, "one"); assert_equal(t[1].value, "1");
ea58c0fe1cd7 test_util_http: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 5776
diff changeset
32 assert_table(t[2]);
ea58c0fe1cd7 test_util_http: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 5776
diff changeset
33 assert_equal(t[2].name, "two"); assert_equal(t[2].value, "2");
ea58c0fe1cd7 test_util_http: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 5776
diff changeset
34 end
4339
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35
7514
ea58c0fe1cd7 test_util_http: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 5776
diff changeset
36 do
ea58c0fe1cd7 test_util_http: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 5776
diff changeset
37 local t = formdecode("one+two=1&two+one%26=2");
ea58c0fe1cd7 test_util_http: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 5776
diff changeset
38 assert_equal(t[1].name, "one two"); assert_equal(t[1].value, "1");
ea58c0fe1cd7 test_util_http: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 5776
diff changeset
39 assert_equal(t[2].name, "two one&"); assert_equal(t[2].value, "2");
ea58c0fe1cd7 test_util_http: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 5776
diff changeset
40 end
4339
63304d323983 tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 end