mirror of
https://github.com/bitwarden/server.git
synced 2026-01-31 06:03:12 +08:00
* Initial implementation of new policy query * Remove unused using * Adjusts method name to better match repository method * Correct namespace * Initial refactor of policy loading * Add xml doc, incorporate shim data model * Updates usages to reflect new shim model * Prune extranneous data from policy detail response model, format code * Fix broken test, delete inapplicable test * Adds test cases covering query * Adjust codebase to use new PolicyQueryçˆ * Format code * Fix incorrect mock on test * Fix formatting * Adjust method name * More naming adjustments * Add PolicyData constructor, update test usages * Rename PolicyData -> PolicyStatus * Remove unused using
58 lines
2.1 KiB
C#
58 lines
2.1 KiB
C#
using Bit.Api.AdminConsole.Models.Response.Helpers;
|
|
using Bit.Core.AdminConsole.Enums;
|
|
using Bit.Core.AdminConsole.Models.Data.Organizations.Policies;
|
|
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationDomains.Interfaces;
|
|
using NSubstitute;
|
|
using Xunit;
|
|
|
|
namespace Bit.Api.Test.AdminConsole.Models.Response.Helpers;
|
|
|
|
public class PolicyStatusResponsesTests
|
|
{
|
|
[Theory]
|
|
[InlineData(true, false)]
|
|
[InlineData(false, true)]
|
|
public async Task GetSingleOrgPolicyDetailResponseAsync_WhenIsSingleOrgTypeAndHasVerifiedDomains_ShouldReturnExpectedToggleState(
|
|
bool policyEnabled,
|
|
bool expectedCanToggle)
|
|
{
|
|
var policy = new PolicyStatus(Guid.NewGuid(), PolicyType.SingleOrg) { Enabled = policyEnabled };
|
|
|
|
var querySub = Substitute.For<IOrganizationHasVerifiedDomainsQuery>();
|
|
querySub.HasVerifiedDomainsAsync(policy.OrganizationId)
|
|
.Returns(true);
|
|
|
|
var result = await policy.GetSingleOrgPolicyStatusResponseAsync(querySub);
|
|
|
|
Assert.Equal(expectedCanToggle, result.CanToggleState);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetSingleOrgPolicyDetailResponseAsync_WhenIsNotSingleOrgType_ThenShouldThrowArgumentException()
|
|
{
|
|
var policy = new PolicyStatus(Guid.NewGuid(), PolicyType.TwoFactorAuthentication);
|
|
|
|
var querySub = Substitute.For<IOrganizationHasVerifiedDomainsQuery>();
|
|
querySub.HasVerifiedDomainsAsync(policy.OrganizationId)
|
|
.Returns(true);
|
|
|
|
var action = async () => await policy.GetSingleOrgPolicyStatusResponseAsync(querySub);
|
|
|
|
await Assert.ThrowsAsync<ArgumentException>("policy", action);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetSingleOrgPolicyDetailResponseAsync_WhenIsSingleOrgTypeAndDoesNotHaveVerifiedDomains_ThenShouldBeAbleToToggle()
|
|
{
|
|
var policy = new PolicyStatus(Guid.NewGuid(), PolicyType.SingleOrg);
|
|
|
|
var querySub = Substitute.For<IOrganizationHasVerifiedDomainsQuery>();
|
|
querySub.HasVerifiedDomainsAsync(policy.OrganizationId)
|
|
.Returns(false);
|
|
|
|
var result = await policy.GetSingleOrgPolicyStatusResponseAsync(querySub);
|
|
|
|
Assert.True(result.CanToggleState);
|
|
}
|
|
}
|