mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
Implement refresh token flow and refactor session handling
Added refresh token endpoint and controller, introduced IUserSessionRefresher and UserSessionRefresher for token renewal, and updated session handling to return both access and refresh tokens. Refactored AuthController, tests, and related interfaces to support new token flow. Fixed JwtAccessOption property typo, updated configuration, and extended UserSessionsRepository to support lookup by refresh token.
This commit is contained in:
@@ -202,6 +202,41 @@ public class UserSessionsRepositoryTests
|
||||
Assert.ThrowsAsync<NotFoundByKeyException<bool>>(async () => await repository.GetByRevokedAsync(false));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Given_ValidRefreshToken_When_GetByRefreshTokenAsync_ShouldReturnSession()
|
||||
{
|
||||
// Arrange
|
||||
var random = new Random();
|
||||
var sessions = _fixture.Build<UserSession>()
|
||||
.With(f => f.IsRevoked, true)
|
||||
.CreateMany(random.Next(2, 10)).ToList();
|
||||
|
||||
var token = sessions.First().RefreshToken;
|
||||
|
||||
await using var context = new GovorDbContext(_options);
|
||||
var repository = new UserSessionsRepository(context);
|
||||
|
||||
context.UserSessions.AddRange(sessions);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
var result = await repository.GetByRefreshTokenAsync(token);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Is.EqualTo(sessions.First()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Given_InvalidRefreshToken_When_GetByRefreshTokenAsync_Should_Throw_NotFoundByKeyException()
|
||||
{
|
||||
// Arrange
|
||||
using var context = new GovorDbContext(_options);
|
||||
var repository = new UserSessionsRepository(context);
|
||||
// Act & Assert
|
||||
Assert.ThrowsAsync<NotFoundByKeyException<string>>(async () => await repository.GetByRefreshTokenAsync(_fixture.Create<string>()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Given_ValidUserSessions_When_AddAsync_Then_UserSessionsAdded()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user