aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2020-09-26 18:09:10 +0200
committerKim Alvefur <zash@zash.se>2020-09-26 18:09:10 +0200
commita2ec5e4e52adc58ef83d5e20f268f2a1005b13ac (patch)
treedee52ffe239a67fec2c369374320904f2cbfbf1f
parent40800ea93bb1dca78c3548de58a09f424f5eef30 (diff)
downloadprosody-a2ec5e4e52adc58ef83d5e20f268f2a1005b13ac.tar.gz
prosody-a2ec5e4e52adc58ef83d5e20f268f2a1005b13ac.zip
util.stanza: Support Application-Specific Conditions in util.error
-rw-r--r--spec/util_stanza_spec.lua14
-rw-r--r--util/stanza.lua5
2 files changed, 18 insertions, 1 deletions
diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua
index cc32bba9..ba90eb84 100644
--- a/spec/util_stanza_spec.lua
+++ b/spec/util_stanza_spec.lua
@@ -252,8 +252,20 @@ describe("util.stanza", function()
local gonner = st.error_reply(s, gone);
assert.are.equal("gone", gonner.tags[1].tags[1].name);
assert.are.equal("file:///dev/null", gonner.tags[1].tags[1][1]);
- end);
+ local e = errors.new({ condition = "internal-server-error", text = "Namespaced thing happened",
+ extra = {namespace="xmpp:example.test", condition="this-happened"} })
+ local r = st.error_reply(s, e);
+ assert.are.equal("xmpp:example.test", r.tags[1].tags[3].attr.xmlns);
+ assert.are.equal("this-happened", r.tags[1].tags[3].name);
+
+ local e2 = errors.new({ condition = "internal-server-error", text = "Namespaced thing happened",
+ extra = {tag=st.stanza("that-happened", { xmlns = "xmpp:example.test", ["another-attribute"] = "here" })} })
+ local r2 = st.error_reply(s, e2);
+ assert.are.equal("xmpp:example.test", r2.tags[1].tags[3].attr.xmlns);
+ assert.are.equal("that-happened", r2.tags[1].tags[3].name);
+ assert.are.equal("here", r2.tags[1].tags[3].attr["another-attribute"]);
+ end);
end);
describe("should reject #invalid", function ()
diff --git a/util/stanza.lua b/util/stanza.lua
index 3d0d5002..9bcf3747 100644
--- a/util/stanza.lua
+++ b/util/stanza.lua
@@ -473,6 +473,11 @@ local function error_reply(orig, error_type, condition, error_message, error_by)
end
t:up();
if error_message then t:text_tag("text", error_message, xmpp_stanzas_attr); end
+ if extra and is_stanza(extra.tag) then
+ t:add_child(extra.tag);
+ elseif extra and extra.namespace and extra.condition then
+ t:tag(extra.condition, { xmlns = extra.namespace }):up();
+ end
return t; -- stanza ready for adding app-specific errors
end