From 0b24fe1a9b89e2c8e52c495d0d534df32710ed0e Mon Sep 17 00:00:00 2001 From: Rui Tome Date: Fri, 24 Nov 2023 11:17:47 +0000 Subject: [PATCH] =?UTF-8?q?[AC-1139]=C2=A0Rewrote=20GroupAuthorizationHand?= =?UTF-8?q?ler=20to=20be=20similar=20to=20other=20AuthHandlers;=20Revisite?= =?UTF-8?q?d=20unit=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Groups/GroupAuthorizationHandler.cs | 39 +++++++++---------- .../GroupAuthorizationHandlerTests.cs | 22 +++++++---- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/Api/Vault/AuthorizationHandlers/Groups/GroupAuthorizationHandler.cs b/src/Api/Vault/AuthorizationHandlers/Groups/GroupAuthorizationHandler.cs index ec48338451..a80b3db928 100644 --- a/src/Api/Vault/AuthorizationHandlers/Groups/GroupAuthorizationHandler.cs +++ b/src/Api/Vault/AuthorizationHandlers/Groups/GroupAuthorizationHandler.cs @@ -1,4 +1,5 @@ -using Bit.Core; +#nullable enable +using Bit.Core; using Bit.Core.Context; using Bit.Core.Enums; using Bit.Core.Exceptions; @@ -58,29 +59,27 @@ public class GroupAuthorizationHandler : AuthorizationHandler sutProvider, CurrentContextOrganization organization) { + organization.Type = OrganizationUserType.User; + organization.LimitCollectionCreationDeletion = true; + organization.Permissions = new Permissions(); + var context = new AuthorizationHandlerContext( new[] { GroupOperations.ReadAll(organization.Id) }, new ClaimsPrincipal(), @@ -64,26 +69,27 @@ public class GroupAuthorizationHandlerTests } [Theory] - [BitAutoData(true, false, false, false, false)] - [BitAutoData(false, true, false, false, false)] - [BitAutoData(false, false, true, false, false)] - [BitAutoData(false, false, false, true, false)] - [BitAutoData(false, false, false, false, true)] + [BitAutoData(true, false, false, false, true)] + [BitAutoData(false, true, false, false, true)] + [BitAutoData(false, false, true, false, true)] + [BitAutoData(false, false, false, true, true)] + [BitAutoData(false, false, false, false, false)] public async Task CanReadAllAsync_WhenCustomUserWithRequiredPermissions_Success( - bool editAnyCollection, bool deleteAnyCollection, bool manageGroups, bool manageUsers, bool accessImportExport, + bool editAnyCollection, bool deleteAnyCollection, bool manageGroups, + bool manageUsers, bool limitCollectionCreationDeletion, SutProvider sutProvider, CurrentContextOrganization organization) { var actingUserId = Guid.NewGuid(); organization.Type = OrganizationUserType.Custom; + organization.LimitCollectionCreationDeletion = limitCollectionCreationDeletion; organization.Permissions = new Permissions { EditAnyCollection = editAnyCollection, DeleteAnyCollection = deleteAnyCollection, ManageGroups = manageGroups, - ManageUsers = manageUsers, - AccessImportExport = accessImportExport + ManageUsers = manageUsers }; var context = new AuthorizationHandlerContext(