mirror of
https://github.com/bitwarden/server.git
synced 2025-05-25 21:34:52 -05:00
Add tests with no access
This commit is contained in:
parent
eac9f13100
commit
ad7ce2abf4
@ -9,7 +9,7 @@ namespace Bit.Infrastructure.IntegrationTest.AdminConsole.Repositories.Collectio
|
|||||||
public class CollectionRepositoryCreateTests
|
public class CollectionRepositoryCreateTests
|
||||||
{
|
{
|
||||||
[DatabaseTheory, DatabaseData]
|
[DatabaseTheory, DatabaseData]
|
||||||
public async Task CreateAsync_Works(
|
public async Task CreateAsync_WithAccess_Works(
|
||||||
IUserRepository userRepository,
|
IUserRepository userRepository,
|
||||||
IOrganizationRepository organizationRepository,
|
IOrganizationRepository organizationRepository,
|
||||||
IOrganizationUserRepository organizationUserRepository,
|
IOrganizationUserRepository organizationUserRepository,
|
||||||
@ -70,5 +70,36 @@ public class CollectionRepositoryCreateTests
|
|||||||
await organizationUserRepository.DeleteManyAsync([orgUser1.Id, orgUser2.Id]);
|
await organizationUserRepository.DeleteManyAsync([orgUser1.Id, orgUser2.Id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: creating with no access to make sure we handle empty sets
|
/// <remarks>
|
||||||
|
/// Makes sure that the sproc handles empty sets.
|
||||||
|
/// </remarks>
|
||||||
|
[DatabaseTheory, DatabaseData]
|
||||||
|
public async Task CreateAsync_WithNoAccess_Works(
|
||||||
|
IOrganizationRepository organizationRepository,
|
||||||
|
ICollectionRepository collectionRepository)
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var organization = await organizationRepository.CreateTestOrganizationAsync();
|
||||||
|
|
||||||
|
var collection = new Collection
|
||||||
|
{
|
||||||
|
Name = "Test Collection Name",
|
||||||
|
OrganizationId = organization.Id,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await collectionRepository.CreateAsync(collection, [], []);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
var (actualCollection, actualAccess) = await collectionRepository.GetByIdWithAccessAsync(collection.Id);
|
||||||
|
|
||||||
|
Assert.NotNull(actualCollection);
|
||||||
|
Assert.Equal("Test Collection Name", actualCollection.Name);
|
||||||
|
|
||||||
|
Assert.Empty(actualAccess.Groups);
|
||||||
|
Assert.Empty(actualAccess.Users);
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
await organizationRepository.DeleteAsync(organization);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ namespace Bit.Infrastructure.IntegrationTest.AdminConsole.Repositories.Collectio
|
|||||||
public class CollectionRepositoryReplaceTests
|
public class CollectionRepositoryReplaceTests
|
||||||
{
|
{
|
||||||
[DatabaseTheory, DatabaseData]
|
[DatabaseTheory, DatabaseData]
|
||||||
public async Task ReplaceAsync_Works(
|
public async Task ReplaceAsync_WithAccess_Works(
|
||||||
IUserRepository userRepository,
|
IUserRepository userRepository,
|
||||||
IOrganizationRepository organizationRepository,
|
IOrganizationRepository organizationRepository,
|
||||||
IOrganizationUserRepository organizationUserRepository,
|
IOrganizationUserRepository organizationUserRepository,
|
||||||
@ -90,9 +90,57 @@ public class CollectionRepositoryReplaceTests
|
|||||||
// TODO: why doesn't delete many work?
|
// TODO: why doesn't delete many work?
|
||||||
await userRepository.DeleteManyAsync([user1, user2, user3]);
|
await userRepository.DeleteManyAsync([user1, user2, user3]);
|
||||||
await organizationRepository.DeleteAsync(organization);
|
await organizationRepository.DeleteAsync(organization);
|
||||||
await groupRepository.DeleteManyAsync([group1.Id, group2.Id, group3.Id]);
|
|
||||||
await organizationUserRepository.DeleteManyAsync([orgUser1.Id, orgUser2.Id, orgUser3.Id]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: replacing with an empty list of access to make sure we handle empty sets
|
/// <remarks>
|
||||||
|
/// Makes sure that the sproc handles empty sets.
|
||||||
|
/// </remarks>
|
||||||
|
[DatabaseTheory, DatabaseData]
|
||||||
|
public async Task ReplaceAsync_WithNoAccess_Works(
|
||||||
|
IUserRepository userRepository,
|
||||||
|
IOrganizationRepository organizationRepository,
|
||||||
|
IOrganizationUserRepository organizationUserRepository,
|
||||||
|
IGroupRepository groupRepository,
|
||||||
|
ICollectionRepository collectionRepository)
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var organization = await organizationRepository.CreateTestOrganizationAsync();
|
||||||
|
|
||||||
|
var user = await userRepository.CreateTestUserAsync();
|
||||||
|
var orgUser = await organizationUserRepository.CreateTestOrganizationUserAsync(organization, user);
|
||||||
|
|
||||||
|
var group = await groupRepository.CreateTestGroupAsync(organization);
|
||||||
|
|
||||||
|
var collection = new Collection
|
||||||
|
{
|
||||||
|
Name = "Test Collection Name",
|
||||||
|
OrganizationId = organization.Id,
|
||||||
|
};
|
||||||
|
|
||||||
|
await collectionRepository.CreateAsync(collection,
|
||||||
|
[
|
||||||
|
new CollectionAccessSelection { Id = group.Id, Manage = true, HidePasswords = false, ReadOnly = true },
|
||||||
|
],
|
||||||
|
[
|
||||||
|
new CollectionAccessSelection { Id = orgUser.Id, Manage = true, HidePasswords = false, ReadOnly = true },
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
collection.Name = "Updated Collection Name";
|
||||||
|
|
||||||
|
await collectionRepository.ReplaceAsync(collection, [], []);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
var (actualCollection, actualAccess) = await collectionRepository.GetByIdWithAccessAsync(collection.Id);
|
||||||
|
|
||||||
|
Assert.NotNull(actualCollection);
|
||||||
|
Assert.Equal("Updated Collection Name", actualCollection.Name);
|
||||||
|
|
||||||
|
Assert.Empty(actualAccess.Groups);
|
||||||
|
Assert.Empty(actualAccess.Users);
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
await userRepository.DeleteAsync(user);
|
||||||
|
await organizationRepository.DeleteAsync(organization);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user