aboutsummaryrefslogtreecommitdiffstats
path: root/spec/util_stanza_spec.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2018-03-16 14:51:24 +0000
committerMatthew Wild <mwild1@gmail.com>2018-03-16 14:51:24 +0000
commit6d7cd57d44fced8c151a1ae010b5e24d9da02a89 (patch)
tree9f92c5b23cf04c6b18282fd4ff47cb52e4fc9391 /spec/util_stanza_spec.lua
parentb7fd84b6e54273b18362b51c0b8388bea0ddbbbf (diff)
downloadprosody-6d7cd57d44fced8c151a1ae010b5e24d9da02a89.tar.gz
prosody-6d7cd57d44fced8c151a1ae010b5e24d9da02a89.zip
util.stanza: Add stricter validation for data passed to stanza builder API
Diffstat (limited to 'spec/util_stanza_spec.lua')
-rw-r--r--spec/util_stanza_spec.lua34
1 files changed, 34 insertions, 0 deletions
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);