mirror of
https://github.com/bitwarden/server
synced 2026-01-06 18:43:36 +00:00
[AC-1174] CollectionUser and CollectionGroup authorization handlers (#3194)
* [AC-1174] Introduce BulkAuthorizationHandler.cs * [AC-1174] Introduce CollectionUserAuthorizationHandler * [AC-1174] Add CreateForNewCollection CollectionUser requirement * [AC-1174] Add some more details to CollectionCustomization * [AC-1174] Formatting * [AC-1174] Add CollectionGroupOperation.cs * [AC-1174] Introduce CollectionGroupAuthorizationHandler.cs * [AC-1174] Cleanup CollectionFixture customization Implement and use re-usable extension method to support seeded Guids * [AC-1174] Introduce WithValueFromList AutoFixtureExtensions Modify CollectionCustomization to use multiple organization Ids for auto generated test data * [AC-1174] Simplify CollectionUserAuthorizationHandler.cs Modify the authorization handler to only perform authorization logic. Validation logic will need to be handled by any calling commands/controllers instead. * [AC-1174] Introduce shared CollectionAccessAuthorizationHandlerBase A shared base authorization handler was created for both CollectionUser and CollectionGroup resources, as they share the same underlying management authorization logic. * [AC-1174] Update CollectionUserAuthorizationHandler and CollectionGroupAuthorizationHandler to use the new CollectionAccessAuthorizationHandlerBase class * [AC-1174] Formatting * [AC-1174] Cleanup typo and redundant ToList() call * [AC-1174] Add check for provider users * [AC-1174] Reduce nested loops * [AC-1174] Introduce ICollectionAccess.cs * [AC-1174] Remove individual CollectionGroup and CollectionUser auth handlers and use base class instead * [AC-1174] Tweak unit test to fail minimally * [AC-1174] Reorganize authorization handlers in Core project * [AC-1174] Introduce new AddCoreAuthorizationHandlers() extension method * [AC-1174] Move CollectionAccessAuthorizationHandler into Api project * [AC-1174] Move CollectionFixture to Vault folder * [AC-1174] Rename operation to CreateUpdateDelete * [AC-1174] Require single organization for collection access authorization handler - Add requirement that all target collections must belong to the same organization - Simplify logic related to multiple organizations - Update tests and helpers - Use ToHashSet to improve lookup time * [AC-1174] Fix null reference exception * [AC-1174] Throw bad request exception when collections belong to different organizations * [AC-1174] Switch to CollectionAuthorizationHandler instead of CollectionAccessAuthorizationHandler to reduce complexity
This commit is contained in:
52
test/Core.Test/Vault/AutoFixture/CollectionFixture.cs
Normal file
52
test/Core.Test/Vault/AutoFixture/CollectionFixture.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using AutoFixture;
|
||||
using Bit.Core.Context;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.Test.AutoFixture;
|
||||
using Bit.Test.Common.AutoFixture.Attributes;
|
||||
|
||||
namespace Bit.Core.Test.Vault.AutoFixture;
|
||||
|
||||
public class CollectionCustomization : ICustomization
|
||||
{
|
||||
private const int _collectionIdSeed = 1;
|
||||
private const int _userIdSeed = 2;
|
||||
private const int _groupIdSeed = 3;
|
||||
|
||||
public void Customize(IFixture fixture)
|
||||
{
|
||||
var orgId = Guid.NewGuid();
|
||||
|
||||
fixture.Customize<CurrentContentOrganization>(composer => composer
|
||||
.With(o => o.Id, orgId));
|
||||
|
||||
fixture.Customize<OrganizationUser>(composer => composer
|
||||
.With(o => o.OrganizationId, orgId)
|
||||
.WithGuidFromSeed(o => o.Id, _userIdSeed));
|
||||
|
||||
fixture.Customize<Collection>(composer => composer
|
||||
.With(o => o.OrganizationId, orgId)
|
||||
.WithGuidFromSeed(c => c.Id, _collectionIdSeed));
|
||||
|
||||
fixture.Customize<CollectionDetails>(composer => composer
|
||||
.With(o => o.OrganizationId, orgId)
|
||||
.WithGuidFromSeed(cd => cd.Id, _collectionIdSeed));
|
||||
|
||||
fixture.Customize<CollectionUser>(c => c
|
||||
.WithGuidFromSeed(cu => cu.OrganizationUserId, _userIdSeed)
|
||||
.WithGuidFromSeed(cu => cu.CollectionId, _collectionIdSeed));
|
||||
|
||||
fixture.Customize<Group>(composer => composer
|
||||
.With(o => o.OrganizationId, orgId)
|
||||
.WithGuidFromSeed(o => o.Id, _groupIdSeed));
|
||||
|
||||
fixture.Customize<CollectionGroup>(c => c
|
||||
.WithGuidFromSeed(cu => cu.GroupId, _groupIdSeed)
|
||||
.WithGuidFromSeed(cu => cu.CollectionId, _collectionIdSeed));
|
||||
}
|
||||
}
|
||||
|
||||
public class CollectionCustomizationAttribute : BitCustomizeAttribute
|
||||
{
|
||||
public override ICustomization GetCustomization() => new CollectionCustomization();
|
||||
}
|
||||
Reference in New Issue
Block a user