1
0
mirror of https://github.com/bitwarden/server synced 2026-01-31 00:33:17 +00:00

Return uniform error

This commit is contained in:
Thomas Rittson
2026-01-01 15:16:48 +10:00
parent a9e840988d
commit ebbdc946a1
7 changed files with 113 additions and 32 deletions

View File

@@ -1,4 +1,6 @@
using Bit.Core.AdminConsole.Entities;

using Bit.Core.AdminConsole.Collections;
using Bit.Core.AdminConsole.Entities;
using Bit.Core.Entities;
using Bit.Core.Enums;
using Bit.Core.Repositories;
@@ -96,8 +98,8 @@ public class CreateDefaultCollectionsBulkTests
await CreateUsersWithExistingDefaultCollectionsAsync(collectionRepository, organization.Id, affectedOrgUserIds, defaultCollectionName, resultOrganizationUsers);
// Act - Try to create again, should throw database constraint exception
await Assert.ThrowsAnyAsync<Exception>(() =>
// Act - Try to create again, should throw specific duplicate collection exception
await Assert.ThrowsAsync<DuplicateDefaultCollectionException>(() =>
collectionRepository.CreateDefaultCollectionsBulkAsync(organization.Id, affectedOrgUserIds, defaultCollectionName));
// Assert - Original collections should remain unchanged
@@ -125,7 +127,7 @@ public class CreateDefaultCollectionsBulkTests
await collectionRepository.CreateDefaultCollectionsBulkAsync(organization.Id, [existingUser.Id], defaultCollectionName);
// Act - Try to create for both without filtering (incorrect usage)
await Assert.ThrowsAnyAsync<Exception>(() =>
await Assert.ThrowsAsync<DuplicateDefaultCollectionException>(() =>
collectionRepository.CreateDefaultCollectionsBulkAsync(
organization.Id,
[existingUser.Id, newUser.Id],

View File

@@ -1,4 +1,5 @@
using Bit.Core.Enums;
using Bit.Core.AdminConsole.Collections;
using Bit.Core.Enums;
using Bit.Core.Repositories;
using Xunit;
@@ -87,8 +88,8 @@ public class CreateDefaultCollectionsTests
[orgUser.Id],
"My Items");
// Second call should throw and should not create duplicate
await Assert.ThrowsAnyAsync<Exception>(() =>
// Second call should throw specific exception and should not create duplicate
await Assert.ThrowsAsync<DuplicateDefaultCollectionException>(() =>
collectionRepository.CreateDefaultCollectionsAsync(
organization.Id,
[orgUser.Id],