2024-06-05 20:42:02 +02:00
|
|
|
|
|
|
|
|
|
using Bit.Api.Auth.Models.Response.TwoFactor;
|
|
|
|
|
using Bit.Core.AdminConsole.Entities;
|
|
|
|
|
using Bit.Test.Common.AutoFixture.Attributes;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace Bit.Api.Test.Auth.Models.Response;
|
|
|
|
|
|
|
|
|
|
public class OrganizationTwoFactorDuoResponseModelTests
|
|
|
|
|
{
|
|
|
|
|
[Theory]
|
|
|
|
|
[BitAutoData]
|
|
|
|
|
public void Organization_WithDuo_ShouldBuildModel(Organization organization)
|
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
organization.TwoFactorProviders = GetTwoFactorOrganizationDuoProvidersJson();
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
var model = new TwoFactorDuoResponseModel(organization);
|
|
|
|
|
|
2024-11-19 00:58:05 +01:00
|
|
|
|
// Assert
|
2024-06-05 20:42:02 +02:00
|
|
|
|
Assert.NotNull(model);
|
|
|
|
|
Assert.Equal("clientId", model.ClientId);
|
2024-07-22 17:21:14 +02:00
|
|
|
|
Assert.Equal("secret************", model.ClientSecret);
|
2024-06-05 20:42:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[BitAutoData]
|
|
|
|
|
public void Organization_WithDuoEmpty_ShouldFail(Organization organization)
|
|
|
|
|
{
|
|
|
|
|
// Arrange
|
|
|
|
|
organization.TwoFactorProviders = "{\"6\" : {}}";
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
var model = new TwoFactorDuoResponseModel(organization);
|
|
|
|
|
|
2024-11-19 00:58:05 +01:00
|
|
|
|
// Assert
|
2024-06-05 20:42:02 +02:00
|
|
|
|
Assert.False(model.Enabled);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[BitAutoData]
|
2024-11-19 00:58:05 +01:00
|
|
|
|
public void Organization_WithTwoFactorProvidersNull_ShouldThrow(Organization organization)
|
2024-06-05 20:42:02 +02:00
|
|
|
|
{
|
|
|
|
|
// Arrange
|
2024-11-19 00:58:05 +01:00
|
|
|
|
organization.TwoFactorProviders = null;
|
2024-06-05 20:42:02 +02:00
|
|
|
|
|
|
|
|
|
// Act
|
2024-11-19 00:58:05 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var model = new TwoFactorDuoResponseModel(organization);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
// Assert
|
|
|
|
|
Assert.IsType<ArgumentNullException>(ex);
|
|
|
|
|
}
|
2024-06-05 20:42:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetTwoFactorOrganizationDuoProvidersJson()
|
|
|
|
|
{
|
2024-07-22 17:21:14 +02:00
|
|
|
|
return
|
|
|
|
|
"{\"6\":{\"Enabled\":true,\"MetaData\":{\"ClientSecret\":\"secretClientSecret\",\"ClientId\":\"clientId\",\"Host\":\"example.com\"}}}";
|
2024-06-05 20:42:02 +02:00
|
|
|
|
}
|
|
|
|
|
}
|