diff --git a/src/main/java/clap/server/adapter/inbound/security/filter/LoginAttemptFilter.java b/src/main/java/clap/server/adapter/inbound/security/filter/LoginAttemptFilter.java index 2fd65036..7d5110f8 100644 --- a/src/main/java/clap/server/adapter/inbound/security/filter/LoginAttemptFilter.java +++ b/src/main/java/clap/server/adapter/inbound/security/filter/LoginAttemptFilter.java @@ -1,7 +1,6 @@ package clap.server.adapter.inbound.security.filter; import clap.server.application.port.inbound.auth.CheckAccountLockStatusUseCase; -import clap.server.application.service.auth.LoginAttemptService; import clap.server.exception.AuthException; import jakarta.servlet.FilterChain; import jakarta.servlet.ServletException; @@ -14,8 +13,10 @@ import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.web.authentication.WebAuthenticationDetailsSource; import org.springframework.web.filter.OncePerRequestFilter; +import org.springframework.web.util.ContentCachingRequestWrapper; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import static clap.server.adapter.inbound.security.WebSecurityUrl.LOGIN_ENDPOINT; @@ -33,9 +34,8 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse throws ServletException, IOException { try { if (request.getRequestURI().equals(LOGIN_ENDPOINT)) { - String clientIp = getClientIp(request); - - checkAccountLockStatusUseCase.checkAccountIsLocked(clientIp); + String nickname = request.getParameter("nickname"); + checkAccountLockStatusUseCase.checkAccountIsLocked(nickname); } } catch (AuthException e) { @@ -54,4 +54,14 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse filterChain.doFilter(request, response); } + private String getRequestBody(HttpServletRequest request) { + try { + ContentCachingRequestWrapper cachingRequest = (ContentCachingRequestWrapper) request; + byte[] content = cachingRequest.getContentAsByteArray(); + return new String(content, StandardCharsets.UTF_8); + } catch (Exception e) { + return "요청 바디의 내용을 읽을 수 없음"; + } + } + } diff --git a/src/main/java/clap/server/adapter/inbound/web/auth/AuthController.java b/src/main/java/clap/server/adapter/inbound/web/auth/AuthController.java index 5325a16d..5e77632f 100644 --- a/src/main/java/clap/server/adapter/inbound/web/auth/AuthController.java +++ b/src/main/java/clap/server/adapter/inbound/web/auth/AuthController.java @@ -12,6 +12,7 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.servlet.http.HttpServletRequest; +import jakarta.validation.constraints.NotBlank; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.ResponseEntity; @@ -32,11 +33,11 @@ public class AuthController { @LogType(LogStatus.LOGIN) @Operation(summary = "로그인 API") @PostMapping("/login") - public ResponseEntity login( + public ResponseEntity login(@RequestParam @NotBlank String nickname, @RequestBody LoginRequest request, HttpServletRequest httpRequest) { String clientIp = getClientIp(httpRequest); - LoginResponse response = loginUsecase.login(request.nickname(), request.password(), clientIp); + LoginResponse response = loginUsecase.login(nickname, request.password(), clientIp); return ResponseEntity.ok(response); } diff --git a/src/main/java/clap/server/adapter/inbound/web/dto/auth/request/LoginRequest.java b/src/main/java/clap/server/adapter/inbound/web/dto/auth/request/LoginRequest.java index 51e2c1e8..dccaea11 100644 --- a/src/main/java/clap/server/adapter/inbound/web/dto/auth/request/LoginRequest.java +++ b/src/main/java/clap/server/adapter/inbound/web/dto/auth/request/LoginRequest.java @@ -1,11 +1,9 @@ package clap.server.adapter.inbound.web.dto.auth.request; -import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.NotBlank; public record LoginRequest( - @NotNull - String nickname, - @NotNull + @NotBlank String password ) { } diff --git a/src/main/java/clap/server/adapter/outbound/infrastructure/redis/log/LoginLogAdapter.java b/src/main/java/clap/server/adapter/outbound/infrastructure/redis/log/LoginLogAdapter.java index e747ec65..4a2bf8ad 100644 --- a/src/main/java/clap/server/adapter/outbound/infrastructure/redis/log/LoginLogAdapter.java +++ b/src/main/java/clap/server/adapter/outbound/infrastructure/redis/log/LoginLogAdapter.java @@ -25,7 +25,8 @@ public void deleteById(String clientIp) { loginLogRepository.deleteById(clientIp); } - public Optional findByClientIp(String clientIp) { - return loginLogRepository.findById(clientIp).map(loginLogMapper::toDomain); + @Override + public Optional findByNickname(String nickname) { + return loginLogRepository.findById(nickname).map(loginLogMapper::toDomain); } } diff --git a/src/main/java/clap/server/adapter/outbound/infrastructure/redis/log/LoginLogEntity.java b/src/main/java/clap/server/adapter/outbound/infrastructure/redis/log/LoginLogEntity.java index fda27839..bab88141 100644 --- a/src/main/java/clap/server/adapter/outbound/infrastructure/redis/log/LoginLogEntity.java +++ b/src/main/java/clap/server/adapter/outbound/infrastructure/redis/log/LoginLogEntity.java @@ -14,15 +14,15 @@ import java.time.LocalDateTime; @Getter -@RedisHash("loginLog") +@RedisHash(value = "loginLog", timeToLive = 3600) @Builder -@ToString(of = {"clientIp", "attemptNickname", "lastAttemptAt", "failedCount", "isLocked"}) -@EqualsAndHashCode(of = {"clientIp"}) +@ToString(of = {"nickname", "clientIp", "lastAttemptAt", "failedCount", "isLocked"}) +@EqualsAndHashCode(of = {"nickname"}) public class LoginLogEntity { @Id - private String clientIp; + private String nickname; - private String attemptNickname; + private String clientIp; @JsonSerialize(using = ToStringSerializer.class) @JsonDeserialize(using = LocalDateTimeDeserializer.class) diff --git a/src/main/java/clap/server/adapter/outbound/persistense/CategoryPersistenceAdapter.java b/src/main/java/clap/server/adapter/outbound/persistense/CategoryPersistenceAdapter.java index ed9f1a7f..e99883db 100644 --- a/src/main/java/clap/server/adapter/outbound/persistense/CategoryPersistenceAdapter.java +++ b/src/main/java/clap/server/adapter/outbound/persistense/CategoryPersistenceAdapter.java @@ -51,7 +51,7 @@ public List findSubCategory() { @Override public boolean existsByNameOrCode(String name, String code) { - return categoryRepository.existsByNameOrCode(name, code); + return categoryRepository.existsByNameOrCodeAndIsDeletedFalse(name, code); } @Override diff --git a/src/main/java/clap/server/adapter/outbound/persistense/repository/task/CategoryRepository.java b/src/main/java/clap/server/adapter/outbound/persistense/repository/task/CategoryRepository.java index a5bec1e3..5cdcc2b1 100644 --- a/src/main/java/clap/server/adapter/outbound/persistense/repository/task/CategoryRepository.java +++ b/src/main/java/clap/server/adapter/outbound/persistense/repository/task/CategoryRepository.java @@ -12,5 +12,5 @@ public interface CategoryRepository extends JpaRepository List findByIsDeletedFalseAndMainCategoryIsNull(); List findByIsDeletedFalseAndMainCategoryIsNotNull(); - boolean existsByNameOrCode(String name, String code); + boolean existsByNameOrCodeAndIsDeletedFalse(String name, String code); } \ No newline at end of file diff --git a/src/main/java/clap/server/application/port/inbound/auth/CheckAccountLockStatusUseCase.java b/src/main/java/clap/server/application/port/inbound/auth/CheckAccountLockStatusUseCase.java index d102e1ab..05f5d3f7 100644 --- a/src/main/java/clap/server/application/port/inbound/auth/CheckAccountLockStatusUseCase.java +++ b/src/main/java/clap/server/application/port/inbound/auth/CheckAccountLockStatusUseCase.java @@ -1,5 +1,5 @@ package clap.server.application.port.inbound.auth; public interface CheckAccountLockStatusUseCase { - void checkAccountIsLocked(String clientIp); + void checkAccountIsLocked(String nickname); } diff --git a/src/main/java/clap/server/application/port/outbound/auth/loginLog/LoadLoginLogPort.java b/src/main/java/clap/server/application/port/outbound/auth/loginLog/LoadLoginLogPort.java index 66c73d42..5e3d1384 100644 --- a/src/main/java/clap/server/application/port/outbound/auth/loginLog/LoadLoginLogPort.java +++ b/src/main/java/clap/server/application/port/outbound/auth/loginLog/LoadLoginLogPort.java @@ -5,5 +5,5 @@ import java.util.Optional; public interface LoadLoginLogPort { - Optional findByClientIp(String clientIp); + Optional findByNickname(String nickname); } diff --git a/src/main/java/clap/server/application/service/admin/UpdateCategoryService.java b/src/main/java/clap/server/application/service/admin/UpdateCategoryService.java index 29ac6249..cae97710 100644 --- a/src/main/java/clap/server/application/service/admin/UpdateCategoryService.java +++ b/src/main/java/clap/server/application/service/admin/UpdateCategoryService.java @@ -12,6 +12,7 @@ import org.springframework.transaction.annotation.Transactional; import static clap.server.exception.code.MemberErrorCode.ACTIVE_MEMBER_NOT_FOUND; +import static clap.server.exception.code.TaskErrorCode.CATEGORY_DUPLICATE; import static clap.server.exception.code.TaskErrorCode.CATEGORY_NOT_FOUND; @ApplicationService @@ -25,6 +26,7 @@ public class UpdateCategoryService implements UpdateCategoryUsecase { @Transactional public void updateCategory(Long adminId, Long categoryId, String name, String code, String descriptionExample) { Member admin = loadMemberPort.findActiveMemberById(adminId).orElseThrow(() -> new ApplicationException(ACTIVE_MEMBER_NOT_FOUND)); + if (loadCategoryPort.existsByNameOrCode(name, code)) throw new ApplicationException(CATEGORY_DUPLICATE); Category category = loadCategoryPort.findById(categoryId) .orElseThrow(() -> new ApplicationException(CATEGORY_NOT_FOUND)); category.updateCategory(admin, name, code, descriptionExample); diff --git a/src/main/java/clap/server/application/service/auth/AuthService.java b/src/main/java/clap/server/application/service/auth/AuthService.java index 6aa030ac..75b4667c 100644 --- a/src/main/java/clap/server/application/service/auth/AuthService.java +++ b/src/main/java/clap/server/application/service/auth/AuthService.java @@ -46,7 +46,7 @@ public LoginResponse login(String nickname, String password, String clientIp) { CustomJwts jwtTokens = manageTokenService.issueTokens(member); refreshTokenService.saveRefreshToken(manageTokenService.issueRefreshToken(member.getMemberId())); - loginAttemptService.resetFailedAttempts(clientIp); + loginAttemptService.resetFailedAttempts(nickname); return AuthResponseMapper.toLoginResponse(jwtTokens.accessToken(), jwtTokens.refreshToken()); } @@ -71,14 +71,14 @@ private void deleteAccessToken(Long memberId, String accessToken) { private Member getMember(String inputNickname, String clientIp) { return loadMemberPort.findByNickname(inputNickname).orElseThrow(() -> { - loginAttemptService.recordFailedAttempt(clientIp, inputNickname); + loginAttemptService.recordFailedAttempt(inputNickname, clientIp); return new AuthException(AuthErrorCode.LOGIN_REQUEST_FAILED); }); } private void validatePassword(String inputPassword, String encodedPassword, String inputNickname, String clientIp) { if (!passwordEncoder.matches(inputPassword, encodedPassword)) { - loginAttemptService.recordFailedAttempt(clientIp, inputNickname); + loginAttemptService.recordFailedAttempt(inputNickname, clientIp); throw new AuthException(AuthErrorCode.LOGIN_REQUEST_FAILED); } } diff --git a/src/main/java/clap/server/application/service/auth/LoginAttemptService.java b/src/main/java/clap/server/application/service/auth/LoginAttemptService.java index 282cbb6d..415724b2 100644 --- a/src/main/java/clap/server/application/service/auth/LoginAttemptService.java +++ b/src/main/java/clap/server/application/service/auth/LoginAttemptService.java @@ -22,10 +22,10 @@ public class LoginAttemptService implements CheckAccountLockStatusUseCase { private static final int MAX_FAILED_ATTEMPTS = 5; private static final long LOCK_TIME_DURATION = 30 * 60 * 1000; // 30분 (밀리초) - public void recordFailedAttempt(String clientIp, String attemptNickname) { - LoginLog loginLog = loadLoginLogPort.findByClientIp(clientIp).orElse(null); + public void recordFailedAttempt(String nickname, String clientIp) { + LoginLog loginLog = loadLoginLogPort.findByNickname(nickname).orElse(null); if (loginLog == null) { - loginLog = LoginLog.createLoginLog(clientIp, attemptNickname); + loginLog = LoginLog.createLoginLog(nickname, clientIp); } else { int attemptCount = loginLog.recordFailedAttempt(); if (attemptCount >= MAX_FAILED_ATTEMPTS) { @@ -38,8 +38,8 @@ public void recordFailedAttempt(String clientIp, String attemptNickname) { } @Override - public void checkAccountIsLocked(String clientIp) { - LoginLog loginLog = loadLoginLogPort.findByClientIp(clientIp).orElse(null); + public void checkAccountIsLocked(String nickname) { + LoginLog loginLog = loadLoginLogPort.findByNickname(nickname).orElse(null); if (loginLog == null) { return; } @@ -53,12 +53,12 @@ public void checkAccountIsLocked(String clientIp) { if (minutesSinceLastAttemptInMillis <= LOCK_TIME_DURATION) { throw new AuthException(AuthErrorCode.ACCOUNT_IS_LOCKED); } - else commandLoginLogPort.deleteById(clientIp); + else commandLoginLogPort.deleteById(nickname); } } - public void resetFailedAttempts(String clientIp) { - commandLoginLogPort.deleteById(clientIp); + public void resetFailedAttempts(String nickname) { + commandLoginLogPort.deleteById(nickname); } } diff --git a/src/main/java/clap/server/application/service/log/LogService.java b/src/main/java/clap/server/application/service/log/LogService.java index 5d527820..019ef2ba 100644 --- a/src/main/java/clap/server/application/service/log/LogService.java +++ b/src/main/java/clap/server/application/service/log/LogService.java @@ -35,7 +35,7 @@ public void createMemberLog(HttpServletRequest request, int statusCode, String c } public void createLoginFailedLog(HttpServletRequest request, int statusCode, String customCode, LogStatus logStatus, String requestBody, String nickName) { - LoginLog loginLog = loadLoginLogPort.findByClientIp(ClientIpParseUtil.getClientIp(request)).orElse(null); + LoginLog loginLog = loadLoginLogPort.findByNickname(nickName).orElse(null); String responseBody = loginLog != null ? loginLog.toSummaryString() : null; AnonymousLog anonymousLog = AnonymousLog.createAnonymousLog(request, statusCode,customCode, logStatus, responseBody, requestBody, nickName); commandLogPort.saveAnonymousLog(anonymousLog); diff --git a/src/main/java/clap/server/config/security/SecurityFilterConfig.java b/src/main/java/clap/server/config/security/SecurityFilterConfig.java index e3994c5a..6be22d7d 100644 --- a/src/main/java/clap/server/config/security/SecurityFilterConfig.java +++ b/src/main/java/clap/server/config/security/SecurityFilterConfig.java @@ -6,6 +6,7 @@ import clap.server.application.port.outbound.auth.forbidden.ForbiddenTokenPort; import clap.server.application.port.outbound.auth.JwtProvider; import clap.server.application.service.auth.LoginAttemptService; +import com.fasterxml.jackson.databind.ObjectMapper; import lombok.AccessLevel; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; diff --git a/src/main/java/clap/server/domain/model/auth/LoginLog.java b/src/main/java/clap/server/domain/model/auth/LoginLog.java index 29792ede..887dbb0d 100644 --- a/src/main/java/clap/server/domain/model/auth/LoginLog.java +++ b/src/main/java/clap/server/domain/model/auth/LoginLog.java @@ -11,35 +11,35 @@ @SuperBuilder @NoArgsConstructor(access = AccessLevel.PROTECTED) public class LoginLog { - private String clientIp; - private String attemptNickname; - private LocalDateTime lastAttemptAt; - private int failedCount; - private boolean isLocked; + private String nickname; + private String clientIp; + private LocalDateTime lastAttemptAt; + private int failedCount; + private boolean isLocked; - public static LoginLog createLoginLog(String clientIp, String attemptNickname) { - return LoginLog.builder() - .clientIp(clientIp) - .attemptNickname(attemptNickname) - .lastAttemptAt(LocalDateTime.now()) - .failedCount(1) - .isLocked(false) - .build(); - } + public static LoginLog createLoginLog(String nickname, String clientIp) { + return LoginLog.builder() + .nickname(nickname) + .clientIp(clientIp) + .lastAttemptAt(LocalDateTime.now()) + .failedCount(1) + .isLocked(false) + .build(); + } - public int recordFailedAttempt() { - this.failedCount++; - return this.failedCount; - } + public int recordFailedAttempt() { + this.failedCount++; + return this.failedCount; + } - public void setLocked(boolean locked) { - isLocked = locked; - } + public void setLocked(boolean locked) { + isLocked = locked; + } - public String toSummaryString() { - return "{" + - ", failedCount=" + failedCount + - ", isLocked=" + isLocked + - '}'; - } + public String toSummaryString() { + return "{" + + "failedCount=" + failedCount + + ", isLocked=" + isLocked + + '}'; + } } diff --git a/src/main/java/clap/server/domain/policy/member/ManagerDepartmentPolicy.java b/src/main/java/clap/server/domain/policy/member/ManagerDepartmentPolicy.java index 08f8f6c1..4b92d3f1 100644 --- a/src/main/java/clap/server/domain/policy/member/ManagerDepartmentPolicy.java +++ b/src/main/java/clap/server/domain/policy/member/ManagerDepartmentPolicy.java @@ -9,9 +9,10 @@ @Policy public class ManagerDepartmentPolicy { public void validateDepartment(final Department department, final MemberRole memberRole) { - if (!(department.isManager() - && memberRole == MemberRole.ROLE_MANAGER)) { - throw new DomainException(MemberErrorCode.MANAGER_PERMISSION_DENIED); + if (!department.isManager() ){ + if(memberRole == MemberRole.ROLE_MANAGER){ + throw new DomainException(MemberErrorCode.MANAGER_PERMISSION_DENIED); + } } } } diff --git a/src/test/java/clap/server/application/service/auth/AuthServiceTest.java b/src/test/java/clap/server/application/service/auth/AuthServiceTest.java index b090fbd6..ca836ba8 100644 --- a/src/test/java/clap/server/application/service/auth/AuthServiceTest.java +++ b/src/test/java/clap/server/application/service/auth/AuthServiceTest.java @@ -67,7 +67,7 @@ void loginSuccess() { assertNotNull(response); assertEquals(jwtTokens.accessToken(), response.accessToken()); assertEquals(jwtTokens.refreshToken(), response.refreshToken()); - verify(loginAttemptService).resetFailedAttempts(clientIp); + verify(loginAttemptService).resetFailedAttempts(nickname); verify(refreshTokenService).saveRefreshToken(any()); } @@ -85,7 +85,7 @@ void loginFailureWrongPassword() { // When & Then assertThrows(AuthException.class, () -> authService.login(nickname, inputPassword, clientIp)); - verify(loginAttemptService).recordFailedAttempt(clientIp, nickname); + verify(loginAttemptService).recordFailedAttempt(nickname, clientIp); } diff --git a/src/test/java/clap/server/application/service/auth/LoginAttemptServiceTest.java b/src/test/java/clap/server/application/service/auth/LoginAttemptServiceTest.java index 5bfdc524..c22581cd 100644 --- a/src/test/java/clap/server/application/service/auth/LoginAttemptServiceTest.java +++ b/src/test/java/clap/server/application/service/auth/LoginAttemptServiceTest.java @@ -31,14 +31,15 @@ class LoginAttemptServiceTest { @Mock private CommandLoginLogPort commandLoginLogPort; - private final String clientIp = "192.168.1.1"; + private static final String nickname = "testUser"; + private static final String clientIp = "192.168.1.1"; private LoginLog existingLoginLog; private LoginLog lockedAccountLoginLog; private LoginLog lockTimeExpiredLoginLog; - public static LoginLog createLoginLog(String clientIp, int count, boolean isLocked, LocalDateTime lastAttemptAt){ + public static LoginLog createLoginLog(int count, boolean isLocked, LocalDateTime lastAttemptAt){ return LoginLog.builder() - .attemptNickname("testUser") + .nickname(nickname) .lastAttemptAt(lastAttemptAt) .failedCount(count) .isLocked(isLocked) @@ -48,18 +49,18 @@ public static LoginLog createLoginLog(String clientIp, int count, boolean isLock @BeforeEach void setUp() { - existingLoginLog = createLoginLog(clientIp, 3, false, LocalDateTime.now()); - lockedAccountLoginLog = createLoginLog(clientIp, 5, true, LocalDateTime.now()); - lockTimeExpiredLoginLog = createLoginLog(clientIp, 5, true, LocalDateTime.now().minusMinutes(31)); + existingLoginLog = createLoginLog(3, false, LocalDateTime.now()); + lockedAccountLoginLog = createLoginLog(5, true, LocalDateTime.now()); + lockTimeExpiredLoginLog = createLoginLog(5, true, LocalDateTime.now().minusMinutes(31)); } @Test - @DisplayName("로그인에 실패하면 IP를 통해 로그인 실패 기록이 저장된다.") + @DisplayName("로그인에 실패하면 nickname을 통해 로그인 실패 기록이 저장된다.") void recordFailedAttempt_NewIP() { String nickname = "testUser"; - when(loadLoginLogPort.findByClientIp(clientIp)).thenReturn(Optional.empty()); + when(loadLoginLogPort.findByNickname(nickname)).thenReturn(Optional.empty()); - loginAttemptService.recordFailedAttempt(clientIp, nickname); + loginAttemptService.recordFailedAttempt(nickname, nickname); verify(commandLoginLogPort).save(any(LoginLog.class)); } @@ -67,12 +68,11 @@ void recordFailedAttempt_NewIP() { @Test @DisplayName("기존 IP로 로그인에 실패하면 로그인 실패 기록이 갱신된다.") void recordFailedAttempt_ExistingIP_BeforeLock() { - String nickname = "testUser"; LoginLog existingLog = existingLoginLog;; - when(loadLoginLogPort.findByClientIp(clientIp)).thenReturn(Optional.of(existingLog)); + when(loadLoginLogPort.findByNickname(nickname)).thenReturn(Optional.of(existingLog)); - loginAttemptService.recordFailedAttempt(clientIp, nickname); + loginAttemptService.recordFailedAttempt(nickname, clientIp); verify(commandLoginLogPort).save(existingLog); assertEquals(4, existingLog.getFailedCount()); @@ -80,15 +80,14 @@ void recordFailedAttempt_ExistingIP_BeforeLock() { } @Test - @DisplayName("기존 IP로 로그인에 5회 실패하면 계정이 잠긴다.") + @DisplayName("로그인에 5회 실패하면 계정이 잠긴다.") void recordFailedAttempt_AccountLock() { - String nickname = "testUser"; LoginLog existingLog = existingLoginLog; existingLog.recordFailedAttempt(); - when(loadLoginLogPort.findByClientIp(clientIp)).thenReturn(Optional.of(existingLog)); + when(loadLoginLogPort.findByNickname(nickname)).thenReturn(Optional.of(existingLog)); - assertThrows(AuthException.class, () -> loginAttemptService.recordFailedAttempt(clientIp, nickname)); + assertThrows(AuthException.class, () -> loginAttemptService.recordFailedAttempt(nickname,clientIp )); verify(commandLoginLogPort).save(existingLog); assertTrue(existingLog.isLocked()); @@ -100,9 +99,9 @@ void checkAccountIsLocked_NotLocked() { LoginLog loginLog = existingLoginLog; loginLog.setLocked(false); - when(loadLoginLogPort.findByClientIp(clientIp)).thenReturn(Optional.of(loginLog)); + when(loadLoginLogPort.findByNickname(loginLog.getNickname())).thenReturn(Optional.of(loginLog)); - assertDoesNotThrow(() -> loginAttemptService.checkAccountIsLocked(clientIp)); + assertDoesNotThrow(() -> loginAttemptService.checkAccountIsLocked(loginLog.getNickname())); } @Test @@ -110,10 +109,10 @@ void checkAccountIsLocked_NotLocked() { void checkAccountIsLocked_Locked() { LoginLog loginLog = lockedAccountLoginLog; - when(loadLoginLogPort.findByClientIp(clientIp)).thenReturn(Optional.of(loginLog)); + when(loadLoginLogPort.findByNickname(loginLog.getNickname())).thenReturn(Optional.of(loginLog)); AuthException exception = assertThrows(AuthException.class, () -> - loginAttemptService.checkAccountIsLocked(clientIp) + loginAttemptService.checkAccountIsLocked(loginLog.getNickname()) ); assertEquals(AuthErrorCode.ACCOUNT_IS_LOCKED.getMessage(), exception.getMessage(), @@ -125,11 +124,11 @@ void checkAccountIsLocked_Locked() { void checkAccountIsLocked_LockTimeExpired() { LoginLog loginLog = lockTimeExpiredLoginLog; - when(loadLoginLogPort.findByClientIp(clientIp)).thenReturn(Optional.of(loginLog)); + when(loadLoginLogPort.findByNickname(loginLog.getNickname())).thenReturn(Optional.of(loginLog)); - loginAttemptService.checkAccountIsLocked(clientIp); + loginAttemptService.checkAccountIsLocked(loginLog.getNickname()); - verify(commandLoginLogPort).deleteById(clientIp); + verify(commandLoginLogPort).deleteById(loginLog.getNickname()); } }