Comparison

spec/util_pubsub_spec.lua @ 9169:3ec013185c15

util.pubsub tests: Add some initial access model tests (open and whitelist)
author Matthew Wild <mwild1@gmail.com>
date Sat, 11 Aug 2018 19:18:13 +0100
parent 9159:a0fd7064f4ac
child 9171:5f03fe90704f
comparison
equal deleted inserted replaced
9168:29de7ad20250 9169:3ec013185c15
109 ["3"] = "item 3", 109 ["3"] = "item 3",
110 }, ret); 110 }, ret);
111 end); 111 end);
112 112
113 end); 113 end);
114
115 describe("access model", function ()
116 describe("open", function ()
117 local service;
118 before_each(function ()
119 service = pubsub.new();
120 -- Do not supply any config, 'open' should be default
121 service:create("test", true);
122 end);
123 it("should be the default", function ()
124 local ok, config = service:get_node_config("test", true);
125 assert.equal("open", config.access_model);
126 end);
127 it("should allow anyone to subscribe", function ()
128 local ok = service:add_subscription("test", "stranger", "stranger");
129 assert.is_true(ok);
130 end);
131 it("should not allow anyone to publish", function ()
132 assert.is_true(service:add_subscription("test", "stranger", "stranger"));
133 local ok, err = service:publish("test", "stranger", "item1", "foo");
134 assert.is_falsy(ok);
135 assert.equals("forbidden", err);
136 end);
137 it("should still reject outcast-affiliated entities", function ()
138 assert(service:set_affiliation("test", true, "enemy", "outcast"));
139 local ok, err = service:add_subscription("test", "enemy", "enemy");
140 assert.is_falsy(ok);
141 assert.equal("forbidden", err);
142 end);
143 end);
144 describe("whitelist", function ()
145 local service;
146 before_each(function ()
147 service = assert(pubsub.new());
148 assert.is_true(service:create("test", true, { access_model = "whitelist" }));
149 end);
150 it("should be present in the configuration", function ()
151 local ok, config = service:get_node_config("test", true);
152 assert.equal("whitelist", config.access_model);
153 end);
154 it("should not allow anyone to subscribe", function ()
155 local ok, err = service:add_subscription("test", "stranger", "stranger");
156 assert.is_false(ok);
157 assert.equals("forbidden", err);
158 end);
159 it("should not allow anyone to publish", function ()
160 local ok, err = service:publish("test", "stranger", "item1", "foo");
161 assert.is_falsy(ok);
162 assert.equals("forbidden", err);
163 end);
164 end);
165 end);
114 end); 166 end);