From 6d7cd57d44fced8c151a1ae010b5e24d9da02a89 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 16 Mar 2018 14:51:24 +0000 Subject: util.stanza: Add stricter validation for data passed to stanza builder API --- spec/util_stanza_spec.lua | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'spec/util_stanza_spec.lua') diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua index 7543ffe7..ea3ef4c9 100644 --- a/spec/util_stanza_spec.lua +++ b/spec/util_stanza_spec.lua @@ -164,4 +164,38 @@ describe("util.stanza", function() assert.are.equal(r.tags[1].tags[1].name, "service-unavailable"); end); end); + + describe("#invalid", function () + it("name should be rejected", function () + assert.has_error(function () + st.stanza(1234); + end); + assert.has_error(function () + st.stanza({}); + end); + assert.has_error(function () + st.stanza(); + end); + assert.has_error(function () + st.stanza(""); + end); + assert.has_error(function () + st.stanza(string.char(0xC0)); + end); + assert.has_error(function () + st.stanza(string.char(0xF4, 0x90, 0x80, 0x80)); + end); + assert.has_error(function () + st.stanza("<>"); + end); + assert.has_error(function () + st.stanza("&"); + end); + end); + it("UTF-8 should be rejected", function () + assert.has_error(function () + st.stanza("tag"):text("hello "..string.char(0xF4, 0x90, 0x80, 0x80).." world"); + end); + end); + end); end); -- cgit v1.2.3