diff options
author | Kim Alvefur <zash@zash.se> | 2019-11-25 20:52:01 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2019-11-25 20:52:01 +0100 |
commit | 52b7181979bcee9000acf1c90e85934976e4da6a (patch) | |
tree | b016011e7c177c36a6f9c301630b7f3458b5f78c | |
parent | 11095184a53cc144e37560b7bbbf4de19ce669c7 (diff) | |
download | prosody-52b7181979bcee9000acf1c90e85934976e4da6a.tar.gz prosody-52b7181979bcee9000acf1c90e85934976e4da6a.zip |
util.stanza: Check that argument to error_reply is a stanza
-rw-r--r-- | spec/util_stanza_spec.lua | 6 | ||||
-rw-r--r-- | util/stanza.lua | 3 |
2 files changed, 9 insertions, 0 deletions
diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua index 3b9084fa..23cdbeb9 100644 --- a/spec/util_stanza_spec.lua +++ b/spec/util_stanza_spec.lua @@ -214,6 +214,12 @@ describe("util.stanza", function() assert.are.equal(#r.tags, 1); assert.are.equal(r.tags[1].tags[1].name, "service-unavailable"); end); + + it("should reject not-stanzas", function () + assert.has.error_match(function () + st.error_reply(not "a stanza", "modify", "bad-request"); + end, "expected stanza"); + end); end); describe("should reject #invalid", function () diff --git a/util/stanza.lua b/util/stanza.lua index 919d983c..24fd4fea 100644 --- a/util/stanza.lua +++ b/util/stanza.lua @@ -448,6 +448,9 @@ end local xmpp_stanzas_attr = { xmlns = xmlns_stanzas }; local function error_reply(orig, error_type, condition, error_message) + if not is_stanza(orig) then + error("bad argument to error_reply: expected stanza, got "..type(orig)); + end local t = reply(orig); t.attr.type = "error"; t:tag("error", {type = error_type}) --COMPAT: Some day xmlns:stanzas goes here |