1
0
mirror of https://github.com/bitwarden/server synced 2026-02-20 11:23:37 +00:00

[PM-26378] Auto confirm events (#7017)

* implement auto confirm push notification

* fix test

* fix test

* simplify LINQ

* add event logging for auto confirm

* fix test
This commit is contained in:
Brandon Treston
2026-02-19 12:10:28 -05:00
committed by GitHub
parent 71a8116d4c
commit 31fe7b0e12
10 changed files with 246 additions and 0 deletions

View File

@@ -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
.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
}