mirror of
https://github.com/bitwarden/server
synced 2025-12-14 23:33:41 +00:00
feat(auth): email OTP validation, and generalize authentication interface - Generalized send authentication method interface - Made validate method async - Added email mail support for Handlebars - Modified email templates to match future implementation fix(auth): update constants, naming conventions, and error handling - Renamed constants for clarity - Updated claims naming convention - Fixed error message generation - Added customResponse for Rust consumption test(auth): add and fix tests for validators and email - Added tests for SendEmailOtpRequestValidator - Updated tests for SendAccessGrantValidator chore: apply dotnet formatting
55 lines
1.7 KiB
C#
55 lines
1.7 KiB
C#
using System.Security.Claims;
|
|
using Bit.Core.Auth.UserFeatures.SendAccess;
|
|
using Bit.Core.Identity;
|
|
using Xunit;
|
|
|
|
namespace Bit.Core.Test.Auth.UserFeatures.SendAccess;
|
|
|
|
public class SendAccessClaimsPrincipalExtensionsTests
|
|
{
|
|
[Fact]
|
|
public void GetSendId_ReturnsGuid_WhenClaimIsPresentAndValid()
|
|
{
|
|
// Arrange
|
|
var guid = Guid.NewGuid();
|
|
var claims = new[] { new Claim(Claims.SendAccessClaims.SendId, guid.ToString()) };
|
|
var principal = new ClaimsPrincipal(new ClaimsIdentity(claims));
|
|
|
|
// Act
|
|
var result = principal.GetSendId();
|
|
|
|
// Assert
|
|
Assert.Equal(guid, result);
|
|
}
|
|
|
|
[Fact]
|
|
public void GetSendId_ThrowsInvalidOperationException_WhenClaimIsMissing()
|
|
{
|
|
// Arrange
|
|
var principal = new ClaimsPrincipal(new ClaimsIdentity());
|
|
|
|
// Act & Assert
|
|
var ex = Assert.Throws<InvalidOperationException>(() => principal.GetSendId());
|
|
Assert.Equal("send_id claim not found.", ex.Message);
|
|
}
|
|
|
|
[Fact]
|
|
public void GetSendId_ThrowsInvalidOperationException_WhenClaimValueIsInvalid()
|
|
{
|
|
// Arrange
|
|
var claims = new[] { new Claim(Claims.SendAccessClaims.SendId, "not-a-guid") };
|
|
var principal = new ClaimsPrincipal(new ClaimsIdentity(claims));
|
|
|
|
// Act & Assert
|
|
var ex = Assert.Throws<InvalidOperationException>(() => principal.GetSendId());
|
|
Assert.Equal("Invalid send_id claim value.", ex.Message);
|
|
}
|
|
|
|
[Fact]
|
|
public void GetSendId_ThrowsArgumentNullException_WhenPrincipalIsNull()
|
|
{
|
|
// Act & Assert
|
|
Assert.Throws<ArgumentNullException>(() => SendAccessClaimsPrincipalExtensions.GetSendId(null));
|
|
}
|
|
}
|