Skip to content

Commit 5d504bd

Browse files
committed
fix: 빌드 오류 수정 - API 인터페이스 호환성 개선
문제점: - 세션 검증에서 존재하지 않는 SessionInfo 프로퍼티 사용 - JwtProvider 생성자 변경으로 테스트 코드 오류 - WebSocketMessageType.Pong 미지원 - AuthResult.User null 허용 불가 수정사항: - SessionInfo 실제 구조에 맞춰 세션 검증 로직 단순화 - JwtProviderTests에 Mock ILogger 추가 - WebSocket Pong → Binary 메시지 처리로 변경 - AuthResult.User를 nullable로 변경 - 기존 ErrorCode.SESSION_EXPIRED 사용
1 parent 1ad19fa commit 5d504bd

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

ProjectVG.Api/Middleware/WebSocketMiddleware.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,9 @@ await socket.SendAsync(
135135
break;
136136
}
137137

138-
if (result.MessageType == WebSocketMessageType.Pong) {
139-
_logger.LogDebug("Pong 받음: {UserId}", userId);
138+
// WebSocket의 기본 제어 메시지들 처리
139+
if (result.MessageType == WebSocketMessageType.Binary) {
140+
_logger.LogDebug("Binary 메시지 받음: {UserId}", userId);
140141
continue;
141142
}
142143

ProjectVG.Application/Services/Auth/IUserAuthService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ public class AuthResult
4242
public TokenResponse Tokens { get; set; } = null!;
4343

4444
/// <summary>사용자 정보</summary>
45-
public UserDto User { get; set; } = null!;
45+
public UserDto? User { get; set; }
4646
}
4747
}

ProjectVG.Application/Services/Chat/Validators/ChatRequestValidator.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,16 @@ public async Task ValidateAsync(ChatRequestCommand command)
7474
private async Task ValidateUserSessionAsync(Guid userId)
7575
{
7676
try {
77-
var sessionKey = $"user_session:{userId}";
78-
var sessionData = await _sessionStorage.GetAsync<string>(sessionKey).ConfigureAwait(false);
77+
// 사용자 ID를 기반으로 세션 조회
78+
var userSessions = await _sessionStorage.GetSessionsByUserIdAsync(userId.ToString()).ConfigureAwait(false);
7979

80-
if (sessionData == null) {
80+
if (!userSessions.Any()) {
8181
_logger.LogWarning("유효하지 않은 사용자 세션: {UserId}", userId);
82-
throw new ValidationException(ErrorCode.INVALID_SESSION, "유효하지 않은 세션입니다. 다시 로그인해 주세요.");
82+
throw new ValidationException(ErrorCode.SESSION_EXPIRED, "세션이 만료되었습니다. 다시 로그인해 주세요.");
8383
}
8484

85-
// 세션이 존재한다면 마지막 활동 시간을 업데이트
86-
var lastActivity = DateTime.UtcNow.ToString("O"); // ISO 8601 format
87-
await _sessionStorage.SetAsync(sessionKey, lastActivity, TimeSpan.FromHours(2)).ConfigureAwait(false);
88-
89-
_logger.LogDebug("세션 검증 성공 및 활동 시간 업데이트: {UserId}", userId);
85+
// 세션이 존재하면 로그 기록
86+
_logger.LogDebug("세션 검증 성공: {UserId}, 활성 세션 수: {SessionCount}", userId, userSessions.Count());
9087
}
9188
catch (ValidationException) {
9289
throw; // 검증 예외는 그대로 전파

ProjectVG.Tests/Auth/JwtProviderTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace ProjectVG.Tests.Auth
1111
public class JwtProviderTests
1212
{
1313
private readonly JwtProvider _jwtProvider;
14+
private readonly Mock<ILogger<JwtProvider>> _mockLogger;
1415
private readonly string _testJwtKey = "your-super-secret-jwt-key-here-minimum-32-characters";
1516
private readonly string _testIssuer = "ProjectVG";
1617
private readonly string _testAudience = "ProjectVG";
@@ -19,12 +20,14 @@ public class JwtProviderTests
1920

2021
public JwtProviderTests()
2122
{
23+
_mockLogger = new Mock<ILogger<JwtProvider>>();
2224
_jwtProvider = new JwtProvider(
2325
_testJwtKey,
2426
_testIssuer,
2527
_testAudience,
2628
_accessTokenExpirationMinutes,
27-
_refreshTokenExpirationMinutes
29+
_refreshTokenExpirationMinutes,
30+
_mockLogger.Object
2831
);
2932
}
3033

0 commit comments

Comments
 (0)