From d13e7cd36c89eb8d2ae80a40c99266533f9cb75e Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 24 Aug 2023 14:10:45 -0400 Subject: [PATCH 1/2] fix: isPrivilegeGroup not capturing admin privileges --- src/groups/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/groups/index.js b/src/groups/index.js index a66e34c6b3..d9549ba805 100644 --- a/src/groups/index.js +++ b/src/groups/index.js @@ -55,7 +55,7 @@ Groups.removeEphemeralGroups = function (groups) { return groups; }; -const isPrivilegeGroupRegex = /^cid:\d+:privileges:[\w\-:]+$/; +const isPrivilegeGroupRegex = /^cid:(?:\d+|admin):privileges:[\w\-:]+$/; Groups.isPrivilegeGroup = function (groupName) { return isPrivilegeGroupRegex.test(groupName); }; From d5c8bf9eb1060af83661dd25ca666d59882ce811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Thu, 24 Aug 2023 14:26:27 -0400 Subject: [PATCH 2/2] test: add some tests for isPrivilegeGroup --- test/groups.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/groups.js b/test/groups.js index c80313e467..2fcb48d59e 100644 --- a/test/groups.js +++ b/test/groups.js @@ -1404,4 +1404,20 @@ describe('Groups', () => { assert(!groupData['cover:url']); }); }); + + describe('isPrivilegeGroup', () => { + assert.strictEqual(Groups.isPrivilegeGroup('cid:1:privileges:topics:find'), true); + assert.strictEqual(Groups.isPrivilegeGroup('cid:1:privileges:groups:topics:find'), true); + assert.strictEqual(Groups.isPrivilegeGroup('cid:0:privileges:groups:search:users'), true); + assert.strictEqual(Groups.isPrivilegeGroup('cid:admin:privileges:admin:users'), true); + assert.strictEqual(Groups.isPrivilegeGroup('cid::privileges:admin:users'), false); + assert.strictEqual(Groups.isPrivilegeGroup('cid:string:privileges:admin:users'), false); + assert.strictEqual(Groups.isPrivilegeGroup('admin'), false); + assert.strictEqual(Groups.isPrivilegeGroup('registered-users'), false); + assert.strictEqual(Groups.isPrivilegeGroup(''), false); + assert.strictEqual(Groups.isPrivilegeGroup(null), false); + assert.strictEqual(Groups.isPrivilegeGroup(undefined), false); + assert.strictEqual(Groups.isPrivilegeGroup(false), false); + assert.strictEqual(Groups.isPrivilegeGroup(true), false); + }); });