mirror of
https://github.com/bitwarden/server.git
synced 2024-11-25 12:45:18 +01:00
d29755de5a
* feat: remove required for AccessAll and add xmldoc for usage restrictions, refs AC-1880 * feat: add validation for create group workflow wrt manage property, refs AC-1880 * feat: add validation for update group workflow wrt manage property, refs AC-1880 * feat: add validation for create and update member workflow wrt manage property, refs AC-1880 * feat: add validation for update collection workflow wrt manage property, refs AC-1880 * fix: flaky Public/GroupsControllerTests + more test coverage, refs AC-1880
67 lines
3.1 KiB
C#
67 lines
3.1 KiB
C#
using Bit.Api.AdminConsole.Controllers;
|
|
using Bit.Api.AdminConsole.Models.Request;
|
|
using Bit.Core.AdminConsole.Entities;
|
|
using Bit.Core.AdminConsole.OrganizationFeatures.Groups.Interfaces;
|
|
using Bit.Core.AdminConsole.Repositories;
|
|
using Bit.Core.Context;
|
|
using Bit.Core.Models.Data;
|
|
using Bit.Core.Repositories;
|
|
using Bit.Test.Common.AutoFixture;
|
|
using Bit.Test.Common.AutoFixture.Attributes;
|
|
using NSubstitute;
|
|
using Xunit;
|
|
|
|
namespace Bit.Api.Test.AdminConsole.Controllers;
|
|
|
|
[ControllerCustomize(typeof(GroupsController))]
|
|
[SutProviderCustomize]
|
|
public class GroupsControllerTests
|
|
{
|
|
[Theory]
|
|
[BitAutoData]
|
|
public async Task Post_Success(Organization organization, GroupRequestModel groupRequestModel, SutProvider<GroupsController> sutProvider)
|
|
{
|
|
sutProvider.GetDependency<IOrganizationRepository>().GetByIdAsync(organization.Id).Returns(organization);
|
|
sutProvider.GetDependency<ICurrentContext>().ManageGroups(organization.Id).Returns(true);
|
|
|
|
var response = await sutProvider.Sut.Post(organization.Id.ToString(), groupRequestModel);
|
|
|
|
await sutProvider.GetDependency<ICurrentContext>().Received(1).ManageGroups(organization.Id);
|
|
await sutProvider.GetDependency<ICreateGroupCommand>().Received(1).CreateGroupAsync(
|
|
Arg.Is<Group>(g =>
|
|
g.OrganizationId == organization.Id && g.Name == groupRequestModel.Name &&
|
|
g.AccessAll == groupRequestModel.AccessAll),
|
|
organization,
|
|
Arg.Any<ICollection<CollectionAccessSelection>>(),
|
|
Arg.Any<IEnumerable<Guid>>());
|
|
Assert.Equal(groupRequestModel.Name, response.Name);
|
|
Assert.Equal(organization.Id, response.OrganizationId);
|
|
Assert.Equal(groupRequestModel.AccessAll, response.AccessAll);
|
|
}
|
|
|
|
[Theory]
|
|
[BitAutoData]
|
|
public async Task Put_Success(Organization organization, Group group, GroupRequestModel groupRequestModel, SutProvider<GroupsController> sutProvider)
|
|
{
|
|
group.OrganizationId = organization.Id;
|
|
|
|
sutProvider.GetDependency<IOrganizationRepository>().GetByIdAsync(organization.Id).Returns(organization);
|
|
sutProvider.GetDependency<IGroupRepository>().GetByIdAsync(group.Id).Returns(group);
|
|
sutProvider.GetDependency<ICurrentContext>().ManageGroups(organization.Id).Returns(true);
|
|
|
|
var response = await sutProvider.Sut.Put(organization.Id.ToString(), group.Id.ToString(), groupRequestModel);
|
|
|
|
await sutProvider.GetDependency<ICurrentContext>().Received(1).ManageGroups(organization.Id);
|
|
await sutProvider.GetDependency<IUpdateGroupCommand>().Received(1).UpdateGroupAsync(
|
|
Arg.Is<Group>(g =>
|
|
g.OrganizationId == organization.Id && g.Name == groupRequestModel.Name &&
|
|
g.AccessAll == groupRequestModel.AccessAll),
|
|
Arg.Is<Organization>(o => o.Id == organization.Id),
|
|
Arg.Any<ICollection<CollectionAccessSelection>>(),
|
|
Arg.Any<IEnumerable<Guid>>());
|
|
Assert.Equal(groupRequestModel.Name, response.Name);
|
|
Assert.Equal(organization.Id, response.OrganizationId);
|
|
Assert.Equal(groupRequestModel.AccessAll, response.AccessAll);
|
|
}
|
|
}
|