Mercurial > prosody-hg
comparison spec/util_pubsub_spec.lua @ 9171:5f03fe90704f
util.pubsub tests: Add tests for publish_model (publishers, open, subscribers)
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sun, 12 Aug 2018 10:43:18 +0100 |
| parents | 3ec013185c15 |
| children | c53663e13b51 |
comparison
equal
deleted
inserted
replaced
| 9170:47ffce31ffe4 | 9171:5f03fe90704f |
|---|---|
| 126 end); | 126 end); |
| 127 it("should allow anyone to subscribe", function () | 127 it("should allow anyone to subscribe", function () |
| 128 local ok = service:add_subscription("test", "stranger", "stranger"); | 128 local ok = service:add_subscription("test", "stranger", "stranger"); |
| 129 assert.is_true(ok); | 129 assert.is_true(ok); |
| 130 end); | 130 end); |
| 131 it("should still reject outcast-affiliated entities", function () | |
| 132 assert(service:set_affiliation("test", true, "enemy", "outcast")); | |
| 133 local ok, err = service:add_subscription("test", "enemy", "enemy"); | |
| 134 assert.is_falsy(ok); | |
| 135 assert.equal("forbidden", err); | |
| 136 end); | |
| 137 end); | |
| 138 describe("whitelist", function () | |
| 139 local service; | |
| 140 before_each(function () | |
| 141 service = assert(pubsub.new()); | |
| 142 assert.is_true(service:create("test", true, { access_model = "whitelist" })); | |
| 143 end); | |
| 144 it("should be present in the configuration", function () | |
| 145 local ok, config = service:get_node_config("test", true); | |
| 146 assert.equal("whitelist", config.access_model); | |
| 147 end); | |
| 148 it("should not allow anyone to subscribe", function () | |
| 149 local ok, err = service:add_subscription("test", "stranger", "stranger"); | |
| 150 assert.is_false(ok); | |
| 151 assert.equals("forbidden", err); | |
| 152 end); | |
| 153 end); | |
| 154 end); | |
| 155 | |
| 156 describe("publish model", function () | |
| 157 describe("publishers", function () | |
| 158 local service; | |
| 159 before_each(function () | |
| 160 service = pubsub.new(); | |
| 161 -- Do not supply any config, 'publishers' should be default | |
| 162 service:create("test", true); | |
| 163 end); | |
| 164 it("should be the default", function () | |
| 165 local ok, config = service:get_node_config("test", true); | |
| 166 assert.equal("publishers", config.publish_model); | |
| 167 end); | |
| 131 it("should not allow anyone to publish", function () | 168 it("should not allow anyone to publish", function () |
| 132 assert.is_true(service:add_subscription("test", "stranger", "stranger")); | 169 assert.is_true(service:add_subscription("test", "stranger", "stranger")); |
| 133 local ok, err = service:publish("test", "stranger", "item1", "foo"); | 170 local ok, err = service:publish("test", "stranger", "item1", "foo"); |
| 134 assert.is_falsy(ok); | 171 assert.is_falsy(ok); |
| 135 assert.equals("forbidden", err); | 172 assert.equals("forbidden", err); |
| 136 end); | 173 end); |
| 137 it("should still reject outcast-affiliated entities", function () | 174 it("should allow publishers to publish", function () |
| 138 assert(service:set_affiliation("test", true, "enemy", "outcast")); | 175 assert(service:set_affiliation("test", true, "mypublisher", "publisher")); |
| 139 local ok, err = service:add_subscription("test", "enemy", "enemy"); | 176 local ok, err = service:publish("test", "mypublisher", "item1", "foo"); |
| 140 assert.is_falsy(ok); | 177 assert.is_true(ok); |
| 141 assert.equal("forbidden", err); | 178 end); |
| 142 end); | 179 it("should allow owners to publish", function () |
| 143 end); | 180 assert(service:set_affiliation("test", true, "myowner", "owner")); |
| 144 describe("whitelist", function () | 181 local ok = service:publish("test", "myowner", "item1", "foo"); |
| 145 local service; | 182 assert.is_true(ok); |
| 146 before_each(function () | 183 end); |
| 147 service = assert(pubsub.new()); | 184 end); |
| 148 assert.is_true(service:create("test", true, { access_model = "whitelist" })); | 185 describe("open", function () |
| 149 end); | 186 local service; |
| 150 it("should be present in the configuration", function () | 187 before_each(function () |
| 151 local ok, config = service:get_node_config("test", true); | 188 service = pubsub.new(); |
| 152 assert.equal("whitelist", config.access_model); | 189 service:create("test", true, { publish_model = "open" }); |
| 153 end); | 190 end); |
| 154 it("should not allow anyone to subscribe", function () | 191 it("should allow anyone to publish", function () |
| 155 local ok, err = service:add_subscription("test", "stranger", "stranger"); | 192 local ok = service:publish("test", "stranger", "item1", "foo"); |
| 156 assert.is_false(ok); | 193 assert.is_true(ok); |
| 157 assert.equals("forbidden", err); | 194 end); |
| 158 end); | 195 end); |
| 159 it("should not allow anyone to publish", function () | 196 describe("subscribers", function () |
| 197 local service; | |
| 198 before_each(function () | |
| 199 service = pubsub.new(); | |
| 200 service:create("test", true, { publish_model = "subscribers" }); | |
| 201 end); | |
| 202 it("should not allow non-subscribers to publish", function () | |
| 160 local ok, err = service:publish("test", "stranger", "item1", "foo"); | 203 local ok, err = service:publish("test", "stranger", "item1", "foo"); |
| 161 assert.is_falsy(ok); | 204 assert.is_falsy(ok); |
| 162 assert.equals("forbidden", err); | 205 assert.equals("forbidden", err); |
| 163 end); | 206 end); |
| 207 it("should allow subscribers to publish without an affiliation", function () | |
| 208 assert.is_true(service:add_subscription("test", "stranger", "stranger")); | |
| 209 local ok = service:publish("test", "stranger", "item1", "foo"); | |
| 210 assert.is_true(ok); | |
| 211 end); | |
| 212 it("should allow publishers to publish without a subscription", function () | |
| 213 assert(service:set_affiliation("test", true, "mypublisher", "publisher")); | |
| 214 local ok, err = service:publish("test", "mypublisher", "item1", "foo"); | |
| 215 assert.is_true(ok); | |
| 216 end); | |
| 217 it("should allow owners to publish without a subscription", function () | |
| 218 assert(service:set_affiliation("test", true, "myowner", "owner")); | |
| 219 local ok = service:publish("test", "myowner", "item1", "foo"); | |
| 220 assert.is_true(ok); | |
| 221 end); | |
| 164 end); | 222 end); |
| 165 end); | 223 end); |
| 166 end); | 224 end); |
