Software /
code /
prosody
File
spec/util_rsm_spec.lua @ 12790:24b55f0e2db9 0.12
mod_http: Allow disabling CORS in the http_cors_override option and by default
Fixes #1779.
Due to an oversight in the logic, if the user set 'enabled' to false in an
override, it would disable the item's requested CORS settings, but still apply
Prosody's default CORS policy.
This change ensures that 'enabled = false' will now disable CORS entirely for
the requested item.
Due to the new structure of the code, it was necessary to have a flag to say
whether CORS is to be applied at all. Rather than hard-coding 'true' here, I
chose to add a new option: 'http_default_cors_enabled'. This is a boolean that
allows the operator to disable Prosody's default CORS policy entirely (the one
that is used when a module or config does not override it). This makes it
easier to disable CORS and then selectively enable it only on services you
want it on.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 31 Oct 2022 14:32:02 +0000 |
parent | 11427:83f5499d1f10 |
line wrap: on
line source
local rsm = require "util.rsm"; local xml = require "util.xml"; local function strip(s) return (s:gsub(">%s+<", "><")); end describe("util.rsm", function () describe("parse", function () it("works", function () local test = xml.parse(strip([[ <set xmlns='http://jabber.org/protocol/rsm'> <max>10</max> </set> ]])); assert.same({ max = 10 }, rsm.parse(test)); end); it("works", function () local test = xml.parse(strip([[ <set xmlns='http://jabber.org/protocol/rsm'> <first index='0'>saint@example.org</first> <last>peterpan@neverland.lit</last> <count>800</count> </set> ]])); assert.same({ first = { index = 0, "saint@example.org" }, last = "peterpan@neverland.lit", count = 800 }, rsm.parse(test)); end); it("works", function () local test = xml.parse(strip([[ <set xmlns='http://jabber.org/protocol/rsm'> <max>10</max> <before>peter@pixyland.org</before> </set> ]])); assert.same({ max = 10, before = "peter@pixyland.org" }, rsm.parse(test)); end); it("all fields works", function() local test = assert(xml.parse(strip([[ <set xmlns='http://jabber.org/protocol/rsm'> <after>a</after> <before>b</before> <count>10</count> <first index='1'>f</first> <index>5</index> <last>z</last> <max>100</max> </set> ]]))); assert.same({ after = "a"; before = "b"; count = 10; first = {index = 1; "f"}; index = 5; last = "z"; max = 100; }, rsm.parse(test)); end); end); describe("generate", function () it("works", function () local test = xml.parse(strip([[ <set xmlns='http://jabber.org/protocol/rsm'> <max>10</max> </set> ]])); local res = rsm.generate({ max = 10 }); assert.same(test:get_child_text("max"), res:get_child_text("max")); end); it("works", function () local test = xml.parse(strip([[ <set xmlns='http://jabber.org/protocol/rsm'> <first index='0'>saint@example.org</first> <last>peterpan@neverland.lit</last> <count>800</count> </set> ]])); local res = rsm.generate({ first = { index = 0, "saint@example.org" }, last = "peterpan@neverland.lit", count = 800 }); assert.same(test:get_child("first").attr.index, res:get_child("first").attr.index); assert.same(test:get_child_text("first"), res:get_child_text("first")); assert.same(test:get_child_text("last"), res:get_child_text("last")); assert.same(test:get_child_text("count"), res:get_child_text("count")); end); it("works", function () local test = xml.parse(strip([[ <set xmlns='http://jabber.org/protocol/rsm'> <max>10</max> <before>peter@pixyland.org</before> </set> ]])); local res = rsm.generate({ max = 10, before = "peter@pixyland.org" }); assert.same(test:get_child_text("max"), res:get_child_text("max")); assert.same(test:get_child_text("before"), res:get_child_text("before")); end); it("handles floats", function () local r1 = rsm.generate({ max = 10.0, count = 100.0, first = { index = 1.0, "foo" } }); assert.equal("10", r1:get_child_text("max")); assert.equal("100", r1:get_child_text("count")); assert.equal("1", r1:get_child("first").attr.index); end); it("all fields works", function () local res = rsm.generate({ after = "a"; before = "b"; count = 10; first = {index = 1; "f"}; index = 5; last = "z"; max = 100; }); assert.equal("a", res:get_child_text("after")); assert.equal("b", res:get_child_text("before")); assert.equal("10", res:get_child_text("count")); assert.equal("f", res:get_child_text("first")); assert.equal("1", res:get_child("first").attr.index); assert.equal("5", res:get_child_text("index")); assert.equal("z", res:get_child_text("last")); assert.equal("100", res:get_child_text("max")); end); end); end);