2023-10-19 22:37:46 +02:00
|
|
|
|
using Bit.Core.AdminConsole.Entities;
|
|
|
|
|
using Bit.Core.AdminConsole.OrganizationFeatures.Groups;
|
|
|
|
|
using Bit.Core.AdminConsole.Repositories;
|
2022-12-12 10:59:48 +01:00
|
|
|
|
using Bit.Core.Enums;
|
|
|
|
|
using Bit.Core.Exceptions;
|
|
|
|
|
using Bit.Core.Models.Data;
|
|
|
|
|
using Bit.Core.Services;
|
|
|
|
|
using Bit.Core.Test.AutoFixture.OrganizationFixtures;
|
2023-04-18 14:05:17 +02:00
|
|
|
|
using Bit.Core.Tools.Enums;
|
|
|
|
|
using Bit.Core.Tools.Models.Business;
|
|
|
|
|
using Bit.Core.Tools.Services;
|
2022-12-12 10:59:48 +01:00
|
|
|
|
using Bit.Test.Common.AutoFixture;
|
|
|
|
|
using Bit.Test.Common.AutoFixture.Attributes;
|
|
|
|
|
using Bit.Test.Common.Helpers;
|
|
|
|
|
using NSubstitute;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
2023-10-19 22:37:46 +02:00
|
|
|
|
namespace Bit.Core.Test.AdminConsole.OrganizationFeatures.Groups;
|
2022-12-12 10:59:48 +01:00
|
|
|
|
|
|
|
|
|
[SutProviderCustomize]
|
|
|
|
|
public class CreateGroupCommandTests
|
|
|
|
|
{
|
[AC-2646] Remove FC MVP dead code from Core (#4281)
* chore: remove fc refs in CreateGroup and UpdateGroup commands, refs AC-2646
* chore: remove fc refs and update interface to represent usage/get rid of double enumeration warnings, refs AC-2646
* chore: remove org/provider service fc callers, refs AC-2646
* chore: remove collection service fc callers, refs AC-2646
* chore: remove cipher service import ciphers fc callers, refs AC-2646
* fix: UpdateOrganizationUserCommandTests collections to list, refs AC-2646
* fix: update CreateGroupCommandTests, refs AC-2646
* fix: adjust UpdateGroupCommandTests, refs AC-2646
* fix: adjust UpdateOrganizationUserCommandTests for FC always true, refs AC-2646
* fix: update CollectionServiceTests, refs AC-2646
* fix: remove unnecessary test with fc disabled, refs AC-2646
* fix: update tests to account for AccessAll removal and Manager removal, refs AC-2646
* chore: remove dependence on FC flag for tests, refs AC-2646
2024-07-12 19:25:04 +02:00
|
|
|
|
[Theory, OrganizationCustomize(UseGroups = true), BitAutoData]
|
2022-12-12 10:59:48 +01:00
|
|
|
|
public async Task CreateGroup_Success(SutProvider<CreateGroupCommand> sutProvider, Organization organization, Group group)
|
|
|
|
|
{
|
|
|
|
|
await sutProvider.Sut.CreateGroupAsync(group, organization);
|
|
|
|
|
|
|
|
|
|
await sutProvider.GetDependency<IGroupRepository>().Received(1).CreateAsync(group);
|
|
|
|
|
await sutProvider.GetDependency<IEventService>().Received(1).LogGroupEventAsync(group, Enums.EventType.Group_Created);
|
|
|
|
|
await sutProvider.GetDependency<IReferenceEventService>().Received(1).RaiseEventAsync(Arg.Is<ReferenceEvent>(r => r.Type == ReferenceEventType.GroupCreated && r.Id == organization.Id && r.Source == ReferenceEventSource.Organization));
|
|
|
|
|
AssertHelper.AssertRecent(group.CreationDate);
|
|
|
|
|
AssertHelper.AssertRecent(group.RevisionDate);
|
|
|
|
|
}
|
|
|
|
|
|
[AC-2646] Remove FC MVP dead code from Core (#4281)
* chore: remove fc refs in CreateGroup and UpdateGroup commands, refs AC-2646
* chore: remove fc refs and update interface to represent usage/get rid of double enumeration warnings, refs AC-2646
* chore: remove org/provider service fc callers, refs AC-2646
* chore: remove collection service fc callers, refs AC-2646
* chore: remove cipher service import ciphers fc callers, refs AC-2646
* fix: UpdateOrganizationUserCommandTests collections to list, refs AC-2646
* fix: update CreateGroupCommandTests, refs AC-2646
* fix: adjust UpdateGroupCommandTests, refs AC-2646
* fix: adjust UpdateOrganizationUserCommandTests for FC always true, refs AC-2646
* fix: update CollectionServiceTests, refs AC-2646
* fix: remove unnecessary test with fc disabled, refs AC-2646
* fix: update tests to account for AccessAll removal and Manager removal, refs AC-2646
* chore: remove dependence on FC flag for tests, refs AC-2646
2024-07-12 19:25:04 +02:00
|
|
|
|
[Theory, OrganizationCustomize(UseGroups = true), BitAutoData]
|
2023-01-19 17:00:54 +01:00
|
|
|
|
public async Task CreateGroup_WithCollections_Success(SutProvider<CreateGroupCommand> sutProvider, Organization organization, Group group, List<CollectionAccessSelection> collections)
|
2022-12-12 10:59:48 +01:00
|
|
|
|
{
|
[AC-2646] Remove FC MVP dead code from Core (#4281)
* chore: remove fc refs in CreateGroup and UpdateGroup commands, refs AC-2646
* chore: remove fc refs and update interface to represent usage/get rid of double enumeration warnings, refs AC-2646
* chore: remove org/provider service fc callers, refs AC-2646
* chore: remove collection service fc callers, refs AC-2646
* chore: remove cipher service import ciphers fc callers, refs AC-2646
* fix: UpdateOrganizationUserCommandTests collections to list, refs AC-2646
* fix: update CreateGroupCommandTests, refs AC-2646
* fix: adjust UpdateGroupCommandTests, refs AC-2646
* fix: adjust UpdateOrganizationUserCommandTests for FC always true, refs AC-2646
* fix: update CollectionServiceTests, refs AC-2646
* fix: remove unnecessary test with fc disabled, refs AC-2646
* fix: update tests to account for AccessAll removal and Manager removal, refs AC-2646
* chore: remove dependence on FC flag for tests, refs AC-2646
2024-07-12 19:25:04 +02:00
|
|
|
|
// Arrange list of collections to make sure Manage is mutually exclusive
|
|
|
|
|
for (var i = 0; i < collections.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var cas = collections[i];
|
|
|
|
|
cas.Manage = i != collections.Count - 1;
|
|
|
|
|
cas.HidePasswords = i == collections.Count - 1;
|
|
|
|
|
cas.ReadOnly = i == collections.Count - 1;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-12 10:59:48 +01:00
|
|
|
|
await sutProvider.Sut.CreateGroupAsync(group, organization, collections);
|
|
|
|
|
|
|
|
|
|
await sutProvider.GetDependency<IGroupRepository>().Received(1).CreateAsync(group, collections);
|
|
|
|
|
await sutProvider.GetDependency<IEventService>().Received(1).LogGroupEventAsync(group, Enums.EventType.Group_Created);
|
|
|
|
|
await sutProvider.GetDependency<IReferenceEventService>().Received(1).RaiseEventAsync(Arg.Is<ReferenceEvent>(r => r.Type == ReferenceEventType.GroupCreated && r.Id == organization.Id && r.Source == ReferenceEventSource.Organization));
|
|
|
|
|
AssertHelper.AssertRecent(group.CreationDate);
|
|
|
|
|
AssertHelper.AssertRecent(group.RevisionDate);
|
|
|
|
|
}
|
|
|
|
|
|
[AC-2646] Remove FC MVP dead code from Core (#4281)
* chore: remove fc refs in CreateGroup and UpdateGroup commands, refs AC-2646
* chore: remove fc refs and update interface to represent usage/get rid of double enumeration warnings, refs AC-2646
* chore: remove org/provider service fc callers, refs AC-2646
* chore: remove collection service fc callers, refs AC-2646
* chore: remove cipher service import ciphers fc callers, refs AC-2646
* fix: UpdateOrganizationUserCommandTests collections to list, refs AC-2646
* fix: update CreateGroupCommandTests, refs AC-2646
* fix: adjust UpdateGroupCommandTests, refs AC-2646
* fix: adjust UpdateOrganizationUserCommandTests for FC always true, refs AC-2646
* fix: update CollectionServiceTests, refs AC-2646
* fix: remove unnecessary test with fc disabled, refs AC-2646
* fix: update tests to account for AccessAll removal and Manager removal, refs AC-2646
* chore: remove dependence on FC flag for tests, refs AC-2646
2024-07-12 19:25:04 +02:00
|
|
|
|
[Theory, OrganizationCustomize(UseGroups = true), BitAutoData]
|
2022-12-12 10:59:48 +01:00
|
|
|
|
public async Task CreateGroup_WithEventSystemUser_Success(SutProvider<CreateGroupCommand> sutProvider, Organization organization, Group group, EventSystemUser eventSystemUser)
|
|
|
|
|
{
|
|
|
|
|
await sutProvider.Sut.CreateGroupAsync(group, organization, eventSystemUser);
|
|
|
|
|
|
|
|
|
|
await sutProvider.GetDependency<IGroupRepository>().Received(1).CreateAsync(group);
|
|
|
|
|
await sutProvider.GetDependency<IEventService>().Received(1).LogGroupEventAsync(group, Enums.EventType.Group_Created, eventSystemUser);
|
|
|
|
|
await sutProvider.GetDependency<IReferenceEventService>().Received(1).RaiseEventAsync(Arg.Is<ReferenceEvent>(r => r.Type == ReferenceEventType.GroupCreated && r.Id == organization.Id && r.Source == ReferenceEventSource.Organization));
|
|
|
|
|
AssertHelper.AssertRecent(group.CreationDate);
|
|
|
|
|
AssertHelper.AssertRecent(group.RevisionDate);
|
|
|
|
|
}
|
|
|
|
|
|
[AC-2646] Remove FC MVP dead code from Core (#4281)
* chore: remove fc refs in CreateGroup and UpdateGroup commands, refs AC-2646
* chore: remove fc refs and update interface to represent usage/get rid of double enumeration warnings, refs AC-2646
* chore: remove org/provider service fc callers, refs AC-2646
* chore: remove collection service fc callers, refs AC-2646
* chore: remove cipher service import ciphers fc callers, refs AC-2646
* fix: UpdateOrganizationUserCommandTests collections to list, refs AC-2646
* fix: update CreateGroupCommandTests, refs AC-2646
* fix: adjust UpdateGroupCommandTests, refs AC-2646
* fix: adjust UpdateOrganizationUserCommandTests for FC always true, refs AC-2646
* fix: update CollectionServiceTests, refs AC-2646
* fix: remove unnecessary test with fc disabled, refs AC-2646
* fix: update tests to account for AccessAll removal and Manager removal, refs AC-2646
* chore: remove dependence on FC flag for tests, refs AC-2646
2024-07-12 19:25:04 +02:00
|
|
|
|
[Theory, OrganizationCustomize(UseGroups = true), BitAutoData]
|
2022-12-12 10:59:48 +01:00
|
|
|
|
public async Task CreateGroup_WithNullOrganization_Throws(SutProvider<CreateGroupCommand> sutProvider, Group group, EventSystemUser eventSystemUser)
|
|
|
|
|
{
|
|
|
|
|
var exception = await Assert.ThrowsAsync<BadRequestException>(async () => await sutProvider.Sut.CreateGroupAsync(group, null, eventSystemUser));
|
|
|
|
|
|
|
|
|
|
Assert.Contains("Organization not found", exception.Message);
|
|
|
|
|
|
|
|
|
|
await sutProvider.GetDependency<IGroupRepository>().DidNotReceiveWithAnyArgs().CreateAsync(default);
|
|
|
|
|
await sutProvider.GetDependency<IEventService>().DidNotReceiveWithAnyArgs().LogGroupEventAsync(default, default, default);
|
|
|
|
|
await sutProvider.GetDependency<IReferenceEventService>().DidNotReceiveWithAnyArgs().RaiseEventAsync(default);
|
|
|
|
|
}
|
|
|
|
|
|
[AC-2646] Remove FC MVP dead code from Core (#4281)
* chore: remove fc refs in CreateGroup and UpdateGroup commands, refs AC-2646
* chore: remove fc refs and update interface to represent usage/get rid of double enumeration warnings, refs AC-2646
* chore: remove org/provider service fc callers, refs AC-2646
* chore: remove collection service fc callers, refs AC-2646
* chore: remove cipher service import ciphers fc callers, refs AC-2646
* fix: UpdateOrganizationUserCommandTests collections to list, refs AC-2646
* fix: update CreateGroupCommandTests, refs AC-2646
* fix: adjust UpdateGroupCommandTests, refs AC-2646
* fix: adjust UpdateOrganizationUserCommandTests for FC always true, refs AC-2646
* fix: update CollectionServiceTests, refs AC-2646
* fix: remove unnecessary test with fc disabled, refs AC-2646
* fix: update tests to account for AccessAll removal and Manager removal, refs AC-2646
* chore: remove dependence on FC flag for tests, refs AC-2646
2024-07-12 19:25:04 +02:00
|
|
|
|
[Theory, OrganizationCustomize(UseGroups = false), BitAutoData]
|
2022-12-12 10:59:48 +01:00
|
|
|
|
public async Task CreateGroup_WithUseGroupsAsFalse_Throws(SutProvider<CreateGroupCommand> sutProvider, Organization organization, Group group, EventSystemUser eventSystemUser)
|
|
|
|
|
{
|
|
|
|
|
var exception = await Assert.ThrowsAsync<BadRequestException>(async () => await sutProvider.Sut.CreateGroupAsync(group, organization, eventSystemUser));
|
|
|
|
|
|
|
|
|
|
Assert.Contains("This organization cannot use groups", exception.Message);
|
|
|
|
|
|
|
|
|
|
await sutProvider.GetDependency<IGroupRepository>().DidNotReceiveWithAnyArgs().CreateAsync(default);
|
|
|
|
|
await sutProvider.GetDependency<IEventService>().DidNotReceiveWithAnyArgs().LogGroupEventAsync(default, default, default);
|
|
|
|
|
await sutProvider.GetDependency<IReferenceEventService>().DidNotReceiveWithAnyArgs().RaiseEventAsync(default);
|
|
|
|
|
}
|
|
|
|
|
}
|