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

@@ -743,4 +743,80 @@ public class CollectControllerTests
Arg.Is<IEnumerable<Tuple<Cipher, EventType, DateTime?>>>(tuples => tuples.Count() == 50)
);
}
[Theory]
[BitAutoData(EventType.Organization_AutoConfirmEnabled_Admin)]
[BitAutoData(EventType.Organization_AutoConfirmDisabled_Admin)]
public async Task Post_OrganizationAutoConfirmAdmin_WithValidOrg_LogsOrgEvent(
EventType eventType, Guid userId, Guid orgId, Organization organization)
{
_currentContext.UserId.Returns(userId);
organization.Id = orgId;
_organizationRepository.GetByIdAsync(orgId).Returns(organization);
var eventDate = DateTime.UtcNow;
var events = new List<EventModel>
{
new EventModel
{
Type = eventType,
OrganizationId = orgId,
Date = eventDate
}
};
var result = await _sut.Post(events);
Assert.IsType<OkResult>(result);
await _organizationRepository.Received(1).GetByIdAsync(orgId);
await _eventService.Received(1).LogOrganizationEventAsync(organization, eventType, eventDate);
}
[Theory]
[BitAutoData(EventType.Organization_AutoConfirmEnabled_Admin)]
[BitAutoData(EventType.Organization_AutoConfirmDisabled_Admin)]
public async Task Post_OrganizationAutoConfirmAdmin_WithoutOrgId_SkipsEvent(
EventType eventType, Guid userId)
{
_currentContext.UserId.Returns(userId);
var events = new List<EventModel>
{
new EventModel
{
Type = eventType,
OrganizationId = null,
Date = DateTime.UtcNow
}
};
var result = await _sut.Post(events);
Assert.IsType<OkResult>(result);
await _organizationRepository.DidNotReceiveWithAnyArgs().GetByIdAsync(default);
await _eventService.DidNotReceiveWithAnyArgs().LogOrganizationEventAsync(default, default, default);
}
[Theory]
[BitAutoData(EventType.Organization_AutoConfirmEnabled_Admin)]
[BitAutoData(EventType.Organization_AutoConfirmDisabled_Admin)]
public async Task Post_OrganizationAutoConfirmAdmin_WithNullOrg_SkipsEvent(
EventType eventType, Guid userId, Guid orgId)
{
_currentContext.UserId.Returns(userId);
_organizationRepository.GetByIdAsync(orgId).Returns((Organization)null);
var events = new List<EventModel>
{
new EventModel
{
Type = eventType,
OrganizationId = orgId,
Date = DateTime.UtcNow
}
};
var result = await _sut.Post(events);
Assert.IsType<OkResult>(result);
await _organizationRepository.Received(1).GetByIdAsync(orgId);
await _eventService.DidNotReceiveWithAnyArgs().LogOrganizationEventAsync(default, default, default);
}
}