1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-01 13:43:23 +01:00
bitwarden-server/test/Api.Test/Auth/Models/Request/TwoFactorDuoRequestModelValidationTests.cs
Ike 97b3f3e7ee
[PM-5216] User and Organization Duo Request and Response Model refactor (#4126)
* inital changes

* add provider GatewayType migrations

* db provider migrations

* removed duo migrations added v2 metadata to duo response

* removed helper scripts

* remove signature from org duo

* added backward compatibility for Duo v2

* added tests for duo request + response models

* refactors to TwoFactorController

* updated test methods to be compartmentalized by usage

* fix organization add duo

* Assert.Empty() fix for validator
2024-06-05 11:42:02 -07:00

68 lines
1.9 KiB
C#

using System.ComponentModel.DataAnnotations;
using Bit.Api.Auth.Models.Request;
using Xunit;
namespace Bit.Api.Test.Auth.Models.Request;
public class TwoFactorDuoRequestModelValidationTests
{
[Fact]
public void ShouldReturnValidationError_WhenHostIsInvalid()
{
// Arrange
var model = new UpdateTwoFactorDuoRequestModel
{
Host = "invalidHost",
ClientId = "clientId",
ClientSecret = "clientSecret",
};
// Act
var result = model.Validate(new ValidationContext(model));
// Assert
Assert.Single(result);
Assert.Equal("Host is invalid.", result.First().ErrorMessage);
Assert.Equal("Host", result.First().MemberNames.First());
}
[Fact]
public void ShouldReturnValidationError_WhenValuesAreInvalid()
{
// Arrange
var model = new UpdateTwoFactorDuoRequestModel
{
Host = "api-12345abc.duosecurity.com"
};
// Act
var result = model.Validate(new ValidationContext(model));
// Assert
Assert.Single(result);
Assert.Equal("Neither v2 or v4 values are valid.", result.First().ErrorMessage);
Assert.Contains("ClientId", result.First().MemberNames);
Assert.Contains("ClientSecret", result.First().MemberNames);
Assert.Contains("IntegrationKey", result.First().MemberNames);
Assert.Contains("SecretKey", result.First().MemberNames);
}
[Fact]
public void ShouldReturnSuccess_WhenValuesAreValid()
{
// Arrange
var model = new UpdateTwoFactorDuoRequestModel
{
Host = "api-12345abc.duosecurity.com",
ClientId = "clientId",
ClientSecret = "clientSecret",
};
// Act
var result = model.Validate(new ValidationContext(model));
// Assert
Assert.Empty(result);
}
}