From bcf321064c316f982aaa4ae862156aee52b55e6e Mon Sep 17 00:00:00 2001 From: Shane Melton Date: Wed, 11 Dec 2024 16:44:57 -0800 Subject: [PATCH] [PM-14378] Formatting --- .../SecurityTaskAuthorizationHandler.cs | 4 +- .../GetCipherPermissionsForUserQuery.cs | 3 +- .../SecurityTaskAuthorizationHandlerTests.cs | 6 +- ...skOrganizationAuthorizationHandlerTests.cs | 1 - .../GetCipherPermissionsForUserQueryTests.cs | 58 +++++++++---------- 5 files changed, 35 insertions(+), 37 deletions(-) diff --git a/src/Core/Vault/Authorization/SecurityTasks/SecurityTaskAuthorizationHandler.cs b/src/Core/Vault/Authorization/SecurityTasks/SecurityTaskAuthorizationHandler.cs index 626174bfa271..eedae9908341 100644 --- a/src/Core/Vault/Authorization/SecurityTasks/SecurityTaskAuthorizationHandler.cs +++ b/src/Core/Vault/Authorization/SecurityTasks/SecurityTaskAuthorizationHandler.cs @@ -121,8 +121,8 @@ private async Task CipherBelongsToOrgAsync(CurrentContextOrganization org, private bool HasAdminAccessToSecurityTasks(CurrentContextOrganization org) { return org is - { Type: OrganizationUserType.Admin or OrganizationUserType.Owner } or - { Type: OrganizationUserType.Custom, Permissions.AccessReports: true }; + { Type: OrganizationUserType.Admin or OrganizationUserType.Owner } or + { Type: OrganizationUserType.Custom, Permissions.AccessReports: true }; } private async Task> GetCipherPermissionsForOrgAsync(CurrentContextOrganization organization) diff --git a/src/Core/Vault/Queries/GetCipherPermissionsForUserQuery.cs b/src/Core/Vault/Queries/GetCipherPermissionsForUserQuery.cs index 650c7dd65559..df336776eab3 100644 --- a/src/Core/Vault/Queries/GetCipherPermissionsForUserQuery.cs +++ b/src/Core/Vault/Queries/GetCipherPermissionsForUserQuery.cs @@ -41,7 +41,8 @@ public async Task> GetByOrganiza cipher.Manage = true; cipher.ViewPassword = true; } - } else if (await CanAccessUnassignedCiphersAsync(org)) + } + else if (await CanAccessUnassignedCiphersAsync(org)) { foreach (var unassignedCipher in cipherPermissions.Where(c => c.Unassigned)) { diff --git a/test/Core.Test/Vault/Authorization/SecurityTaskAuthorizationHandlerTests.cs b/test/Core.Test/Vault/Authorization/SecurityTaskAuthorizationHandlerTests.cs index e4566347761d..43bdceac9898 100644 --- a/test/Core.Test/Vault/Authorization/SecurityTaskAuthorizationHandlerTests.cs +++ b/test/Core.Test/Vault/Authorization/SecurityTaskAuthorizationHandlerTests.cs @@ -298,10 +298,10 @@ public async Task Create_Admin_Success( Assert.True(context.HasSucceeded); } - [Theory, CurrentContextOrganizationCustomize(Type = OrganizationUserType.User), BitAutoData] + [Theory, CurrentContextOrganizationCustomize(Type = OrganizationUserType.User), BitAutoData] public async Task Update_User_CanEditCipher_Success( - CurrentContextOrganization organization, - SutProvider sutProvider) + CurrentContextOrganization organization, + SutProvider sutProvider) { var userId = Guid.NewGuid(); var task = new SecurityTask diff --git a/test/Core.Test/Vault/Authorization/SecurityTaskOrganizationAuthorizationHandlerTests.cs b/test/Core.Test/Vault/Authorization/SecurityTaskOrganizationAuthorizationHandlerTests.cs index c5a6ffcc1df5..d0b2ecbcf051 100644 --- a/test/Core.Test/Vault/Authorization/SecurityTaskOrganizationAuthorizationHandlerTests.cs +++ b/test/Core.Test/Vault/Authorization/SecurityTaskOrganizationAuthorizationHandlerTests.cs @@ -3,7 +3,6 @@ using Bit.Core.Enums; using Bit.Core.Test.AdminConsole.AutoFixture; using Bit.Core.Vault.Authorization.SecurityTasks; -using Bit.Core.Vault.Entities; using Bit.Test.Common.AutoFixture; using Bit.Test.Common.AutoFixture.Attributes; using Microsoft.AspNetCore.Authorization; diff --git a/test/Core.Test/Vault/Queries/GetCipherPermissionsForUserQueryTests.cs b/test/Core.Test/Vault/Queries/GetCipherPermissionsForUserQueryTests.cs index e681328a65da..af92f50ed056 100644 --- a/test/Core.Test/Vault/Queries/GetCipherPermissionsForUserQueryTests.cs +++ b/test/Core.Test/Vault/Queries/GetCipherPermissionsForUserQueryTests.cs @@ -1,6 +1,4 @@ -using AutoFixture; -using Bit.Core.AdminConsole.Entities; -using Bit.Core.Context; +using Bit.Core.Context; using Bit.Core.Enums; using Bit.Core.Models.Data.Organizations; using Bit.Core.Services; @@ -24,7 +22,7 @@ public class GetCipherPermissionsForUserQueryTests private static Guid _readExceptPasswordCipherId = Guid.NewGuid(); private static Guid _unassignedCipherId = Guid.NewGuid(); - private static List _cipherIds = new [] + private static List _cipherIds = new[] { _noAccessCipherId, _readOnlyCipherId, @@ -53,16 +51,16 @@ public async Task GetCipherPermissionsForUserQuery_Base(Guid userId, CurrentCont var result = await sutProvider.Sut.GetByOrganization(organizationId); Assert.Equal(6, result.Count); - Assert.All(result, x => Assert.True(_cipherIds.Contains(x.Key))); - Assert.Equal(false, result[_noAccessCipherId].Read); - Assert.Equal(true, result[_readOnlyCipherId].Read); - Assert.Equal(false, result[_readOnlyCipherId].Edit); - Assert.Equal(true, result[_editCipherId].Edit); - Assert.Equal(true, result[_manageCipherId].Manage); - Assert.Equal(true, result[_readExceptPasswordCipherId].Read); - Assert.Equal(false, result[_readExceptPasswordCipherId].ViewPassword); - Assert.Equal(true, result[_unassignedCipherId].Unassigned); - Assert.Equal(false, result[_unassignedCipherId].Read); + Assert.All(result, x => Assert.Contains(x.Key, _cipherIds)); + Assert.False(result[_noAccessCipherId].Read); + Assert.True(result[_readOnlyCipherId].Read); + Assert.False(result[_readOnlyCipherId].Edit); + Assert.True(result[_editCipherId].Edit); + Assert.True(result[_manageCipherId].Manage); + Assert.True(result[_readExceptPasswordCipherId].Read); + Assert.False(result[_readExceptPasswordCipherId].ViewPassword); + Assert.True(result[_unassignedCipherId].Unassigned); + Assert.False(result[_unassignedCipherId].Read); } [Theory, BitAutoData] @@ -83,7 +81,7 @@ public async Task GetCipherPermissionsForUserQuery_CanEditAllCiphers_CustomUser( var result = await sutProvider.Sut.GetByOrganization(organizationId); Assert.Equal(6, result.Count); - Assert.All(result, x => Assert.True(_cipherIds.Contains(x.Key))); + Assert.All(result, x => Assert.Contains(x.Key, _cipherIds)); Assert.All(result, x => Assert.True(x.Value.Read && x.Value.Edit && x.Value.Manage && x.Value.ViewPassword)); } @@ -110,7 +108,7 @@ public async Task GetCipherPermissionsForUserQuery_CanEditAllCiphers_Admin(Guid var result = await sutProvider.Sut.GetByOrganization(organizationId); Assert.Equal(6, result.Count); - Assert.All(result, x => Assert.True(_cipherIds.Contains(x.Key))); + Assert.All(result, x => Assert.Contains(x.Key, _cipherIds)); Assert.All(result, x => Assert.True(x.Value.Read && x.Value.Edit && x.Value.Manage && x.Value.ViewPassword)); } @@ -132,20 +130,20 @@ public async Task GetCipherPermissionsForUserQuery_CanEditUnassignedCiphers(Guid var result = await sutProvider.Sut.GetByOrganization(organizationId); Assert.Equal(6, result.Count); - Assert.All(result, x => Assert.True(_cipherIds.Contains(x.Key))); - Assert.Equal(false, result[_noAccessCipherId].Read); - Assert.Equal(true, result[_readOnlyCipherId].Read); - Assert.Equal(false, result[_readOnlyCipherId].Edit); - Assert.Equal(true, result[_editCipherId].Edit); - Assert.Equal(true, result[_manageCipherId].Manage); - Assert.Equal(true, result[_readExceptPasswordCipherId].Read); - Assert.Equal(false, result[_readExceptPasswordCipherId].ViewPassword); - - Assert.Equal(true, result[_unassignedCipherId].Unassigned); - Assert.Equal(true, result[_unassignedCipherId].Read); - Assert.Equal(true, result[_unassignedCipherId].Edit); - Assert.Equal(true, result[_unassignedCipherId].ViewPassword); - Assert.Equal(true, result[_unassignedCipherId].Manage); + Assert.All(result, x => Assert.Contains(x.Key, _cipherIds)); + Assert.False(result[_noAccessCipherId].Read); + Assert.True(result[_readOnlyCipherId].Read); + Assert.False(result[_readOnlyCipherId].Edit); + Assert.True(result[_editCipherId].Edit); + Assert.True(result[_manageCipherId].Manage); + Assert.True(result[_readExceptPasswordCipherId].Read); + Assert.False(result[_readExceptPasswordCipherId].ViewPassword); + + Assert.True(result[_unassignedCipherId].Unassigned); + Assert.True(result[_unassignedCipherId].Read); + Assert.True(result[_unassignedCipherId].Edit); + Assert.True(result[_unassignedCipherId].ViewPassword); + Assert.True(result[_unassignedCipherId].Manage); } private List CreateCipherPermissions()