mirror of
https://github.com/bitwarden/server.git
synced 2024-12-11 15:17:44 +01:00
eee7494c91
* [PM-14373] Introduce SecurityTask entity and related enums * [PM-14373] Add Dapper SecurityTask repository * [PM-14373] Introduce MSSQL table, view, and stored procedures * [PM-14373] Add EF SecurityTask repository and type configurations * [PM-14373] Add EF Migration * [PM-14373] Add integration tests * [PM-14373] Formatting * Typo Co-authored-by: Matt Bishop <mbishop@bitwarden.com> * Typo Co-authored-by: Matt Bishop <mbishop@bitwarden.com> * [PM-14373] Remove DeleteById sproc * [PM-14373] SQL formatting --------- Co-authored-by: Matt Bishop <mbishop@bitwarden.com>
124 lines
3.9 KiB
C#
124 lines
3.9 KiB
C#
using Bit.Core.AdminConsole.Entities;
|
|
using Bit.Core.Billing.Enums;
|
|
using Bit.Core.Repositories;
|
|
using Bit.Core.Vault.Entities;
|
|
using Bit.Core.Vault.Enums;
|
|
using Bit.Core.Vault.Repositories;
|
|
using Xunit;
|
|
|
|
namespace Bit.Infrastructure.IntegrationTest.Vault.Repositories;
|
|
|
|
public class SecurityTaskRepositoryTests
|
|
{
|
|
[DatabaseTheory, DatabaseData]
|
|
public async Task CreateAsync(
|
|
IOrganizationRepository organizationRepository,
|
|
ICipherRepository cipherRepository,
|
|
ISecurityTaskRepository securityTaskRepository)
|
|
{
|
|
var organization = await organizationRepository.CreateAsync(new Organization
|
|
{
|
|
Name = "Test Org",
|
|
PlanType = PlanType.EnterpriseAnnually,
|
|
Plan = "Test Plan",
|
|
BillingEmail = "billing@email.com"
|
|
});
|
|
|
|
var cipher = await cipherRepository.CreateAsync(new Cipher
|
|
{
|
|
Type = CipherType.Login,
|
|
OrganizationId = organization.Id,
|
|
Data = "",
|
|
});
|
|
|
|
var task = await securityTaskRepository.CreateAsync(new SecurityTask
|
|
{
|
|
OrganizationId = organization.Id,
|
|
CipherId = cipher.Id,
|
|
Status = SecurityTaskStatus.Pending,
|
|
Type = SecurityTaskType.UpdateAtRiskCredential,
|
|
});
|
|
|
|
Assert.NotNull(task);
|
|
}
|
|
|
|
[DatabaseTheory, DatabaseData]
|
|
public async Task ReadByIdAsync(
|
|
IOrganizationRepository organizationRepository,
|
|
ICipherRepository cipherRepository,
|
|
ISecurityTaskRepository securityTaskRepository)
|
|
{
|
|
var organization = await organizationRepository.CreateAsync(new Organization
|
|
{
|
|
Name = "Test Org",
|
|
PlanType = PlanType.EnterpriseAnnually,
|
|
Plan = "Test Plan",
|
|
BillingEmail = "billing@email.com"
|
|
});
|
|
|
|
var cipher = await cipherRepository.CreateAsync(new Cipher
|
|
{
|
|
Type = CipherType.Login,
|
|
OrganizationId = organization.Id,
|
|
Data = "",
|
|
});
|
|
|
|
var task = await securityTaskRepository.CreateAsync(new SecurityTask
|
|
{
|
|
OrganizationId = organization.Id,
|
|
CipherId = cipher.Id,
|
|
Status = SecurityTaskStatus.Pending,
|
|
Type = SecurityTaskType.UpdateAtRiskCredential,
|
|
});
|
|
|
|
Assert.NotNull(task);
|
|
|
|
var readTask = await securityTaskRepository.GetByIdAsync(task.Id);
|
|
|
|
Assert.NotNull(readTask);
|
|
Assert.Equal(task.Id, readTask.Id);
|
|
Assert.Equal(task.Status, readTask.Status);
|
|
}
|
|
|
|
[DatabaseTheory, DatabaseData]
|
|
public async Task UpdateAsync(
|
|
IOrganizationRepository organizationRepository,
|
|
ICipherRepository cipherRepository,
|
|
ISecurityTaskRepository securityTaskRepository)
|
|
{
|
|
var organization = await organizationRepository.CreateAsync(new Organization
|
|
{
|
|
Name = "Test Org",
|
|
PlanType = PlanType.EnterpriseAnnually,
|
|
Plan = "Test Plan",
|
|
BillingEmail = "billing@email.com"
|
|
});
|
|
|
|
var cipher = await cipherRepository.CreateAsync(new Cipher
|
|
{
|
|
Type = CipherType.Login,
|
|
OrganizationId = organization.Id,
|
|
Data = "",
|
|
});
|
|
|
|
var task = await securityTaskRepository.CreateAsync(new SecurityTask
|
|
{
|
|
OrganizationId = organization.Id,
|
|
CipherId = cipher.Id,
|
|
Status = SecurityTaskStatus.Pending,
|
|
Type = SecurityTaskType.UpdateAtRiskCredential,
|
|
});
|
|
|
|
Assert.NotNull(task);
|
|
|
|
task.Status = SecurityTaskStatus.Completed;
|
|
await securityTaskRepository.ReplaceAsync(task);
|
|
|
|
var updatedTask = await securityTaskRepository.GetByIdAsync(task.Id);
|
|
|
|
Assert.NotNull(updatedTask);
|
|
Assert.Equal(task.Id, updatedTask.Id);
|
|
Assert.Equal(SecurityTaskStatus.Completed, updatedTask.Status);
|
|
}
|
|
}
|