mirror of
https://github.com/bitwarden/server
synced 2026-01-04 09:33:40 +00:00
Merge branch 'main' into billing/PM-24964/msp-unable-verfy-bank-account
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Text.Json;
|
||||
using Bit.Core.AdminConsole.Entities.Provider;
|
||||
using Bit.Core.AdminConsole.Enums.Provider;
|
||||
using Bit.Core.AdminConsole.Models.Business;
|
||||
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.Interfaces;
|
||||
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers;
|
||||
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.InviteUsers.Models;
|
||||
@@ -27,7 +28,6 @@ using Bit.Test.Common.AutoFixture.Attributes;
|
||||
using Bit.Test.Common.Fakes;
|
||||
using NSubstitute;
|
||||
using NSubstitute.ExceptionExtensions;
|
||||
using NSubstitute.ReceivedExtensions;
|
||||
using NSubstitute.ReturnsExtensions;
|
||||
using Stripe;
|
||||
using Xunit;
|
||||
@@ -42,8 +42,6 @@ public class OrganizationServiceTests
|
||||
{
|
||||
private readonly IDataProtectorTokenFactory<OrgUserInviteTokenable> _orgUserInviteTokenDataFactory = new FakeDataProtectorTokenFactory<OrgUserInviteTokenable>();
|
||||
|
||||
|
||||
|
||||
[Theory]
|
||||
[OrganizationInviteCustomize(InviteeUserType = OrganizationUserType.User,
|
||||
InvitorUserType = OrganizationUserType.Owner), OrganizationCustomize, BitAutoData]
|
||||
@@ -1229,6 +1227,109 @@ public class OrganizationServiceTests
|
||||
.GetByIdentifierAsync(Arg.Is<string>(id => id == organization.Identifier));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[BitAutoData(false, true, false, true)]
|
||||
[BitAutoData(true, false, true, false)]
|
||||
public async Task UpdateCollectionManagementSettingsAsync_WhenSettingsChanged_LogsSpecificEvents(
|
||||
bool newLimitCollectionCreation,
|
||||
bool newLimitCollectionDeletion,
|
||||
bool newLimitItemDeletion,
|
||||
bool newAllowAdminAccessToAllCollectionItems,
|
||||
Organization existingOrganization, SutProvider<OrganizationService> sutProvider)
|
||||
{
|
||||
// Arrange
|
||||
existingOrganization.LimitCollectionCreation = false;
|
||||
existingOrganization.LimitCollectionDeletion = false;
|
||||
existingOrganization.LimitItemDeletion = false;
|
||||
existingOrganization.AllowAdminAccessToAllCollectionItems = false;
|
||||
|
||||
sutProvider.GetDependency<IOrganizationRepository>()
|
||||
.GetByIdAsync(existingOrganization.Id)
|
||||
.Returns(existingOrganization);
|
||||
|
||||
var settings = new OrganizationCollectionManagementSettings
|
||||
{
|
||||
LimitCollectionCreation = newLimitCollectionCreation,
|
||||
LimitCollectionDeletion = newLimitCollectionDeletion,
|
||||
LimitItemDeletion = newLimitItemDeletion,
|
||||
AllowAdminAccessToAllCollectionItems = newAllowAdminAccessToAllCollectionItems
|
||||
};
|
||||
|
||||
// Act
|
||||
await sutProvider.Sut.UpdateCollectionManagementSettingsAsync(existingOrganization.Id, settings);
|
||||
|
||||
// Assert
|
||||
var eventService = sutProvider.GetDependency<IEventService>();
|
||||
if (newLimitCollectionCreation)
|
||||
{
|
||||
await eventService.Received(1).LogOrganizationEventAsync(
|
||||
Arg.Is<Organization>(org => org.Id == existingOrganization.Id),
|
||||
Arg.Is<EventType>(e => e == EventType.Organization_CollectionManagement_LimitCollectionCreationEnabled));
|
||||
}
|
||||
else
|
||||
{
|
||||
await eventService.DidNotReceive().LogOrganizationEventAsync(
|
||||
Arg.Is<Organization>(org => org.Id == existingOrganization.Id),
|
||||
Arg.Is<EventType>(e => e == EventType.Organization_CollectionManagement_LimitCollectionCreationEnabled));
|
||||
}
|
||||
|
||||
if (newLimitCollectionDeletion)
|
||||
{
|
||||
await eventService.Received(1).LogOrganizationEventAsync(
|
||||
Arg.Is<Organization>(org => org.Id == existingOrganization.Id),
|
||||
Arg.Is<EventType>(e => e == EventType.Organization_CollectionManagement_LimitCollectionDeletionEnabled));
|
||||
}
|
||||
else
|
||||
{
|
||||
await eventService.DidNotReceive().LogOrganizationEventAsync(
|
||||
Arg.Is<Organization>(org => org.Id == existingOrganization.Id),
|
||||
Arg.Is<EventType>(e => e == EventType.Organization_CollectionManagement_LimitCollectionDeletionEnabled));
|
||||
}
|
||||
|
||||
if (newLimitItemDeletion)
|
||||
{
|
||||
await eventService.Received(1).LogOrganizationEventAsync(
|
||||
Arg.Is<Organization>(org => org.Id == existingOrganization.Id),
|
||||
Arg.Is<EventType>(e => e == EventType.Organization_CollectionManagement_LimitItemDeletionEnabled));
|
||||
}
|
||||
else
|
||||
{
|
||||
await eventService.DidNotReceive().LogOrganizationEventAsync(
|
||||
Arg.Is<Organization>(org => org.Id == existingOrganization.Id),
|
||||
Arg.Is<EventType>(e => e == EventType.Organization_CollectionManagement_LimitItemDeletionEnabled));
|
||||
}
|
||||
|
||||
if (newAllowAdminAccessToAllCollectionItems)
|
||||
{
|
||||
await eventService.Received(1).LogOrganizationEventAsync(
|
||||
Arg.Is<Organization>(org => org.Id == existingOrganization.Id),
|
||||
Arg.Is<EventType>(e => e == EventType.Organization_CollectionManagement_AllowAdminAccessToAllCollectionItemsEnabled));
|
||||
}
|
||||
else
|
||||
{
|
||||
await eventService.DidNotReceive().LogOrganizationEventAsync(
|
||||
Arg.Is<Organization>(org => org.Id == existingOrganization.Id),
|
||||
Arg.Is<EventType>(e => e == EventType.Organization_CollectionManagement_AllowAdminAccessToAllCollectionItemsEnabled));
|
||||
}
|
||||
}
|
||||
|
||||
[Theory, BitAutoData]
|
||||
public async Task UpdateCollectionManagementSettingsAsync_WhenOrganizationNotFound_ThrowsNotFoundException(
|
||||
Guid organizationId, OrganizationCollectionManagementSettings settings, SutProvider<OrganizationService> sutProvider)
|
||||
{
|
||||
// Arrange
|
||||
sutProvider.GetDependency<IOrganizationRepository>()
|
||||
.GetByIdAsync(organizationId)
|
||||
.Returns((Organization)null);
|
||||
|
||||
// Act/Assert
|
||||
await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.UpdateCollectionManagementSettingsAsync(organizationId, settings));
|
||||
|
||||
await sutProvider.GetDependency<IOrganizationRepository>()
|
||||
.Received(1)
|
||||
.GetByIdAsync(organizationId);
|
||||
}
|
||||
|
||||
// Must set real guids in order for dictionary of guids to not throw aggregate exceptions
|
||||
private void SetupOrgUserRepositoryCreateManyAsyncMock(IOrganizationUserRepository organizationUserRepository)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Security.Claims;
|
||||
using Bit.Core.Auth.Identity;
|
||||
using Bit.Core.Auth.UserFeatures.SendAccess;
|
||||
using Bit.Core.Identity;
|
||||
using Xunit;
|
||||
|
||||
namespace Bit.Core.Test.Auth.UserFeatures.SendAccess;
|
||||
|
||||
Reference in New Issue
Block a user