2026-01-29 14:11:20 -06:00
|
|
|
|
using Bit.Api.AdminConsole.Models.Response.Helpers;
|
2024-11-11 09:52:42 -06:00
|
|
|
|
using Bit.Core.AdminConsole.Enums;
|
2026-01-29 14:11:20 -06:00
|
|
|
|
using Bit.Core.AdminConsole.Models.Data.Organizations.Policies;
|
2024-11-11 09:52:42 -06:00
|
|
|
|
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationDomains.Interfaces;
|
|
|
|
|
|
using NSubstitute;
|
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Bit.Api.Test.AdminConsole.Models.Response.Helpers;
|
|
|
|
|
|
|
2026-01-29 14:11:20 -06:00
|
|
|
|
public class PolicyStatusResponsesTests
|
2024-11-11 09:52:42 -06:00
|
|
|
|
{
|
2025-04-01 10:28:57 -04:00
|
|
|
|
[Theory]
|
|
|
|
|
|
[InlineData(true, false)]
|
|
|
|
|
|
[InlineData(false, true)]
|
|
|
|
|
|
public async Task GetSingleOrgPolicyDetailResponseAsync_WhenIsSingleOrgTypeAndHasVerifiedDomains_ShouldReturnExpectedToggleState(
|
|
|
|
|
|
bool policyEnabled,
|
|
|
|
|
|
bool expectedCanToggle)
|
2024-11-11 09:52:42 -06:00
|
|
|
|
{
|
2026-01-29 14:11:20 -06:00
|
|
|
|
var policy = new PolicyStatus(Guid.NewGuid(), PolicyType.SingleOrg) { Enabled = policyEnabled };
|
2024-11-11 09:52:42 -06:00
|
|
|
|
|
|
|
|
|
|
var querySub = Substitute.For<IOrganizationHasVerifiedDomainsQuery>();
|
|
|
|
|
|
querySub.HasVerifiedDomainsAsync(policy.OrganizationId)
|
|
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
2026-01-29 14:11:20 -06:00
|
|
|
|
var result = await policy.GetSingleOrgPolicyStatusResponseAsync(querySub);
|
2024-11-11 09:52:42 -06:00
|
|
|
|
|
2025-04-01 10:28:57 -04:00
|
|
|
|
Assert.Equal(expectedCanToggle, result.CanToggleState);
|
2024-11-11 09:52:42 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2025-04-01 10:28:57 -04:00
|
|
|
|
public async Task GetSingleOrgPolicyDetailResponseAsync_WhenIsNotSingleOrgType_ThenShouldThrowArgumentException()
|
2024-11-11 09:52:42 -06:00
|
|
|
|
{
|
2026-01-29 14:11:20 -06:00
|
|
|
|
var policy = new PolicyStatus(Guid.NewGuid(), PolicyType.TwoFactorAuthentication);
|
2024-11-11 09:52:42 -06:00
|
|
|
|
|
|
|
|
|
|
var querySub = Substitute.For<IOrganizationHasVerifiedDomainsQuery>();
|
|
|
|
|
|
querySub.HasVerifiedDomainsAsync(policy.OrganizationId)
|
|
|
|
|
|
.Returns(true);
|
|
|
|
|
|
|
2026-01-29 14:11:20 -06:00
|
|
|
|
var action = async () => await policy.GetSingleOrgPolicyStatusResponseAsync(querySub);
|
2024-11-11 09:52:42 -06:00
|
|
|
|
|
|
|
|
|
|
await Assert.ThrowsAsync<ArgumentException>("policy", action);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2025-04-01 10:28:57 -04:00
|
|
|
|
public async Task GetSingleOrgPolicyDetailResponseAsync_WhenIsSingleOrgTypeAndDoesNotHaveVerifiedDomains_ThenShouldBeAbleToToggle()
|
2024-11-11 09:52:42 -06:00
|
|
|
|
{
|
2026-01-29 14:11:20 -06:00
|
|
|
|
var policy = new PolicyStatus(Guid.NewGuid(), PolicyType.SingleOrg);
|
2024-11-11 09:52:42 -06:00
|
|
|
|
|
|
|
|
|
|
var querySub = Substitute.For<IOrganizationHasVerifiedDomainsQuery>();
|
|
|
|
|
|
querySub.HasVerifiedDomainsAsync(policy.OrganizationId)
|
|
|
|
|
|
.Returns(false);
|
|
|
|
|
|
|
2026-01-29 14:11:20 -06:00
|
|
|
|
var result = await policy.GetSingleOrgPolicyStatusResponseAsync(querySub);
|
2024-11-11 09:52:42 -06:00
|
|
|
|
|
|
|
|
|
|
Assert.True(result.CanToggleState);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|