diff options
author | Kim Alvefur <zash@zash.se> | 2019-03-03 19:31:56 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2019-03-03 19:31:56 +0100 |
commit | 5d4504e51b8d1e77b20fffaf60cd7f2bdb80785a (patch) | |
tree | 2f850f6d31956c595e9950ae016378195acadd57 | |
parent | 7241f866687168f1e3f9238ea240af0f4b319ccb (diff) | |
download | prosody-5d4504e51b8d1e77b20fffaf60cd7f2bdb80785a.tar.gz prosody-5d4504e51b8d1e77b20fffaf60cd7f2bdb80785a.zip |
util.pubsub: Validate node configuration on node creation (fixes #1328)
-rw-r--r-- | spec/util_pubsub_spec.lua | 41 | ||||
-rw-r--r-- | util/pubsub.lua | 11 |
2 files changed, 51 insertions, 1 deletions
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 = {}; }; |