aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2018-09-13 16:35:48 +0100
committerMatthew Wild <mwild1@gmail.com>2018-09-13 16:35:48 +0100
commit27d8902b8e38dd459f0b69dc9f17ebf6ad3e2059 (patch)
treeb0c749993e031bfa71f9cb2b0b672b83c20bd985 /spec
parentc3ba0cd3c5865294540fb559400941fa9c729eaa (diff)
downloadprosody-27d8902b8e38dd459f0b69dc9f17ebf6ad3e2059.tar.gz
prosody-27d8902b8e38dd459f0b69dc9f17ebf6ad3e2059.zip
util.stanza: Don't automatically generate ids for iq stanzas
Users of this API should provide their own id attribute that meets their uniqueness requirements. The current implementation leaks information (i.e. how many iq stanzas have been sent by the server to other JIDs). Providing any strong guarantees of randomness here would need to pull in additional dependencies that we don't want in this simple library.
Diffstat (limited to 'spec')
-rw-r--r--spec/util_stanza_spec.lua17
1 files changed, 14 insertions, 3 deletions
diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua
index 4263923d..dcbd6cf8 100644
--- a/spec/util_stanza_spec.lua
+++ b/spec/util_stanza_spec.lua
@@ -84,9 +84,20 @@ describe("util.stanza", function()
end);
describe("#iq()", function()
- it("should work", function()
- local i = st.iq();
- assert.are.equal(i.name, "iq");
+ it("should create an iq stanza", function()
+ local i = st.iq({ id = "foo" });
+ assert.are.equal("iq", i.name);
+ assert.are.equal("foo", i.attr.id);
+ end);
+
+ it("should reject stanzas with no id", function ()
+ assert.has.error_match(function ()
+ local i = st.iq();
+ end, "id attribute");
+
+ assert.has.error_match(function ()
+ local i = st.iq({ foo = "bar" });
+ end, "id attribute");
end);
end);