mirror of
https://github.com/bitwarden/server.git
synced 2024-11-25 12:45:18 +01:00
3289a8c35e
* Move Api files * Move Core files * Move Infrastructure files * Move Sql Files * Move Api Sync files to Vault * Move test vault files * Update Sql.sqlproj paths * Update Codeowners * Fix vault file paths in sqlproj * Update CipherDetails.sql path in sqlproj * Update Core models and entities namespaces * Update namespaces Core Services and Repositories * Missed service namespaces * Update Api namespaces * Update Infrastructure namespaces * Move infrastructure queries that were missed * Tests namespace updates * Admin and Events namespace updates * Remove unused usings * Remove extra CiphersController usings * Rename folder * Fix CipherDetails namespace * Sqlproj fixes * Move stored procs into folders by table * using order fix
101 lines
3.1 KiB
C#
101 lines
3.1 KiB
C#
using Bit.Core.Entities;
|
|
using Bit.Core.Enums;
|
|
using Bit.Core.Repositories;
|
|
using Bit.Core.Vault.Entities;
|
|
using Bit.Core.Vault.Enums;
|
|
using Bit.Core.Vault.Models.Data;
|
|
using Bit.Core.Vault.Repositories;
|
|
using Xunit;
|
|
|
|
namespace Bit.Infrastructure.IntegrationTest.Repositories;
|
|
|
|
public class CipherRepositoryTests
|
|
{
|
|
[DatabaseTheory, DatabaseData]
|
|
public async Task DeleteAsync_UpdatesUserRevisionDate(
|
|
IUserRepository userRepository,
|
|
ICipherRepository cipherRepository,
|
|
ITestDatabaseHelper helper)
|
|
{
|
|
var user = await userRepository.CreateAsync(new User
|
|
{
|
|
Name = "Test User",
|
|
Email = "test@email.com",
|
|
ApiKey = "TEST",
|
|
SecurityStamp = "stamp",
|
|
});
|
|
|
|
var cipher = await cipherRepository.CreateAsync(new Cipher
|
|
{
|
|
Type = CipherType.Login,
|
|
UserId = user.Id,
|
|
});
|
|
|
|
helper.ClearTracker();
|
|
|
|
await cipherRepository.DeleteAsync(cipher);
|
|
|
|
var deletedCipher = await cipherRepository.GetByIdAsync(cipher.Id);
|
|
|
|
Assert.Null(deletedCipher);
|
|
var updatedUser = await userRepository.GetByIdAsync(user.Id);
|
|
Assert.NotEqual(updatedUser.AccountRevisionDate, user.AccountRevisionDate);
|
|
}
|
|
|
|
[DatabaseTheory, DatabaseData]
|
|
public async Task CreateAsync_UpdateWithCollecitons_Works(
|
|
IUserRepository userRepository,
|
|
IOrganizationRepository organizationRepository,
|
|
IOrganizationUserRepository organizationUserRepository,
|
|
ICollectionRepository collectionRepository,
|
|
ICipherRepository cipherRepository,
|
|
ICollectionCipherRepository collectionCipherRepository,
|
|
ITestDatabaseHelper helper)
|
|
{
|
|
var user = await userRepository.CreateAsync(new User
|
|
{
|
|
Name = "Test User",
|
|
Email = "test@email.com",
|
|
ApiKey = "TEST",
|
|
SecurityStamp = "stamp",
|
|
});
|
|
|
|
var organization = await organizationRepository.CreateAsync(new Organization
|
|
{
|
|
Name = "Test Organization",
|
|
});
|
|
|
|
await organizationUserRepository.CreateAsync(new OrganizationUser
|
|
{
|
|
UserId = user.Id,
|
|
OrganizationId = organization.Id,
|
|
Status = OrganizationUserStatusType.Accepted,
|
|
Type = OrganizationUserType.Owner,
|
|
});
|
|
|
|
var collection = await collectionRepository.CreateAsync(new Collection
|
|
{
|
|
Name = "Test Collection",
|
|
OrganizationId = organization.Id
|
|
});
|
|
|
|
helper.ClearTracker();
|
|
|
|
await cipherRepository.CreateAsync(new CipherDetails
|
|
{
|
|
Type = CipherType.Login,
|
|
OrganizationId = organization.Id,
|
|
}, new List<Guid>
|
|
{
|
|
collection.Id,
|
|
});
|
|
|
|
var updatedUser = await userRepository.GetByIdAsync(user.Id);
|
|
|
|
Assert.NotEqual(updatedUser.AccountRevisionDate, user.AccountRevisionDate);
|
|
|
|
var collectionCiphers = await collectionCipherRepository.GetManyByOrganizationIdAsync(organization.Id);
|
|
Assert.NotEmpty(collectionCiphers);
|
|
}
|
|
}
|