mirror of
https://github.com/bitwarden/server.git
synced 2024-12-04 14:13:28 +01:00
splitting up tests
This commit is contained in:
parent
8669e90e18
commit
d485305b20
@ -63,11 +63,8 @@ public class SingleOrgPolicyValidatorTests
|
|||||||
Assert.True(string.IsNullOrEmpty(result));
|
Assert.True(string.IsNullOrEmpty(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory, BitAutoData]
|
||||||
[BitAutoData(true)]
|
public async Task OnSaveSideEffectsAsync_RevokesNonCompliantUsers(
|
||||||
[BitAutoData(false)]
|
|
||||||
public async Task OnSaveSideEffectsAsync_RemovesNonCompliantUsers(
|
|
||||||
bool isAccountDeprovisioningEnabled,
|
|
||||||
[PolicyUpdate(PolicyType.SingleOrg)] PolicyUpdate policyUpdate,
|
[PolicyUpdate(PolicyType.SingleOrg)] PolicyUpdate policyUpdate,
|
||||||
[Policy(PolicyType.SingleOrg, false)] Policy policy,
|
[Policy(PolicyType.SingleOrg, false)] Policy policy,
|
||||||
Guid savingUserId,
|
Guid savingUserId,
|
||||||
@ -122,7 +119,7 @@ public class SingleOrgPolicyValidatorTests
|
|||||||
sutProvider.GetDependency<IOrganizationRepository>().GetByIdAsync(policyUpdate.OrganizationId).Returns(organization);
|
sutProvider.GetDependency<IOrganizationRepository>().GetByIdAsync(policyUpdate.OrganizationId).Returns(organization);
|
||||||
|
|
||||||
sutProvider.GetDependency<IFeatureService>().IsEnabled(FeatureFlagKeys.AccountDeprovisioning)
|
sutProvider.GetDependency<IFeatureService>().IsEnabled(FeatureFlagKeys.AccountDeprovisioning)
|
||||||
.Returns(isAccountDeprovisioningEnabled);
|
.Returns(true);
|
||||||
|
|
||||||
sutProvider.GetDependency<IRevokeNonCompliantOrganizationUserCommand>()
|
sutProvider.GetDependency<IRevokeNonCompliantOrganizationUserCommand>()
|
||||||
.RevokeNonCompliantOrganizationUsersAsync(Arg.Any<RevokeOrganizationUsersRequest>())
|
.RevokeNonCompliantOrganizationUsersAsync(Arg.Any<RevokeOrganizationUsersRequest>())
|
||||||
@ -130,8 +127,6 @@ public class SingleOrgPolicyValidatorTests
|
|||||||
|
|
||||||
await sutProvider.Sut.OnSaveSideEffectsAsync(policyUpdate, policy);
|
await sutProvider.Sut.OnSaveSideEffectsAsync(policyUpdate, policy);
|
||||||
|
|
||||||
if (isAccountDeprovisioningEnabled)
|
|
||||||
{
|
|
||||||
await sutProvider.GetDependency<IRevokeNonCompliantOrganizationUserCommand>()
|
await sutProvider.GetDependency<IRevokeNonCompliantOrganizationUserCommand>()
|
||||||
.Received(1)
|
.Received(1)
|
||||||
.RevokeNonCompliantOrganizationUsersAsync(Arg.Any<RevokeOrganizationUsersRequest>());
|
.RevokeNonCompliantOrganizationUsersAsync(Arg.Any<RevokeOrganizationUsersRequest>());
|
||||||
@ -140,8 +135,71 @@ public class SingleOrgPolicyValidatorTests
|
|||||||
.SendOrganizationUserRevokedForPolicySingleOrgEmailAsync(organization.DisplayName(),
|
.SendOrganizationUserRevokedForPolicySingleOrgEmailAsync(organization.DisplayName(),
|
||||||
"user3@example.com");
|
"user3@example.com");
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
[Theory, BitAutoData]
|
||||||
|
public async Task OnSaveSideEffectsAsync_RemovesNonCompliantUsers(
|
||||||
|
[PolicyUpdate(PolicyType.SingleOrg)] PolicyUpdate policyUpdate,
|
||||||
|
[Policy(PolicyType.SingleOrg, false)] Policy policy,
|
||||||
|
Guid savingUserId,
|
||||||
|
Guid nonCompliantUserId,
|
||||||
|
Organization organization, SutProvider<SingleOrgPolicyValidator> sutProvider)
|
||||||
{
|
{
|
||||||
|
policy.OrganizationId = organization.Id = policyUpdate.OrganizationId;
|
||||||
|
|
||||||
|
var compliantUser1 = new OrganizationUserUserDetails
|
||||||
|
{
|
||||||
|
OrganizationId = organization.Id,
|
||||||
|
Type = OrganizationUserType.User,
|
||||||
|
Status = OrganizationUserStatusType.Confirmed,
|
||||||
|
UserId = new Guid(),
|
||||||
|
Email = "user1@example.com"
|
||||||
|
};
|
||||||
|
|
||||||
|
var compliantUser2 = new OrganizationUserUserDetails
|
||||||
|
{
|
||||||
|
OrganizationId = organization.Id,
|
||||||
|
Type = OrganizationUserType.User,
|
||||||
|
Status = OrganizationUserStatusType.Confirmed,
|
||||||
|
UserId = new Guid(),
|
||||||
|
Email = "user2@example.com"
|
||||||
|
};
|
||||||
|
|
||||||
|
var nonCompliantUser = new OrganizationUserUserDetails
|
||||||
|
{
|
||||||
|
OrganizationId = organization.Id,
|
||||||
|
Type = OrganizationUserType.User,
|
||||||
|
Status = OrganizationUserStatusType.Confirmed,
|
||||||
|
UserId = nonCompliantUserId,
|
||||||
|
Email = "user3@example.com"
|
||||||
|
};
|
||||||
|
|
||||||
|
sutProvider.GetDependency<IOrganizationUserRepository>()
|
||||||
|
.GetManyDetailsByOrganizationAsync(policyUpdate.OrganizationId)
|
||||||
|
.Returns([compliantUser1, compliantUser2, nonCompliantUser]);
|
||||||
|
|
||||||
|
var otherOrganizationUser = new OrganizationUser
|
||||||
|
{
|
||||||
|
OrganizationId = new Guid(),
|
||||||
|
UserId = nonCompliantUserId,
|
||||||
|
Status = OrganizationUserStatusType.Confirmed
|
||||||
|
};
|
||||||
|
|
||||||
|
sutProvider.GetDependency<IOrganizationUserRepository>()
|
||||||
|
.GetManyByManyUsersAsync(Arg.Is<IEnumerable<Guid>>(ids => ids.Contains(nonCompliantUserId)))
|
||||||
|
.Returns([otherOrganizationUser]);
|
||||||
|
|
||||||
|
sutProvider.GetDependency<ICurrentContext>().UserId.Returns(savingUserId);
|
||||||
|
sutProvider.GetDependency<IOrganizationRepository>().GetByIdAsync(policyUpdate.OrganizationId).Returns(organization);
|
||||||
|
|
||||||
|
sutProvider.GetDependency<IFeatureService>().IsEnabled(FeatureFlagKeys.AccountDeprovisioning)
|
||||||
|
.Returns(false);
|
||||||
|
|
||||||
|
sutProvider.GetDependency<IRevokeNonCompliantOrganizationUserCommand>()
|
||||||
|
.RevokeNonCompliantOrganizationUsersAsync(Arg.Any<RevokeOrganizationUsersRequest>())
|
||||||
|
.Returns(new CommandResult());
|
||||||
|
|
||||||
|
await sutProvider.Sut.OnSaveSideEffectsAsync(policyUpdate, policy);
|
||||||
|
|
||||||
await sutProvider.GetDependency<IRemoveOrganizationUserCommand>()
|
await sutProvider.GetDependency<IRemoveOrganizationUserCommand>()
|
||||||
.Received(1)
|
.Received(1)
|
||||||
.RemoveUserAsync(policyUpdate.OrganizationId, nonCompliantUser.Id, savingUserId);
|
.RemoveUserAsync(policyUpdate.OrganizationId, nonCompliantUser.Id, savingUserId);
|
||||||
@ -151,8 +209,6 @@ public class SingleOrgPolicyValidatorTests
|
|||||||
"user3@example.com");
|
"user3@example.com");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
[Theory, BitAutoData]
|
||||||
public async Task OnSaveSideEffectsAsync_WhenAccountDeprovisioningIsEnabled_ThenUsersAreRevoked(
|
public async Task OnSaveSideEffectsAsync_WhenAccountDeprovisioningIsEnabled_ThenUsersAreRevoked(
|
||||||
[PolicyUpdate(PolicyType.SingleOrg)] PolicyUpdate policyUpdate,
|
[PolicyUpdate(PolicyType.SingleOrg)] PolicyUpdate policyUpdate,
|
||||||
|
Loading…
Reference in New Issue
Block a user