Diff

spec/util_stanza_spec.lua @ 9307:feaef6215bb8

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.
author Matthew Wild <mwild1@gmail.com>
date Thu, 13 Sep 2018 16:35:48 +0100
parent 9302:57f8e41255fb
child 9308:21c2f3331c59
line wrap: on
line diff
--- a/spec/util_stanza_spec.lua	Thu Sep 13 17:28:50 2018 +0200
+++ b/spec/util_stanza_spec.lua	Thu Sep 13 16:35:48 2018 +0100
@@ -84,9 +84,20 @@
 	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);