2023-04-14 19:25:56 +02:00
|
|
|
|
using Bit.Core.Auth.Entities;
|
|
|
|
|
using Bit.Core.Auth.Enums;
|
|
|
|
|
using Bit.Core.Entities;
|
2022-12-02 20:24:30 +01:00
|
|
|
|
using Bit.Core.Repositories;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
2023-04-14 19:25:56 +02:00
|
|
|
|
namespace Bit.Infrastructure.IntegrationTest.Auth.Repositories;
|
2022-12-02 20:24:30 +01:00
|
|
|
|
|
|
|
|
|
public class EmergencyAccessRepositoriesTests
|
|
|
|
|
{
|
|
|
|
|
[DatabaseTheory, DatabaseData]
|
|
|
|
|
public async Task DeleteAsync_UpdatesRevisionDate(IUserRepository userRepository,
|
2023-10-12 11:15:02 +02:00
|
|
|
|
IEmergencyAccessRepository emergencyAccessRepository)
|
2022-12-02 20:24:30 +01:00
|
|
|
|
{
|
|
|
|
|
var grantorUser = await userRepository.CreateAsync(new User
|
|
|
|
|
{
|
|
|
|
|
Name = "Test Grantor User",
|
2023-05-30 19:25:55 +02:00
|
|
|
|
Email = $"test+grantor{Guid.NewGuid()}@email.com",
|
2022-12-02 20:24:30 +01:00
|
|
|
|
ApiKey = "TEST",
|
|
|
|
|
SecurityStamp = "stamp",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var granteeUser = await userRepository.CreateAsync(new User
|
|
|
|
|
{
|
|
|
|
|
Name = "Test Grantee User",
|
2023-05-30 19:25:55 +02:00
|
|
|
|
Email = $"test+grantee{Guid.NewGuid()}@email.com",
|
2022-12-02 20:24:30 +01:00
|
|
|
|
ApiKey = "TEST",
|
|
|
|
|
SecurityStamp = "stamp",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var emergencyAccess = await emergencyAccessRepository.CreateAsync(new EmergencyAccess
|
|
|
|
|
{
|
|
|
|
|
GrantorId = grantorUser.Id,
|
|
|
|
|
GranteeId = granteeUser.Id,
|
|
|
|
|
Status = EmergencyAccessStatusType.Confirmed,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await emergencyAccessRepository.DeleteAsync(emergencyAccess);
|
|
|
|
|
|
|
|
|
|
var updatedGrantee = await userRepository.GetByIdAsync(granteeUser.Id);
|
|
|
|
|
|
|
|
|
|
Assert.NotEqual(updatedGrantee.AccountRevisionDate, granteeUser.AccountRevisionDate);
|
|
|
|
|
}
|
|
|
|
|
}
|