# HG changeset patch # User Matthew Wild # Date 1572187557 0 # Node ID 0a2d7efca039c29a0fa26f5973814c736e5bd972 # Parent cb9755d7a36eeadcdd6b49f4e15351a3ab6777c9 util.pubsub, pubsub.lib and tests: Add text to precondition-not-met error (fixes #1455) diff -r cb9755d7a36e -r 0a2d7efca039 plugins/mod_pubsub/pubsub.lib.lua --- a/plugins/mod_pubsub/pubsub.lib.lua Sun Oct 20 23:47:48 2019 +0200 +++ b/plugins/mod_pubsub/pubsub.lib.lua Sun Oct 27 14:45:57 2019 +0000 @@ -7,6 +7,7 @@ local it = require "util.iterators"; local uuid_generate = require "util.uuid".generate; local dataform = require"util.dataforms".new; +local errors = require "util.error"; local xmlns_pubsub = "http://jabber.org/protocol/pubsub"; local xmlns_pubsub_errors = "http://jabber.org/protocol/pubsub#errors"; @@ -34,6 +35,9 @@ }; local function pubsub_error_reply(stanza, error) local e = pubsub_errors[error]; + if not e and errors.is_err(error) then + e = { error.type, error.condition, error.text, error.pubsub_condition }; + end local reply = st.error_reply(stanza, t_unpack(e, 1, 3)); if e[4] then reply:tag(e[4], { xmlns = xmlns_pubsub_errors }):up(); diff -r cb9755d7a36e -r 0a2d7efca039 spec/scansion/pubsub_preconditions.scs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spec/scansion/pubsub_preconditions.scs Sun Oct 27 14:45:57 2019 +0000 @@ -0,0 +1,234 @@ +# Pubsub preconditions are enforced + +[Client] Romeo + password: password + jid: jqpcrbq2@localhost + +----- + +Romeo connects + +Romeo sends: + + + + + + + + + + +Romeo receives: + + + + + + + + +Romeo sends: + + + + + + +Romeo receives: + + + + + + http://jabber.org/protocol/pubsub#node_config + + + + + + + 1 + + + 1 + + + + + + + + presence + + + + + + publishers + + + 1 + + + 1 + + + + + headline + + + 1 + + + 1 + + + + + + +Romeo sends: + + + + + + http://jabber.org/protocol/pubsub#node_config + + + Nice tunes + + + + + + 1 + + + 1 + + + + + + + + presence + + + + + + publishers + + + 1 + + + 1 + + + + + headline + + + 1 + + + 1 + + + + + + +Romeo receives: + + +Romeo sends: + + + + +Romeo receives: + + + + + + +Romeo sends: + + + + + + + + + + + http://jabber.org/protocol/pubsub#publish-options + + + whitelist + + + + + + +Romeo receives: + + + + Field does not match: access_model + + + + +Romeo disconnects + diff -r cb9755d7a36e -r 0a2d7efca039 spec/util_pubsub_spec.lua --- a/spec/util_pubsub_spec.lua Sun Oct 20 23:47:48 2019 +0200 +++ b/spec/util_pubsub_spec.lua Sun Oct 27 14:45:57 2019 +0000 @@ -107,7 +107,7 @@ it("fails to publish to a node with differing config", function () local ok, err = service:publish("node", true, "1", "item 2", { myoption = false }); assert.falsy(ok); - assert.equals("precondition-not-met", err); + assert.equals("precondition-not-met", err.pubsub_condition); end); it("allows to publish to a node with differing config when only defaults are suggested", function () diff -r cb9755d7a36e -r 0a2d7efca039 util/pubsub.lua --- a/util/pubsub.lua Sun Oct 20 23:47:48 2019 +0200 +++ b/util/pubsub.lua Sun Oct 27 14:45:57 2019 +0000 @@ -1,5 +1,6 @@ local events = require "util.events"; local cache = require "util.cache"; +local errors = require "util.error"; local service_mt = {}; @@ -510,7 +511,7 @@ end for config_field, value in pairs(required_config) do if node_config[config_field] ~= value then - return false; + return false, config_field; end end return true; @@ -546,8 +547,13 @@ node_obj = self.nodes[node]; elseif requested_config and not requested_config._defaults_only then -- Check that node has the requested config before we publish - if not check_preconditions(node_obj.config, requested_config) then - return false, "precondition-not-met"; + local ok, field = check_preconditions(node_obj.config, requested_config); + if not ok then + local err = errors.new({ + type = "cancel", condition = "conflict", text = "Field does not match: "..field; + }); + err.pubsub_condition = "precondition-not-met"; + return false, err; end end if not self.config.itemcheck(item) then