UDT-002: Logout + Refresh Token con rotación y chain revocation #3

Merged
dmolinari merged 36 commits from feature/UDT-002 into main 2026-04-14 17:37:47 +00:00
Showing only changes of commit 15a7687e4c - Show all commits

View File

@@ -0,0 +1,39 @@
using NSubstitute;
using SIGCM2.Application.Abstractions.Persistence;
using SIGCM2.Application.Auth.Logout;
namespace SIGCM2.Application.Tests.Auth.Logout;
public class LogoutCommandHandlerTests
{
private readonly IRefreshTokenRepository _refreshRepo = Substitute.For<IRefreshTokenRepository>();
private readonly LogoutCommandHandler _handler;
public LogoutCommandHandlerTests()
{
_handler = new LogoutCommandHandler(_refreshRepo);
}
[Fact]
public async Task Handle_RevokesAllActiveForUser()
{
_refreshRepo.RevokeAllActiveForUserAsync(42, Arg.Any<DateTime>()).Returns(3);
var result = await _handler.Handle(new LogoutCommand(42));
Assert.True(result.Success);
Assert.False(string.IsNullOrWhiteSpace(result.Mensaje));
await _refreshRepo.Received(1).RevokeAllActiveForUserAsync(42, Arg.Any<DateTime>());
}
[Fact]
public async Task Handle_NoActiveTokens_StillReturnsSuccess()
{
// 0 rows affected = idempotent logout
_refreshRepo.RevokeAllActiveForUserAsync(Arg.Any<int>(), Arg.Any<DateTime>()).Returns(0);
var result = await _handler.Handle(new LogoutCommand(99));
Assert.True(result.Success);
}
}