1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-02 00:22:50 -05:00

[AC-1139] Fixed CollectionAuthorizationHandler unit tests

This commit is contained in:
Rui Tome
2023-10-25 21:05:54 +01:00
parent 18592e4f0a
commit 57d3abb994

View File

@ -17,30 +17,26 @@ namespace Bit.Api.Test.Vault.AuthorizationHandlers;
public class CollectionAuthorizationHandlerTests public class CollectionAuthorizationHandlerTests
{ {
[Theory] [Theory]
[BitAutoData(OrganizationUserType.User, false, true)] [BitAutoData(OrganizationUserType.Admin, false, false, false, false, false, true)]
[BitAutoData(OrganizationUserType.Admin, false, false)] [BitAutoData(OrganizationUserType.Owner, false, false, false, false, false, true)]
[BitAutoData(OrganizationUserType.Owner, false, false)] [BitAutoData(OrganizationUserType.User, false, false, false, false, false, false)]
[BitAutoData(OrganizationUserType.Custom, true, false)] [BitAutoData(OrganizationUserType.Custom, true, false, false, false, false, true)]
[BitAutoData(OrganizationUserType.Owner, true, true)] [BitAutoData(OrganizationUserType.Custom, false, true, false, false, false, true)]
public async Task CanReadAllAccessAsync_Success( [BitAutoData(OrganizationUserType.Custom, false, false, true, false, false, true)]
[BitAutoData(OrganizationUserType.Custom, false, false, false, true, false, true)]
[BitAutoData(OrganizationUserType.Custom, false, false, false, false, true, true)]
public async Task CanReadAllAccessAsync_ReturnsExpectedResult(
OrganizationUserType userType, bool editAnyCollection, bool deleteAnyCollection, OrganizationUserType userType, bool editAnyCollection, bool deleteAnyCollection,
bool manageGroups, bool manageUsers, bool accessImportExport, bool expectedSuccess,
Guid userId, SutProvider<CollectionAuthorizationHandler> sutProvider, Guid userId, SutProvider<CollectionAuthorizationHandler> sutProvider,
CurrentContextOrganization organization) CurrentContextOrganization organization)
{ {
// if (org.Type is OrganizationUserType.Owner or OrganizationUserType.Admin ||
// org.Permissions.ManageGroups ||
// org.Permissions.ManageUsers ||
// org.Permissions.EditAnyCollection ||
// org.Permissions.DeleteAnyCollection ||
// org.Permissions.AccessImportExport ||
// await _currentContext.ProviderUserForOrgAsync(org.Id))
// {
// context.Succeed(requirement);
// }
organization.Type = userType; organization.Type = userType;
organization.Permissions.EditAnyCollection = editAnyCollection; organization.Permissions.EditAnyCollection = editAnyCollection;
organization.Permissions.DeleteAnyCollection = deleteAnyCollection; organization.Permissions.DeleteAnyCollection = deleteAnyCollection;
organization.Permissions.ManageGroups = manageGroups;
organization.Permissions.ManageUsers = manageUsers;
organization.Permissions.AccessImportExport = accessImportExport;
var context = new AuthorizationHandlerContext( var context = new AuthorizationHandlerContext(
new[] { CollectionOperations.ReadAll(organization.Id) }, new[] { CollectionOperations.ReadAll(organization.Id) },
@ -52,7 +48,7 @@ public class CollectionAuthorizationHandlerTests
await sutProvider.Sut.HandleAsync(context); await sutProvider.Sut.HandleAsync(context);
Assert.True(context.HasSucceeded); Assert.True(expectedSuccess ? context.HasSucceeded : context.HasFailed);
} }
[Theory, BitAutoData] [Theory, BitAutoData]