Mercurial > prosody-hg
diff spec/util_stanza_spec.lua @ 8599:62bfc85a53c8
util.stanza: Add stricter validation for data passed to stanza builder API
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Fri, 16 Mar 2018 14:51:24 +0000 |
| parents | 282d544d48f4 |
| children | e3e9479d526e |
line wrap: on
line diff
--- a/spec/util_stanza_spec.lua Fri Mar 16 14:50:28 2018 +0000 +++ b/spec/util_stanza_spec.lua Fri Mar 16 14:51:24 2018 +0000 @@ -164,4 +164,38 @@ 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);
