mirror of
https://github.com/bjc/prosody.git
synced 2025-04-03 05:07:42 +03:00
util.pubsub: Validate node configuration on node creation (fixes #1328)
This commit is contained in:
parent
7241f86668
commit
5d4504e51b
2 changed files with 51 additions and 1 deletions
|
@ -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);
|
||||
|
|
|
@ -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 = {};
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue