Heimdall Gitea / Detect CI scope (pull_request) Successful in 6s
Heimdall Gitea / Build and tests (pull_request) Failing after 4m5s
Heimdall Gitea / Build and scan server image (pull_request) Skipped
Heimdall Gitea / Build and scan agent image (pull_request) Skipped
Heimdall Gitea / Publish Docker Hub latest tags (pull_request) Skipped
Heimdall Gitea / Publish versioned release (pull_request) Skipped
Heimdall Gitea / CI policy (pull_request) Failing after 1s
47 lines
2.0 KiB
C#
47 lines
2.0 KiB
C#
using Heimdall.Application.Auth.Commands.Verify2fa;
|
|
using Heimdall.Application.Auth.Services;
|
|
using Heimdall.Application.Common;
|
|
using Heimdall.Application.Services;
|
|
using Heimdall.Application.Tests.Common;
|
|
using Heimdall.Domain.Entities;
|
|
using Microsoft.Extensions.Logging;
|
|
using NSubstitute;
|
|
|
|
namespace Heimdall.Application.Tests.Handlers.Auth;
|
|
|
|
public class Verify2faHandlerTests
|
|
{
|
|
private readonly IIdentityAccountService _userManager;
|
|
private readonly IJwtService _jwtService;
|
|
private readonly IRolePermissionService _rolePermissionService;
|
|
private readonly IApplicationDbContext _db;
|
|
private readonly ILogger<Verify2faHandler> _logger;
|
|
private readonly Verify2faHandler _handler;
|
|
private readonly InMemoryDbSet<UserRecoveryCode> _recoveryCodes;
|
|
|
|
public Verify2faHandlerTests()
|
|
{
|
|
_userManager = Substitute.For<IIdentityAccountService>();
|
|
_jwtService = Substitute.For<IJwtService>();
|
|
_rolePermissionService = Substitute.For<IRolePermissionService>();
|
|
_rolePermissionService.GetPermissionsForRolesAsync(Arg.Any<IList<string>>(), Arg.Any<CancellationToken>())
|
|
.Returns(Task.FromResult<IList<string>>([]));
|
|
_db = Substitute.For<IApplicationDbContext>();
|
|
_logger = Substitute.For<ILogger<Verify2faHandler>>();
|
|
_recoveryCodes = (InMemoryDbSet<UserRecoveryCode>)MockDbSetHelper.CreateFor<UserRecoveryCode>();
|
|
_db.UserRecoveryCodes.Returns(_recoveryCodes);
|
|
_handler = new Verify2faHandler(_userManager, _jwtService, _rolePermissionService, _db, _logger);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("")]
|
|
[InlineData("test@test.com")]
|
|
[InlineData("123456")]
|
|
public async Task Verify2fa_without_password_challenge_is_rejected(string proof)
|
|
{
|
|
var result = await _handler.Handle(new Verify2faCommand(proof, "123456"), CancellationToken.None);
|
|
result.StatusCode.ShouldBe(401);
|
|
await _userManager.DidNotReceiveWithAnyArgs().VerifyAuthenticatorTokenAsync(Arg.Any<IdentityAccount>(), Arg.Any<string>(), Arg.Any<CancellationToken>());
|
|
}
|
|
}
|