Add some additional improved permission.js tests, and null check rather than !Metadata in permission handleBody (because else 0 would be true)

indiachan-spamvector
Thomas Lynch 1 year ago
parent 571380e243
commit d68a32b831
  1. 2
      lib/permission/permission.js
  2. 24
      lib/permission/permission.test.js

@ -30,7 +30,7 @@ class Permission extends BigBitfield {
const handlingBits = boardOnly ? Permissions._MANAGE_BOARD_BITS : Object.keys(Metadata);
for (let bit of handlingBits) {
// If perm has no "parent" bit, or current user has the parent permission, set each bit based on the form input
const allowedParent = !Metadata[bit].parent
const allowedParent = Metadata[bit].parent == null
|| editorPermission.get(Metadata[bit].parent);
if (allowedParent && !Metadata[bit].block) {
this.set(parseInt(bit), (body[`permission_bit_${bit}`] != null));

@ -67,6 +67,28 @@ describe('testing permissions', () => {
expect(Permission.allPermissions.every(b => NO_PERMISSION.get(b))).toBe(true);
});
//todo: what othe rpermissions test should be added?
test('handleBody() by somebody with editorPermission NOT having Permissions.ROOT cannot set Permissions.ROOT', () => {
const TEST_PERMISSION = new Permission();
TEST_PERMISSION.handleBody({
'permission_bit_0': 0,
}, ANON);
expect(TEST_PERMISSION.get(0)).toBe(false);
});
test('handleBody() by somebody with editorPermission having Permissions.ROOT CAN set Permissions.ROOT', () => {
const TEST_PERMISSION = new Permission();
TEST_PERMISSION.handleBody({
'permission_bit_0': 0,
}, ROOT);
expect(TEST_PERMISSION.get(0)).toBe(true);
});
test('handleBody() does not allow setting permission outside of _MANAGE_BOARD_BITS when boardOnly=true, even with permission', () => {
const TEST_PERMISSION = new Permission();
TEST_PERMISSION.handleBody({
'permission_bit_0': 0,
}, ROOT, true);
expect(TEST_PERMISSION.get(0)).toBe(false);
});
});

Loading…
Cancel
Save