mirror of
https://github.com/bitwarden/server.git
synced 2025-06-27 14:16:19 -05:00
Implement a check to throw a BadRequestException if an attempt is made to modify member access for collections of type DefaultUserCollection.
This commit is contained in:
parent
4d36e87b6f
commit
bcb90f2913
@ -3,6 +3,7 @@ using Bit.Api.Models.Response;
|
||||
using Bit.Api.Vault.AuthorizationHandlers.Collections;
|
||||
using Bit.Core.Context;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Exceptions;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.OrganizationFeatures.OrganizationCollections.Interfaces;
|
||||
@ -208,6 +209,11 @@ public class CollectionsController : Controller
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
if (collection.Type == CollectionType.DefaultUserCollection)
|
||||
{
|
||||
throw new BadRequestException("You cannot modify member access for collections with the type as DefaultUserCollection.");
|
||||
}
|
||||
|
||||
await _collectionRepository.UpdateUsersAsync(collection.Id, model?.Select(g => g.ToSelectionReadOnly()));
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ using Bit.Api.Vault.AuthorizationHandlers.Collections;
|
||||
using Bit.Core.AdminConsole.Entities;
|
||||
using Bit.Core.Context;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Exceptions;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.OrganizationFeatures.OrganizationCollections.Interfaces;
|
||||
@ -484,4 +485,31 @@ public class CollectionsControllerTests
|
||||
await sutProvider.GetDependency<IBulkAddCollectionAccessCommand>().DidNotReceiveWithAnyArgs()
|
||||
.AddAccessAsync(default, default, default);
|
||||
}
|
||||
|
||||
[Theory, BitAutoData]
|
||||
public async Task PutUsers_WithDefaultUserCollectionType_ThrowsBadRequest(Organization organization,
|
||||
Collection collection, IEnumerable<SelectionReadOnlyRequestModel> model, SutProvider<CollectionsController> sutProvider)
|
||||
{
|
||||
collection.Type = CollectionType.DefaultUserCollection;
|
||||
collection.OrganizationId = organization.Id;
|
||||
|
||||
sutProvider.GetDependency<ICollectionRepository>()
|
||||
.GetByIdAsync(collection.Id)
|
||||
.Returns(collection);
|
||||
|
||||
sutProvider.GetDependency<IAuthorizationService>()
|
||||
.AuthorizeAsync(Arg.Any<ClaimsPrincipal>(),
|
||||
collection,
|
||||
Arg.Is<IEnumerable<IAuthorizationRequirement>>(r => r.Contains(BulkCollectionOperations.ModifyUserAccess)))
|
||||
.Returns(AuthorizationResult.Success());
|
||||
|
||||
var exception = await Assert.ThrowsAsync<BadRequestException>(() =>
|
||||
sutProvider.Sut.PutUsers(organization.Id, collection.Id, model));
|
||||
|
||||
Assert.Contains("You cannot modify member access for collections with the type as DefaultUserCollection.", exception.Message);
|
||||
|
||||
await sutProvider.GetDependency<ICollectionRepository>()
|
||||
.DidNotReceiveWithAnyArgs()
|
||||
.UpdateUsersAsync(default, default);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user