From 17595df1a00ec1bcff54ce000c99f2c3170fbdeb Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 11 Aug 2018 19:18:13 +0100 Subject: util.pubsub tests: Add some initial access model tests (open and whitelist) --- spec/util_pubsub_spec.lua | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'spec/util_pubsub_spec.lua') 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); -- cgit v1.2.3