2024-04-18 12:42:30 +02:00
|
|
|
|
using System.Text.Json;
|
|
|
|
|
using Bit.Core.AdminConsole.Entities;
|
|
|
|
|
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers;
|
|
|
|
|
using Bit.Core.Entities;
|
|
|
|
|
using Bit.Core.Enums;
|
|
|
|
|
using Bit.Core.Exceptions;
|
|
|
|
|
using Bit.Core.Models.Data;
|
|
|
|
|
using Bit.Core.Repositories;
|
|
|
|
|
using Bit.Core.Services;
|
|
|
|
|
using Bit.Core.Test.AutoFixture.OrganizationUserFixtures;
|
|
|
|
|
using Bit.Core.Utilities;
|
|
|
|
|
using Bit.Test.Common.AutoFixture;
|
|
|
|
|
using Bit.Test.Common.AutoFixture.Attributes;
|
|
|
|
|
using NSubstitute;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace Bit.Core.Test.AdminConsole.OrganizationFeatures.OrganizationUsers;
|
|
|
|
|
|
|
|
|
|
[SutProviderCustomize]
|
|
|
|
|
public class UpdateOrganizationUserCommandTests
|
|
|
|
|
{
|
|
|
|
|
[Theory, BitAutoData]
|
|
|
|
|
public async Task UpdateUserAsync_NoUserId_Throws(OrganizationUser user, Guid? savingUserId,
|
[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
|
|
|
|
List<CollectionAccessSelection> collections, IEnumerable<Guid> groups, SutProvider<UpdateOrganizationUserCommand> sutProvider)
|
2024-04-18 12:42:30 +02:00
|
|
|
|
{
|
|
|
|
|
user.Id = default(Guid);
|
|
|
|
|
var exception = await Assert.ThrowsAsync<BadRequestException>(
|
|
|
|
|
() => sutProvider.Sut.UpdateUserAsync(user, savingUserId, collections, groups));
|
|
|
|
|
Assert.Contains("invite the user first", exception.Message.ToLowerInvariant());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory, BitAutoData]
|
|
|
|
|
public async Task UpdateUserAsync_Passes(
|
|
|
|
|
Organization organization,
|
|
|
|
|
OrganizationUser oldUserData,
|
|
|
|
|
OrganizationUser newUserData,
|
[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
|
|
|
|
List<CollectionAccessSelection> collections,
|
2024-04-18 12:42:30 +02:00
|
|
|
|
IEnumerable<Guid> groups,
|
|
|
|
|
Permissions permissions,
|
|
|
|
|
[OrganizationUser(type: OrganizationUserType.Owner)] OrganizationUser savingUser,
|
|
|
|
|
SutProvider<UpdateOrganizationUserCommand> sutProvider)
|
|
|
|
|
{
|
|
|
|
|
var organizationRepository = sutProvider.GetDependency<IOrganizationRepository>();
|
|
|
|
|
var organizationUserRepository = sutProvider.GetDependency<IOrganizationUserRepository>();
|
|
|
|
|
var organizationService = sutProvider.GetDependency<IOrganizationService>();
|
|
|
|
|
|
|
|
|
|
organizationRepository.GetByIdAsync(organization.Id).Returns(organization);
|
|
|
|
|
|
[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
|
|
|
|
// Deprecated with Flexible Collections
|
|
|
|
|
oldUserData.AccessAll = false;
|
|
|
|
|
newUserData.AccessAll = false;
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-18 12:42:30 +02:00
|
|
|
|
newUserData.Id = oldUserData.Id;
|
|
|
|
|
newUserData.UserId = oldUserData.UserId;
|
|
|
|
|
newUserData.OrganizationId = savingUser.OrganizationId = oldUserData.OrganizationId = organization.Id;
|
|
|
|
|
newUserData.Permissions = JsonSerializer.Serialize(permissions, new JsonSerializerOptions
|
|
|
|
|
{
|
|
|
|
|
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
|
|
|
|
});
|
|
|
|
|
organizationUserRepository.GetByIdAsync(oldUserData.Id).Returns(oldUserData);
|
|
|
|
|
organizationUserRepository.GetManyByOrganizationAsync(savingUser.OrganizationId, OrganizationUserType.Owner)
|
|
|
|
|
.Returns(new List<OrganizationUser> { savingUser });
|
|
|
|
|
organizationService
|
|
|
|
|
.HasConfirmedOwnersExceptAsync(
|
|
|
|
|
newUserData.OrganizationId,
|
|
|
|
|
Arg.Is<IEnumerable<Guid>>(i => i.Contains(newUserData.Id)))
|
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
|
|
await sutProvider.Sut.UpdateUserAsync(newUserData, savingUser.UserId, collections, groups);
|
|
|
|
|
|
|
|
|
|
await organizationService.Received(1).ValidateOrganizationUserUpdatePermissions(
|
|
|
|
|
newUserData.OrganizationId,
|
|
|
|
|
newUserData.Type,
|
|
|
|
|
oldUserData.Type,
|
|
|
|
|
Arg.Any<Permissions>());
|
|
|
|
|
await organizationService.Received(1).ValidateOrganizationCustomPermissionsEnabledAsync(
|
|
|
|
|
newUserData.OrganizationId,
|
|
|
|
|
newUserData.Type);
|
|
|
|
|
await organizationService.Received(1).HasConfirmedOwnersExceptAsync(
|
|
|
|
|
newUserData.OrganizationId,
|
|
|
|
|
Arg.Is<IEnumerable<Guid>>(i => i.Contains(newUserData.Id)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory, BitAutoData]
|
[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
|
|
|
|
public async Task UpdateUserAsync_WithAccessAll_Throws(
|
2024-04-18 12:42:30 +02:00
|
|
|
|
Organization organization,
|
|
|
|
|
[OrganizationUser(type: OrganizationUserType.User)] OrganizationUser oldUserData,
|
|
|
|
|
[OrganizationUser(type: OrganizationUserType.User)] OrganizationUser newUserData,
|
|
|
|
|
[OrganizationUser(type: OrganizationUserType.Owner, status: OrganizationUserStatusType.Confirmed)] OrganizationUser savingUser,
|
[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
|
|
|
|
List<CollectionAccessSelection> collections,
|
2024-04-18 12:42:30 +02:00
|
|
|
|
IEnumerable<Guid> groups,
|
|
|
|
|
SutProvider<UpdateOrganizationUserCommand> sutProvider)
|
|
|
|
|
{
|
|
|
|
|
newUserData.Id = oldUserData.Id;
|
|
|
|
|
newUserData.UserId = oldUserData.UserId;
|
|
|
|
|
newUserData.OrganizationId = oldUserData.OrganizationId = savingUser.OrganizationId = organization.Id;
|
|
|
|
|
newUserData.Permissions = CoreHelpers.ClassToJsonData(new Permissions());
|
|
|
|
|
newUserData.AccessAll = true;
|
|
|
|
|
|
|
|
|
|
sutProvider.GetDependency<IOrganizationRepository>()
|
|
|
|
|
.GetByIdAsync(organization.Id)
|
|
|
|
|
.Returns(organization);
|
|
|
|
|
|
|
|
|
|
sutProvider.GetDependency<IOrganizationService>()
|
|
|
|
|
.HasConfirmedOwnersExceptAsync(
|
|
|
|
|
newUserData.OrganizationId,
|
|
|
|
|
Arg.Is<IEnumerable<Guid>>(i => i.Contains(newUserData.Id)))
|
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
|
|
|
sutProvider.GetDependency<IOrganizationUserRepository>()
|
|
|
|
|
.GetByIdAsync(oldUserData.Id)
|
|
|
|
|
.Returns(oldUserData);
|
|
|
|
|
|
|
|
|
|
sutProvider.GetDependency<IOrganizationUserRepository>()
|
|
|
|
|
.GetManyByOrganizationAsync(organization.Id, OrganizationUserType.Owner)
|
|
|
|
|
.Returns(new List<OrganizationUser> { savingUser });
|
|
|
|
|
|
|
|
|
|
var exception = await Assert.ThrowsAsync<BadRequestException>(
|
|
|
|
|
() => sutProvider.Sut.UpdateUserAsync(newUserData, oldUserData.UserId, collections, groups));
|
|
|
|
|
|
|
|
|
|
Assert.Contains("the accessall property has been deprecated", exception.Message.ToLowerInvariant());
|
|
|
|
|
}
|
|
|
|
|
}
|