2025-11-06 11:35:07 +00:00
|
|
|
|
using Bit.Api.AdminConsole.Public.Controllers;
|
|
|
|
|
|
using Bit.Api.AdminConsole.Public.Models.Request;
|
|
|
|
|
|
using Bit.Core.AdminConsole.Entities;
|
|
|
|
|
|
using Bit.Core.AdminConsole.Enums;
|
|
|
|
|
|
using Bit.Core.AdminConsole.Models.Data;
|
|
|
|
|
|
using Bit.Core.AdminConsole.OrganizationFeatures.Policies.Models;
|
|
|
|
|
|
using Bit.Core.AdminConsole.OrganizationFeatures.Policies.PolicyUpdateEvents.Interfaces;
|
|
|
|
|
|
using Bit.Core.Context;
|
|
|
|
|
|
using Bit.Test.Common.AutoFixture;
|
|
|
|
|
|
using Bit.Test.Common.AutoFixture.Attributes;
|
|
|
|
|
|
using NSubstitute;
|
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Bit.Api.Test.AdminConsole.Public.Controllers;
|
|
|
|
|
|
|
|
|
|
|
|
[ControllerCustomize(typeof(PoliciesController))]
|
|
|
|
|
|
[SutProviderCustomize]
|
|
|
|
|
|
public class PoliciesControllerTests
|
|
|
|
|
|
{
|
|
|
|
|
|
[Theory]
|
|
|
|
|
|
[BitAutoData]
|
[PM-26426] [PM-26427] Remove feature flag - policy validators/requirements refactor (#6674)
* chore: remove ff from PoliciesController, refs PM-26426
* chore: remove ff from public PoliciesController, refs PM-26426
* chore: remove ff from VerifyOrganizationDomainCommands, refs PM-26426
* chore: remove ff from SsoConfigService, refs PM-26426
* chore: remove ff from public PoliciesControllerTests, refs PM-26426
* chore: remove ff from PoliciesControllerTests, refs PM-26426
* chore: remove ff from VerifyOrganizationDomainCommandTests, refs PM-26426
* chore: remove ff from SsoConfigServiceTests, refs PM-26426
* chore: remove ff definition, refs PM-26427
* chore: dotnet format
* chore: remove unused constructor parameters, refs PM-26426
* chore: fix failing tests for VerifyOrganizationDomainCommandTests and SsoConfigServiceTests, refs PM-26426
2025-12-03 10:42:54 -06:00
|
|
|
|
public async Task Put_UsesVNextSavePolicyCommand(
|
2025-11-06 11:35:07 +00:00
|
|
|
|
Guid organizationId,
|
|
|
|
|
|
PolicyType policyType,
|
|
|
|
|
|
PolicyUpdateRequestModel model,
|
|
|
|
|
|
Policy policy,
|
|
|
|
|
|
SutProvider<PoliciesController> sutProvider)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
|
|
|
|
|
policy.Data = null;
|
|
|
|
|
|
sutProvider.GetDependency<ICurrentContext>()
|
|
|
|
|
|
.OrganizationId.Returns(organizationId);
|
|
|
|
|
|
sutProvider.GetDependency<IVNextSavePolicyCommand>()
|
|
|
|
|
|
.SaveAsync(Arg.Any<SavePolicyModel>())
|
|
|
|
|
|
.Returns(policy);
|
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
|
await sutProvider.Sut.Put(policyType, model);
|
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
await sutProvider.GetDependency<IVNextSavePolicyCommand>()
|
|
|
|
|
|
.Received(1)
|
|
|
|
|
|
.SaveAsync(Arg.Is<SavePolicyModel>(m =>
|
|
|
|
|
|
m.PolicyUpdate.OrganizationId == organizationId &&
|
|
|
|
|
|
m.PolicyUpdate.Type == policyType &&
|
|
|
|
|
|
m.PolicyUpdate.Enabled == model.Enabled.GetValueOrDefault() &&
|
|
|
|
|
|
m.PerformedBy is SystemUser));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|