Software /
code /
prosody
File
spec/util_array_spec.lua @ 12659:c0eea4f6c739
usermanager: Add back temporary is_admin to warn about deprecated API usage
Goal: Introduce role-auth with minimal disruption
is_admin() is unsafe in a system with per-session permissions, so it has been
deprecated.
Roll-out approach:
1) First, log a warning when is_admin() is used. It should continue to
function normally, backed by the new role API. Nothing is really using
per-session authz yet, so there is minimal security concern.
The 'strict_deprecate_is_admin' global setting can be set to 'true' to
force a hard failure of is_admin() attempts (it will log an error and
always return false).
2) In some time (at least 1 week), but possibly longer depending on the number
of affected deployments: switch 'strict_deprecate_is_admin' to 'true' by
default. It can still be disabled for systems that need it.
3) Further in the future, before the next release, the option will be removed
and is_admin() will be permanently disabled.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 15 Aug 2022 15:25:07 +0100 |
parent | 11787:3ae6fa901a8b |
child | 13245:ffe4adbd2af9 |
line wrap: on
line source
local array = require "util.array"; describe("util.array", function () describe("creation", function () describe("from table", function () it("works", function () local a = array({"a", "b", "c"}); assert.same({"a", "b", "c"}, a); end); end); describe("from iterator", function () it("works", function () -- collects the first value, ie the keys local a = array(ipairs({true, true, true})); assert.same({1, 2, 3}, a); end); end); describe("collect", function () it("works", function () -- collects the first value, ie the keys local a = array.collect(ipairs({true, true, true})); assert.same({1, 2, 3}, a); end); end); end); describe("metatable", function () describe("operator", function () describe("addition", function () it("works", function () local a = array({ "a", "b" }); local b = array({ "c", "d" }); assert.same({"a", "b", "c", "d"}, a + b); end); end); describe("equality", function () it("works", function () local a1 = array({ "a", "b" }); local a2 = array({ "a", "b" }); local b = array({ "c", "d" }); assert.truthy(a1 == a2); assert.falsy(a1 == b); assert.falsy(a1 == { "a", "b" }, "Behavior of metatables changed in Lua 5.3"); end); end); describe("division", function () it("works", function () local a = array({ "a", "b", "c" }); local b = a / function (i) if i ~= "b" then return i .. "x" end end; assert.same({ "ax", "cx" }, b); end); end); end); end); describe("methods", function () describe("map", function () it("works", function () local a = array({ "a", "b", "c" }); local b = a:map(string.upper); assert.same({ "A", "B", "C" }, b); end); end); describe("filter", function () it("works", function () local a = array({ "a", "b", "c" }); a:filter(function (i) return i ~= "b" end); assert.same({ "a", "c" }, a); end); end); describe("sort", function () it("works", function () local a = array({ 5, 4, 3, 1, 2, }); a:sort(); assert.same({ 1, 2, 3, 4, 5, }, a); end); end); describe("unique", function () it("works", function () local a = array({ "a", "b", "c", "c", "a", "b" }); a:unique(); assert.same({ "a", "b", "c" }, a); end); end); describe("pluck", function () it("works", function () local a = array({ { a = 1, b = -1 }, { a = 2, b = -2 }, }); a:pluck("a"); assert.same({ 1, 2 }, a); end); end); describe("reverse", function () it("works", function () local a = array({ "a", "b", "c" }); a:reverse(); assert.same({ "c", "b", "a" }, a); end); end); -- TODO :shuffle describe("append", function () it("works", function () local a = array({ "a", "b", "c" }); a:append(array({ "d", "e", })); assert.same({ "a", "b", "c", "d", "e" }, a); end); end); describe("push", function () it("works", function () local a = array({ "a", "b", "c" }); a:push("d"):push("e"); assert.same({ "a", "b", "c", "d", "e" }, a); end); end); describe("pop", function () it("works", function () local a = array({ "a", "b", "c" }); assert.equal("c", a:pop()); assert.same({ "a", "b", }, a); end); end); describe("concat", function () it("works", function () local a = array({ "a", "b", "c" }); assert.equal("a,b,c", a:concat(",")); end); end); describe("length", function () it("works", function () local a = array({ "a", "b", "c" }); assert.equal(3, a:length()); end); end); describe("slice", function () it("works", function () local a = array({ "a", "b", "c" }); assert.equal(array.slice(a, 1, 2), array{ "a", "b" }); assert.equal(array.slice(a, 1, 3), array{ "a", "b", "c" }); assert.equal(array.slice(a, 2, 3), array{ "b", "c" }); assert.equal(array.slice(a, 2), array{ "b", "c" }); assert.equal(array.slice(a, -4), array{ "a", "b", "c" }); assert.equal(array.slice(a, -3), array{ "a", "b", "c" }); assert.equal(array.slice(a, -2), array{ "b", "c" }); assert.equal(array.slice(a, -1), array{ "c" }); end); it("can mutate", function () local a = array({ "a", "b", "c" }); assert.equal(a:slice(-1), array{"c"}); assert.equal(a, array{"c"}); end); end); end); -- TODO The various array.foo(array ina, array outa) functions end);