1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-25 12:45:18 +01:00

Actually correcting the test and logic.

This commit is contained in:
jrmccannon 2024-11-13 16:18:52 -06:00
parent 95bb1f4167
commit eb693a8be0
No known key found for this signature in database
GPG Key ID: CF03F3DB01CE96A6
2 changed files with 6 additions and 9 deletions

View File

@ -90,7 +90,7 @@ public class RevokeNonCompliantOrganizationUserCommand(IOrganizationUserReposito
return result;
}
if (IsNonOwnerRevokingAnOwner(userToRevoke, request.ActionPerformedBy))
if (NonOwnersCannotRevokeOwners(userToRevoke, request.ActionPerformedBy))
{
result.ErrorMessages.Add($"{OnlyOwnersCanRevokeOtherOwners}");
return result;
@ -105,13 +105,9 @@ public class RevokeNonCompliantOrganizationUserCommand(IOrganizationUserReposito
private static bool IsAlreadyRevoked(OrganizationUserUserDetails organizationUser) =>
organizationUser is { Status: OrganizationUserStatusType.Revoked };
private static bool IsNonOwnerRevokingAnOwner(OrganizationUserUserDetails organizationUser,
IActingUser requestingUser) => requestingUser is StandardUser standardUser &&
!IsActingUserAllowedToRevokeOwner(organizationUser, standardUser) &&
!IsActingUserRevokingNonOwner(organizationUser);
private static bool IsActingUserRevokingNonOwner(OrganizationUserUserDetails organizationUser) =>
organizationUser is not { Type: OrganizationUserType.Owner };
private static bool NonOwnersCannotRevokeOwners(OrganizationUserUserDetails organizationUser,
IActingUser actingUser) =>
actingUser is StandardUser { IsOrganizationOwner: false } && organizationUser.Type == OrganizationUserType.Owner;
private static bool IsActingUserAllowedToRevokeOwner(OrganizationUserUserDetails organizationUser,
StandardUser requestingOrganizationUser) => organizationUser is { Type: OrganizationUserType.Owner }

View File

@ -148,9 +148,10 @@ public class RevokeNonCompliantOrganizationUserCommandTests
SutProvider<RevokeNonCompliantOrganizationUserCommand> sutProvider)
{
userToRevoke.OrganizationId = organizationId;
userToRevoke.Type = OrganizationUserType.Admin;
var command = new RevokeOrganizationUsers(organizationId, userToRevoke,
new StandardUser(Guid.NewGuid(), true));
new StandardUser(Guid.NewGuid(), false));
sutProvider.GetDependency<IHasConfirmedOwnersExceptQuery>()
.HasConfirmedOwnersExceptAsync(organizationId, Arg.Any<IEnumerable<Guid>>())