mirror of
https://github.com/bitwarden/server.git
synced 2025-05-31 00:00:34 -05:00
Refactor AcceptOrgUserCommandTests to remove redundant two-factor authentication checks and simplify test setup
This commit is contained in:
parent
fe5180adf5
commit
398a542528
@ -168,9 +168,6 @@ public class AcceptOrgUserCommandTests
|
|||||||
// Arrange
|
// Arrange
|
||||||
SetupCommonAcceptOrgUserMocks(sutProvider, user, org, orgUser, adminUserDetails);
|
SetupCommonAcceptOrgUserMocks(sutProvider, user, org, orgUser, adminUserDetails);
|
||||||
|
|
||||||
// User doesn't have 2FA enabled
|
|
||||||
sutProvider.GetDependency<ITwoFactorIsEnabledQuery>().TwoFactorIsEnabledAsync(user).Returns(false);
|
|
||||||
|
|
||||||
// Organization they are trying to join requires 2FA
|
// Organization they are trying to join requires 2FA
|
||||||
var twoFactorPolicy = new OrganizationUserPolicyDetails { OrganizationId = orgUser.OrganizationId };
|
var twoFactorPolicy = new OrganizationUserPolicyDetails { OrganizationId = orgUser.OrganizationId };
|
||||||
sutProvider.GetDependency<IPolicyService>()
|
sutProvider.GetDependency<IPolicyService>()
|
||||||
@ -199,11 +196,6 @@ public class AcceptOrgUserCommandTests
|
|||||||
.IsEnabled(FeatureFlagKeys.PolicyRequirements)
|
.IsEnabled(FeatureFlagKeys.PolicyRequirements)
|
||||||
.Returns(true);
|
.Returns(true);
|
||||||
|
|
||||||
// User doesn't have 2FA enabled
|
|
||||||
sutProvider.GetDependency<ITwoFactorIsEnabledQuery>()
|
|
||||||
.TwoFactorIsEnabledAsync(user)
|
|
||||||
.Returns(false);
|
|
||||||
|
|
||||||
// Organization they are trying to join requires 2FA
|
// Organization they are trying to join requires 2FA
|
||||||
sutProvider.GetDependency<IPolicyRequirementQuery>()
|
sutProvider.GetDependency<IPolicyRequirementQuery>()
|
||||||
.GetAsync<RequireTwoFactorPolicyRequirement>(user.Id)
|
.GetAsync<RequireTwoFactorPolicyRequirement>(user.Id)
|
||||||
@ -237,7 +229,9 @@ public class AcceptOrgUserCommandTests
|
|||||||
.Returns(true);
|
.Returns(true);
|
||||||
|
|
||||||
// User has 2FA enabled
|
// User has 2FA enabled
|
||||||
sutProvider.GetDependency<ITwoFactorIsEnabledQuery>().TwoFactorIsEnabledAsync(Arg.Any<User>()).Returns(true);
|
sutProvider.GetDependency<ITwoFactorIsEnabledQuery>()
|
||||||
|
.TwoFactorIsEnabledAsync(user)
|
||||||
|
.Returns(true);
|
||||||
|
|
||||||
// Organization they are trying to join requires 2FA
|
// Organization they are trying to join requires 2FA
|
||||||
sutProvider.GetDependency<IPolicyRequirementQuery>()
|
sutProvider.GetDependency<IPolicyRequirementQuery>()
|
||||||
@ -260,10 +254,9 @@ public class AcceptOrgUserCommandTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[BitAutoData(true)]
|
[BitAutoData]
|
||||||
[BitAutoData(false)]
|
|
||||||
public async Task AcceptOrgUserAsync_WithPolicyRequirementsEnabled_UserJoiningOrgWithout2FARequirement_Succeeds(
|
public async Task AcceptOrgUserAsync_WithPolicyRequirementsEnabled_UserJoiningOrgWithout2FARequirement_Succeeds(
|
||||||
bool userTwoFactorEnabled, SutProvider<AcceptOrgUserCommand> sutProvider,
|
SutProvider<AcceptOrgUserCommand> sutProvider,
|
||||||
User user, Organization org, OrganizationUser orgUser, OrganizationUserUserDetails adminUserDetails)
|
User user, Organization org, OrganizationUser orgUser, OrganizationUserUserDetails adminUserDetails)
|
||||||
{
|
{
|
||||||
SetupCommonAcceptOrgUserMocks(sutProvider, user, org, orgUser, adminUserDetails);
|
SetupCommonAcceptOrgUserMocks(sutProvider, user, org, orgUser, adminUserDetails);
|
||||||
@ -272,11 +265,6 @@ public class AcceptOrgUserCommandTests
|
|||||||
.IsEnabled(FeatureFlagKeys.PolicyRequirements)
|
.IsEnabled(FeatureFlagKeys.PolicyRequirements)
|
||||||
.Returns(true);
|
.Returns(true);
|
||||||
|
|
||||||
// User 2FA status
|
|
||||||
sutProvider.GetDependency<ITwoFactorIsEnabledQuery>()
|
|
||||||
.TwoFactorIsEnabledAsync(user)
|
|
||||||
.Returns(userTwoFactorEnabled);
|
|
||||||
|
|
||||||
// Organization they are trying to join doesn't require 2FA
|
// Organization they are trying to join doesn't require 2FA
|
||||||
sutProvider.GetDependency<IPolicyRequirementQuery>()
|
sutProvider.GetDependency<IPolicyRequirementQuery>()
|
||||||
.GetAsync<RequireTwoFactorPolicyRequirement>(user.Id)
|
.GetAsync<RequireTwoFactorPolicyRequirement>(user.Id)
|
||||||
@ -759,11 +747,6 @@ public class AcceptOrgUserCommandTests
|
|||||||
.AnyPoliciesApplicableToUserAsync(user.Id, PolicyType.SingleOrg)
|
.AnyPoliciesApplicableToUserAsync(user.Id, PolicyType.SingleOrg)
|
||||||
.Returns(false);
|
.Returns(false);
|
||||||
|
|
||||||
// User doesn't have 2FA enabled
|
|
||||||
sutProvider.GetDependency<ITwoFactorIsEnabledQuery>()
|
|
||||||
.TwoFactorIsEnabledAsync(user)
|
|
||||||
.Returns(false);
|
|
||||||
|
|
||||||
// Org does not require 2FA
|
// Org does not require 2FA
|
||||||
sutProvider.GetDependency<IPolicyService>().GetPoliciesApplicableToUserAsync(user.Id,
|
sutProvider.GetDependency<IPolicyService>().GetPoliciesApplicableToUserAsync(user.Id,
|
||||||
PolicyType.TwoFactorAuthentication, OrganizationUserStatusType.Invited)
|
PolicyType.TwoFactorAuthentication, OrganizationUserStatusType.Invited)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user