aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-12-31 14:00:28 +0100
committerKim Alvefur <zash@zash.se>2021-12-31 14:00:28 +0100
commit893de236f687dae595e91382f019fa9a759da3a7 (patch)
treee07bb4de209b3f690f383f669a5d792aff4c65ae /spec
parent72be6f822941c431c51343cf00c4280ec132e00c (diff)
downloadprosody-893de236f687dae595e91382f019fa9a759da3a7.tar.gz
prosody-893de236f687dae595e91382f019fa9a759da3a7.zip
util.stanza: Increase test coverage to cover validation errors
Diffstat (limited to 'spec')
-rw-r--r--spec/util_stanza_spec.lua25
1 files changed, 25 insertions, 0 deletions
diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua
index 5306c05b..3afd67a2 100644
--- a/spec/util_stanza_spec.lua
+++ b/spec/util_stanza_spec.lua
@@ -85,6 +85,31 @@ describe("util.stanza", function()
assert.same(st.stanza("foo"):text(nil), s_control);
assert.same(st.stanza("foo"):text(""), s_control);
end);
+ it("validates names", function ()
+ assert.has_error_match(function ()
+ st.stanza("invalid\0name");
+ end, "invalid tag name:")
+ assert.has_error_match(function ()
+ st.stanza("name", { ["foo\1\2\3bar"] = "baz" });
+ end, "invalid attribute name: contains control characters")
+ assert.has_error_match(function ()
+ st.stanza("name", { ["foo"] = "baz\1\2\3\255moo" });
+ end, "invalid attribute value: contains control characters")
+ end)
+ it("validates types", function ()
+ assert.has_error_match(function ()
+ st.stanza(1);
+ end, "invalid tag name: expected string, got number")
+ assert.has_error_match(function ()
+ st.stanza("name", "string");
+ end, "invalid attributes: expected table, got string")
+ assert.has_error_match(function ()
+ st.stanza("name",{1});
+ end, "invalid attribute name: expected string, got number")
+ assert.has_error_match(function ()
+ st.stanza("name",{foo=1});
+ end, "invalid attribute value: expected string, got number")
+ end)
end);
describe("#message()", function()