mirror of
https://github.com/bitwarden/server.git
synced 2025-02-27 03:41:30 +01:00
* remove validation from 2fa GET and mask sensitive data
* skip verification check on put email
* disable verification on send-email and reenable on put email
* validate authenticator on set instead of get
* Revert "validate authenticator on set instead of get"
This reverts commit 7bf2084531
.
* fix tests
* fix more tests
* Narrow scope of verify bypass
* Defaulted to false on VerifySecretAsync
* fix default param value
---------
Co-authored-by: Ike Kottlowski <ikottlowski@bitwarden.com>
Co-authored-by: Todd Martin <tmartin@bitwarden.com>
110 lines
3.2 KiB
C#
110 lines
3.2 KiB
C#
|
|
using Bit.Api.Auth.Models.Response.TwoFactor;
|
|
using Bit.Core.Entities;
|
|
using Bit.Test.Common.AutoFixture.Attributes;
|
|
using Xunit;
|
|
|
|
namespace Bit.Api.Test.Auth.Models.Response;
|
|
|
|
public class UserTwoFactorDuoResponseModelTests
|
|
{
|
|
[Theory]
|
|
[BitAutoData]
|
|
public void User_WithDuoV4_ShouldBuildModel(User user)
|
|
{
|
|
// Arrange
|
|
user.TwoFactorProviders = GetTwoFactorDuoV4ProvidersJson();
|
|
|
|
// Act
|
|
var model = new TwoFactorDuoResponseModel(user);
|
|
|
|
// Assert if v4 data Ikey and Skey are set to clientId and clientSecret
|
|
Assert.NotNull(model);
|
|
Assert.Equal("clientId", model.ClientId);
|
|
Assert.Equal("secret************", model.ClientSecret);
|
|
Assert.Equal("clientId", model.IntegrationKey);
|
|
Assert.Equal("secret************", model.SecretKey);
|
|
}
|
|
|
|
[Theory]
|
|
[BitAutoData]
|
|
public void User_WithDuov2_ShouldBuildModel(User user)
|
|
{
|
|
// Arrange
|
|
user.TwoFactorProviders = GetTwoFactorDuoV2ProvidersJson();
|
|
|
|
// Act
|
|
var model = new TwoFactorDuoResponseModel(user);
|
|
|
|
// Assert if only v2 data clientId and clientSecret are set to Ikey and Skey
|
|
Assert.NotNull(model);
|
|
Assert.Equal("IKey", model.ClientId);
|
|
Assert.Equal("SKey", model.ClientSecret);
|
|
Assert.Equal("IKey", model.IntegrationKey);
|
|
Assert.Equal("SKey", model.SecretKey);
|
|
}
|
|
|
|
[Theory]
|
|
[BitAutoData]
|
|
public void User_WithDuo_ShouldBuildModel(User user)
|
|
{
|
|
// Arrange
|
|
user.TwoFactorProviders = GetTwoFactorDuoProvidersJson();
|
|
|
|
// Act
|
|
var model = new TwoFactorDuoResponseModel(user);
|
|
|
|
// Assert Even if both versions are present priority is given to v4 data
|
|
Assert.NotNull(model);
|
|
Assert.Equal("clientId", model.ClientId);
|
|
Assert.Equal("secret************", model.ClientSecret);
|
|
Assert.Equal("clientId", model.IntegrationKey);
|
|
Assert.Equal("secret************", model.SecretKey);
|
|
}
|
|
|
|
[Theory]
|
|
[BitAutoData]
|
|
public void User_WithDuoEmpty_ShouldFail(User user)
|
|
{
|
|
// Arrange
|
|
user.TwoFactorProviders = "{\"2\" : {}}";
|
|
|
|
// Act
|
|
var model = new TwoFactorDuoResponseModel(user);
|
|
|
|
/// Assert
|
|
Assert.False(model.Enabled);
|
|
}
|
|
|
|
[Theory]
|
|
[BitAutoData]
|
|
public void User_WithTwoFactorProvidersNull_ShouldFail(User user)
|
|
{
|
|
// Arrange
|
|
user.TwoFactorProviders = null;
|
|
|
|
// Act
|
|
var model = new TwoFactorDuoResponseModel(user);
|
|
|
|
/// Assert
|
|
Assert.False(model.Enabled);
|
|
}
|
|
|
|
private string GetTwoFactorDuoProvidersJson()
|
|
{
|
|
return
|
|
"{\"2\":{\"Enabled\":true,\"MetaData\":{\"SKey\":\"SKey\",\"IKey\":\"IKey\",\"ClientSecret\":\"secretClientSecret\",\"ClientId\":\"clientId\",\"Host\":\"example.com\"}}}";
|
|
}
|
|
|
|
private string GetTwoFactorDuoV4ProvidersJson()
|
|
{
|
|
return
|
|
"{\"2\":{\"Enabled\":true,\"MetaData\":{\"ClientSecret\":\"secretClientSecret\",\"ClientId\":\"clientId\",\"Host\":\"example.com\"}}}";
|
|
}
|
|
|
|
private string GetTwoFactorDuoV2ProvidersJson()
|
|
{
|
|
return "{\"2\":{\"Enabled\":true,\"MetaData\":{\"SKey\":\"SKey\",\"IKey\":\"IKey\",\"Host\":\"example.com\"}}}";
|
|
}
|
|
}
|