|
|
|
|
@ -11,6 +11,7 @@ using Bit.Core.Billing.Enums;
@@ -11,6 +11,7 @@ using Bit.Core.Billing.Enums;
|
|
|
|
|
using Bit.Core.Billing.Providers.Services; |
|
|
|
|
using Bit.Core.Enums; |
|
|
|
|
using Bit.Core.Repositories; |
|
|
|
|
using Bit.Core.Services; |
|
|
|
|
using Bit.Test.Common.AutoFixture; |
|
|
|
|
using Bit.Test.Common.AutoFixture.Attributes; |
|
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
|
|
@ -464,5 +465,109 @@ public class OrganizationsControllerTests
@@ -464,5 +465,109 @@ public class OrganizationsControllerTests
|
|
|
|
|
.IsOrganizationCompliantAsync(Arg.Any<AutomaticUserConfirmationOrganizationPolicyComplianceValidatorRequest>()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[BitAutoData] |
|
|
|
|
[SutProviderCustomize] |
|
|
|
|
[Theory] |
|
|
|
|
public async Task Edit_UseAutomaticUserConfirmation_EnabledByPortal_LogsEvent( |
|
|
|
|
Organization organization, |
|
|
|
|
SutProvider<OrganizationsController> sutProvider) |
|
|
|
|
{ |
|
|
|
|
var update = new OrganizationEditModel |
|
|
|
|
{ |
|
|
|
|
PlanType = PlanType.TeamsMonthly, |
|
|
|
|
UseAutomaticUserConfirmation = true |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
organization.UseAutomaticUserConfirmation = false; |
|
|
|
|
organization.Enabled = true; |
|
|
|
|
organization.UseEvents = true; |
|
|
|
|
|
|
|
|
|
sutProvider.GetDependency<IAccessControlService>() |
|
|
|
|
.UserHasPermission(Permission.Org_Plan_Edit) |
|
|
|
|
.Returns(true); |
|
|
|
|
|
|
|
|
|
var organizationRepository = sutProvider.GetDependency<IOrganizationRepository>(); |
|
|
|
|
organizationRepository.GetByIdAsync(organization.Id).Returns(organization); |
|
|
|
|
|
|
|
|
|
var request = new AutomaticUserConfirmationOrganizationPolicyComplianceValidatorRequest(organization.Id); |
|
|
|
|
sutProvider.GetDependency<IAutomaticUserConfirmationOrganizationPolicyComplianceValidator>() |
|
|
|
|
.IsOrganizationCompliantAsync(Arg.Any<AutomaticUserConfirmationOrganizationPolicyComplianceValidatorRequest>()) |
|
|
|
|
.Returns(Valid(request)); |
|
|
|
|
|
|
|
|
|
_ = await sutProvider.Sut.Edit(organization.Id, update); |
|
|
|
|
|
|
|
|
|
await sutProvider.GetDependency<IEventService>().Received(1) |
|
|
|
|
.LogOrganizationEventAsync( |
|
|
|
|
Arg.Is<Organization>(o => o.Id == organization.Id), |
|
|
|
|
EventType.Organization_AutoConfirmEnabled_Portal, |
|
|
|
|
EventSystemUser.BitwardenPortal); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[BitAutoData] |
|
|
|
|
[SutProviderCustomize] |
|
|
|
|
[Theory] |
|
|
|
|
public async Task Edit_UseAutomaticUserConfirmation_DisabledByPortal_LogsEvent( |
|
|
|
|
Organization organization, |
|
|
|
|
SutProvider<OrganizationsController> sutProvider) |
|
|
|
|
{ |
|
|
|
|
var update = new OrganizationEditModel |
|
|
|
|
{ |
|
|
|
|
PlanType = PlanType.TeamsMonthly, |
|
|
|
|
UseAutomaticUserConfirmation = false |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
organization.UseAutomaticUserConfirmation = true; |
|
|
|
|
organization.Enabled = true; |
|
|
|
|
organization.UseEvents = true; |
|
|
|
|
|
|
|
|
|
sutProvider.GetDependency<IAccessControlService>() |
|
|
|
|
.UserHasPermission(Permission.Org_Plan_Edit) |
|
|
|
|
.Returns(true); |
|
|
|
|
|
|
|
|
|
var organizationRepository = sutProvider.GetDependency<IOrganizationRepository>(); |
|
|
|
|
organizationRepository.GetByIdAsync(organization.Id).Returns(organization); |
|
|
|
|
|
|
|
|
|
_ = await sutProvider.Sut.Edit(organization.Id, update); |
|
|
|
|
|
|
|
|
|
await sutProvider.GetDependency<IEventService>().Received(1) |
|
|
|
|
.LogOrganizationEventAsync( |
|
|
|
|
Arg.Is<Organization>(o => o.Id == organization.Id), |
|
|
|
|
EventType.Organization_AutoConfirmDisabled_Portal, |
|
|
|
|
EventSystemUser.BitwardenPortal); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[BitAutoData] |
|
|
|
|
[SutProviderCustomize] |
|
|
|
|
[Theory] |
|
|
|
|
public async Task Edit_UseAutomaticUserConfirmation_NoChange_DoesNotLogEvent( |
|
|
|
|
Organization organization, |
|
|
|
|
SutProvider<OrganizationsController> sutProvider) |
|
|
|
|
{ |
|
|
|
|
var update = new OrganizationEditModel |
|
|
|
|
{ |
|
|
|
|
PlanType = PlanType.TeamsMonthly, |
|
|
|
|
UseAutomaticUserConfirmation = true |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
organization.UseAutomaticUserConfirmation = true; |
|
|
|
|
organization.Enabled = true; |
|
|
|
|
organization.UseEvents = true; |
|
|
|
|
|
|
|
|
|
sutProvider.GetDependency<IAccessControlService>() |
|
|
|
|
.UserHasPermission(Permission.Org_Plan_Edit) |
|
|
|
|
.Returns(true); |
|
|
|
|
|
|
|
|
|
var organizationRepository = sutProvider.GetDependency<IOrganizationRepository>(); |
|
|
|
|
organizationRepository.GetByIdAsync(organization.Id).Returns(organization); |
|
|
|
|
|
|
|
|
|
_ = await sutProvider.Sut.Edit(organization.Id, update); |
|
|
|
|
|
|
|
|
|
await sutProvider.GetDependency<IEventService>().DidNotReceive() |
|
|
|
|
.LogOrganizationEventAsync( |
|
|
|
|
Arg.Any<Organization>(), |
|
|
|
|
Arg.Any<EventType>(), |
|
|
|
|
Arg.Any<EventSystemUser>()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endregion |
|
|
|
|
} |
|
|
|
|
|