From 5d4504e51b8d1e77b20fffaf60cd7f2bdb80785a Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 3 Mar 2019 19:31:56 +0100 Subject: util.pubsub: Validate node configuration on node creation (fixes #1328) --- spec/util_pubsub_spec.lua | 41 +++++++++++++++++++++++++++++++++++++++++ util/pubsub.lua | 11 ++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/spec/util_pubsub_spec.lua b/spec/util_pubsub_spec.lua index 551aedd6..c982fb36 100644 --- a/spec/util_pubsub_spec.lua +++ b/spec/util_pubsub_spec.lua @@ -436,4 +436,45 @@ describe("util.pubsub", function () end); end); + describe("node config checking", function () + local service; + before_each(function () + service = pubsub.new({ + check_node_config = function (node, actor, config) -- luacheck: ignore 212 + return config["max_items"] <= 20; + end; + }); + end); + + it("defaults, then configure", function () + local ok, err = service:create("node", true); + assert.is_true(ok, err); + + local ok, err = service:set_node_config("node", true, { max_items = 10 }); + assert.is_true(ok, err); + + local ok, err = service:set_node_config("node", true, { max_items = 100 }); + assert.falsy(ok, err); + assert.equals(err, "not-acceptable"); + end); + + it("create with ok config, then configure", function () + local ok, err = service:create("node", true, { max_items = 10 }); + assert.is_true(ok, err); + + local ok, err = service:set_node_config("node", true, { max_items = 100 }); + assert.falsy(ok, err); + + local ok, err = service:set_node_config("node", true, { max_items = 10 }); + assert.is_true(ok, err); + end); + + it("create with unacceptable config", function () + local ok, err = service:create("node", true, { max_items = 100 }); + assert.falsy(ok, err); + end); + + + end); + end); diff --git a/util/pubsub.lua b/util/pubsub.lua index a53e8b95..e5e0cb7c 100644 --- a/util/pubsub.lua +++ b/util/pubsub.lua @@ -436,10 +436,19 @@ function service:create(node, actor, options) --> ok, err return false, "conflict"; end + local config = setmetatable(options or {}, {__index=self.node_defaults}); + + if self.config.check_node_config then + local ok = self.config.check_node_config(node, actor, config); + if not ok then + return false, "not-acceptable"; + end + end + self.nodes[node] = { name = node; subscribers = {}; - config = setmetatable(options or {}, {__index=self.node_defaults}); + config = config; affiliations = {}; }; -- cgit v1.2.3 From dad8bb5feebd8d32c1d4172d205b871e824d42b8 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 4 Mar 2019 12:56:31 +0100 Subject: mod_muc_mam: Strip the stanza 'to' attribute (fixes #1259) --- plugins/mod_muc_mam.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/mod_muc_mam.lua b/plugins/mod_muc_mam.lua index 166a5c71..c92e22cd 100644 --- a/plugins/mod_muc_mam.lua +++ b/plugins/mod_muc_mam.lua @@ -208,6 +208,7 @@ module:hook("iq-set/bare/"..xmlns_mam..":query", function(event) if not is_stanza(item) then item = st.deserialize(item); end + item.attr.to = nil; item.attr.xmlns = "jabber:client"; fwd_st:add_child(item); @@ -329,6 +330,7 @@ local function save_to_history(self, stanza) if stanza.name == "message" and self:get_whois() == "anyone" then stored_stanza = st.clone(stanza); + stored_stanza.attr.to = nil; local actor = jid_bare(self._occupants[stanza.attr.from].jid); local affiliation = self:get_affiliation(actor) or "none"; local role = self:get_role(actor) or self:get_default_role(affiliation); -- cgit v1.2.3 From 2c8eecf7c2b3c27a4c3f29f49a081be2a578ae90 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 4 Mar 2019 12:57:42 +0100 Subject: mod_muc_mam: Move a comment to the line it describes --- plugins/mod_muc_mam.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_muc_mam.lua b/plugins/mod_muc_mam.lua index c92e22cd..c9430ae8 100644 --- a/plugins/mod_muc_mam.lua +++ b/plugins/mod_muc_mam.lua @@ -341,12 +341,12 @@ local function save_to_history(self, stanza) -- Policy check if not archiving_enabled(self) then return end -- Don't log - -- And stash it local with = stanza.name if stanza.attr.type then with = with .. "<" .. stanza.attr.type end + -- And stash it local id = archive:append(room_node, nil, stored_stanza, time_now(), with); if id then -- cgit v1.2.3 From 09a662026a3fc4c69eda9d8ef8862abac5569625 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 4 Mar 2019 12:58:20 +0100 Subject: mod_muc_mam: Add comment about the tricks done with the 'with' field --- plugins/mod_muc_mam.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/mod_muc_mam.lua b/plugins/mod_muc_mam.lua index c9430ae8..ede4e57a 100644 --- a/plugins/mod_muc_mam.lua +++ b/plugins/mod_muc_mam.lua @@ -341,6 +341,7 @@ local function save_to_history(self, stanza) -- Policy check if not archiving_enabled(self) then return end -- Don't log + -- Save the type in the 'with' field, allows storing presence without conflicts local with = stanza.name if stanza.attr.type then with = with .. "<" .. stanza.attr.type -- cgit v1.2.3