aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2018-08-11 19:18:13 +0100
committerMatthew Wild <mwild1@gmail.com>2018-08-11 19:18:13 +0100
commit0a7dcafbbad82bcbe4eafec2a7eaf11ae5356648 (patch)
tree8e39038ba084de999dc71dd686af49f8670029f8 /spec
parentf8abac32f5f32853f5457c85c5a7ca3a85933271 (diff)
downloadprosody-0a7dcafbbad82bcbe4eafec2a7eaf11ae5356648.tar.gz
prosody-0a7dcafbbad82bcbe4eafec2a7eaf11ae5356648.zip
util.pubsub tests: Add some initial access model tests (open and whitelist)
Diffstat (limited to 'spec')
-rw-r--r--spec/util_pubsub_spec.lua52
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/util_pubsub_spec.lua b/spec/util_pubsub_spec.lua
index 068dbd1a..bc81b2eb 100644
--- a/spec/util_pubsub_spec.lua
+++ b/spec/util_pubsub_spec.lua
@@ -111,4 +111,56 @@ describe("util.pubsub", function ()
end);
end);
+
+ describe("access model", function ()
+ describe("open", function ()
+ local service;
+ before_each(function ()
+ service = pubsub.new();
+ -- Do not supply any config, 'open' should be default
+ service:create("test", true);
+ end);
+ it("should be the default", function ()
+ local ok, config = service:get_node_config("test", true);
+ assert.equal("open", config.access_model);
+ end);
+ it("should allow anyone to subscribe", function ()
+ local ok = service:add_subscription("test", "stranger", "stranger");
+ assert.is_true(ok);
+ end);
+ it("should not allow anyone to publish", function ()
+ assert.is_true(service:add_subscription("test", "stranger", "stranger"));
+ local ok, err = service:publish("test", "stranger", "item1", "foo");
+ assert.is_falsy(ok);
+ assert.equals("forbidden", err);
+ end);
+ it("should still reject outcast-affiliated entities", function ()
+ assert(service:set_affiliation("test", true, "enemy", "outcast"));
+ local ok, err = service:add_subscription("test", "enemy", "enemy");
+ assert.is_falsy(ok);
+ assert.equal("forbidden", err);
+ end);
+ end);
+ describe("whitelist", function ()
+ local service;
+ before_each(function ()
+ service = assert(pubsub.new());
+ assert.is_true(service:create("test", true, { access_model = "whitelist" }));
+ end);
+ it("should be present in the configuration", function ()
+ local ok, config = service:get_node_config("test", true);
+ assert.equal("whitelist", config.access_model);
+ end);
+ it("should not allow anyone to subscribe", function ()
+ local ok, err = service:add_subscription("test", "stranger", "stranger");
+ assert.is_false(ok);
+ assert.equals("forbidden", err);
+ end);
+ it("should not allow anyone to publish", function ()
+ local ok, err = service:publish("test", "stranger", "item1", "foo");
+ assert.is_falsy(ok);
+ assert.equals("forbidden", err);
+ end);
+ end);
+ end);
end);