Skip to content

Conversation

@dungbik
Copy link
Contributor

@dungbik dungbik commented Jul 11, 2025

📝 변경 내용


✅ 체크리스트

  • 코드가 정상적으로 동작함
  • 테스트 코드 통과함
  • 문서(README 등)를 최신화함
  • 코드 스타일 가이드 준수

💬 기타 참고 사항

Summary by CodeRabbit

  • 신규 기능

    • 로그인 요청 및 응답에 대한 새로운 데이터 구조가 도입되었습니다.
    • 테스트용 사용자 생성 도구가 추가되었습니다.
  • 버그 수정

    • 로그인 시 활성화된 사용자만 인증이 가능하도록 개선되었습니다.
  • 리팩터

    • 쿠키 처리 방식이 변경되어 응답 헤더를 통해 쿠키가 관리됩니다.
    • 내부 데이터 구조 및 메서드 시그니처가 일관성 있게 정리되었습니다.
  • 테스트

    • 로그인 성공 및 실패(이메일 또는 비밀번호 오류) 상황에 대한 테스트가 추가되었습니다.

@dungbik dungbik requested a review from stoneTiger0912 July 11, 2025 04:34
@dungbik dungbik self-assigned this Jul 11, 2025
@dungbik dungbik added the enhancement New feature or request label Jul 11, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jul 11, 2025

Walkthrough

로그인 및 로그아웃 시 리프레시 토큰 쿠키 처리가 HttpServletResponse에서 응답 헤더로 변경되었습니다. 로그인 요청/응답 DTO가 UserLoginDto에서 UserLoginRequest/UserLoginResponse로 대체되었고, 서비스 및 레포지토리 계층에서 사용자 상태를 확인하도록 수정되었습니다. 테스트 코드와 쿠키 유틸리티도 이에 맞게 리팩토링되었습니다.

Changes

파일/경로 변경 요약
.../auth/controller/AuthController.java 로그인/로그아웃에서 쿠키 처리 방식 변경, DTO 교체, 메서드 시그니처 수정
.../auth/model/UserLoginDto.java UserLoginDto 및 내부 Request/Response record 삭제
.../auth/model/UserLoginRequest.java
.../auth/model/UserLoginResponse.java
UserLoginRequest, UserLoginResponse record 신설 및 정적 팩토리 메서드 추가
.../auth/service/AuthService.java 로그인 시 ACTIVE 상태 사용자만 허용, DTO 교체, 일부 유틸리티 메서드 정리 및 위치 이동
.../common/util/CookieUtil.java 쿠키 생성 메서드가 Cookie 객체 반환하도록 변경, HttpServletResponse 의존성 제거
.../user/repository/UserRepository.java findByEmail → findByEmailAndStatus로 변경, UserStatus 추가
.../auth/service/AuthServiceTest.java 로그인 성공/실패 케이스 테스트 추가, PasswordEncoder 및 JwtComponent 모킹
.../fixture/UserFixture.java 테스트용 User 엔티티 생성기 추가

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant AuthController
    participant AuthService
    participant UserRepository
    participant CookieUtil

    Client->>AuthController: POST /login (UserLoginRequest)
    AuthController->>AuthService: login(UserLoginRequest)
    AuthService->>UserRepository: findByEmailAndStatus(email, ACTIVE)
    UserRepository-->>AuthService: User or empty
    AuthService->>AuthService: 비밀번호 검증
    AuthService-->>AuthController: TokenPair
    AuthController->>CookieUtil: createCookie(...)
    CookieUtil-->>AuthController: Cookie
    AuthController-->>Client: Response(헤더에 쿠키, body에 UserLoginResponse)
Loading

Poem

🐰
로그인 쿠키가 바뀌었어요,
응답 헤더에 살짝 숨었지요.
DTO도 새 옷을 입고,
ACTIVE만 찾는 레포도 멋져요.
테스트 토끼도 신이 나,
오늘도 코드밭에 당근 하나!
🍪✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9f6eb56 and c31e696.

📒 Files selected for processing (1)
  • src/test/java/project/flipnote/auth/service/AuthServiceTest.java (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/test/java/project/flipnote/auth/service/AuthServiceTest.java
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 17af2ba and 9f6eb56.

📒 Files selected for processing (9)
  • src/main/java/project/flipnote/auth/controller/AuthController.java (2 hunks)
  • src/main/java/project/flipnote/auth/model/UserLoginDto.java (0 hunks)
  • src/main/java/project/flipnote/auth/model/UserLoginRequest.java (1 hunks)
  • src/main/java/project/flipnote/auth/model/UserLoginResponse.java (1 hunks)
  • src/main/java/project/flipnote/auth/service/AuthService.java (3 hunks)
  • src/main/java/project/flipnote/common/util/CookieUtil.java (2 hunks)
  • src/main/java/project/flipnote/user/repository/UserRepository.java (1 hunks)
  • src/test/java/project/flipnote/auth/service/AuthServiceTest.java (3 hunks)
  • src/test/java/project/flipnote/fixture/UserFixture.java (1 hunks)
💤 Files with no reviewable changes (1)
  • src/main/java/project/flipnote/auth/model/UserLoginDto.java
🔇 Additional comments (19)
src/main/java/project/flipnote/auth/model/UserLoginResponse.java (1)

3-10: 깔끔한 DTO 구조 설계

레코드 클래스를 사용한 간결하고 불변한 응답 DTO 구조가 잘 설계되어 있습니다. 정적 팩토리 메서드를 통해 객체 생성 의도를 명확히 표현한 점도 좋습니다.

src/main/java/project/flipnote/user/repository/UserRepository.java (2)

8-8: UserStatus import 추가 확인

새로운 메서드 시그니처에 필요한 UserStatus 임포트가 적절히 추가되었습니다.


16-16: 사용자 상태 기반 필터링 로직 추가

활성 사용자만 로그인할 수 있도록 하는 보안 강화 로직이 잘 구현되어 있습니다. 메서드명도 의도를 명확히 표현하고 있습니다.

src/main/java/project/flipnote/auth/model/UserLoginRequest.java (2)

9-10: 이메일 필드 검증 로직

이메일 필드에 @Email@NotBlank 어노테이션이 적절히 적용되어 있어 입력값 검증이 잘 구현되어 있습니다.


12-13: 비밀번호 커스텀 검증 어노테이션

비밀번호 필드에 @ValidPassword 커스텀 검증 어노테이션이 적용되어 있어 비밀번호 정책을 일관되게 적용할 수 있습니다.

src/test/java/project/flipnote/fixture/UserFixture.java (2)

9-11: 테스트 상수 정의

테스트에서 사용할 상수들이 명확하게 정의되어 있어 테스트 데이터의 일관성을 보장할 수 있습니다.


12-21: 활성 사용자 생성 픽스처

ReflectionTestUtils를 사용해 테스트 환경에서 private 필드를 설정하는 것은 적절한 방법입니다. 활성 사용자 생성 로직이 명확하고 재사용 가능한 구조로 잘 구현되어 있습니다.

src/main/java/project/flipnote/auth/service/AuthService.java (6)

18-18: 새로운 요청 DTO import

UserLoginRequest 임포트가 적절히 추가되어 새로운 DTO 구조를 지원합니다.


23-23: UserStatus import 추가

활성 사용자 확인 로직을 위한 UserStatus 임포트가 적절히 추가되었습니다.


39-45: 로그인 메서드 리팩토링

메서드 시그니처가 새로운 DTO 구조에 맞게 업데이트되었고, 활성 사용자 확인 로직이 추가되어 보안이 강화되었습니다. 비밀번호 검증 로직도 별도 메서드로 분리되어 코드 가독성이 향상되었습니다.


87-90: 활성 사용자 조회 로직

활성 상태의 사용자만 로그인할 수 있도록 하는 보안 강화 로직이 잘 구현되어 있습니다. 메서드명도 의도를 명확히 표현하고 있습니다.


92-96: 비밀번호 검증 로직 분리

비밀번호 매칭 검증 로직이 별도 메서드로 분리되어 코드의 가독성과 재사용성이 향상되었습니다.


98-119: 검증 헬퍼 메서드들

여러 검증 로직들이 명확한 메서드명으로 분리되어 있어 코드의 가독성과 유지보수성이 크게 향상되었습니다. 각 메서드가 단일 책임을 가지고 있어 SOLID 원칙을 잘 준수하고 있습니다.

src/test/java/project/flipnote/auth/service/AuthServiceTest.java (2)

164-239: 로그인 테스트 구현이 잘 되어 있습니다.

새로 추가된 Login 테스트 클래스가 성공/실패 시나리오를 모두 포함하여 포괄적으로 작성되었습니다. 특히 다음 사항들이 잘 구현되었습니다:

  • 성공 케이스에서 모든 의존성 호출 검증
  • 실패 케이스에서 적절한 예외 처리 및 호출되지 않아야 할 메서드 검증
  • 새로운 UserLoginRequest DTO 사용
  • UserFixture.createActiveUser() 사용으로 일관된 테스트 데이터 생성

175-175: 확인 완료: UserFixture.createActiveUser() 비밀번호 일치
UserFixture.createActiveUser()가 반환하는 비밀번호는 ENCODED_PASSWORD 상수("encodedPass")이며, 테스트 내 encodedPassword 변수 역시 "encodedPass"로 동일하게 사용되고 있습니다. 따라서 별도 수정 없이 의도한 대로 동작합니다.

src/main/java/project/flipnote/common/util/CookieUtil.java (1)

11-32: 쿠키 유틸리티 리팩토링이 잘 되어 있습니다.

쿠키 생성과 응답 처리를 분리한 리팩토링이 매우 좋습니다. 다음과 같은 개선사항들이 있습니다:

  • 단일 책임 원칙 준수: 쿠키 생성만 담당
  • 테스트 가능성 향상: Cookie 객체 반환으로 테스트 용이
  • 재사용성 증가: 다양한 응답 처리 방식에 활용 가능

메서드 시그니처와 기본값 설정도 적절합니다.

src/main/java/project/flipnote/auth/controller/AuthController.java (3)

32-47: 로그인 엔드포인트 구현이 잘 되어 있습니다.

새로운 DTO와 쿠키 처리 방식을 적절히 활용하여 구현되었습니다. 특히 다음 사항들이 개선되었습니다:

  • 새로운 UserLoginRequest/UserLoginResponse DTO 사용
  • HttpHeaders.SET_COOKIE를 통한 명시적 쿠키 설정
  • JwtProperties를 통한 설정 기반 만료 시간 관리

50-56: 로그아웃 엔드포인트 구현이 깔끔합니다.

만료된 쿠키를 생성하여 기존 쿠키를 무효화하는 방식이 적절하게 구현되었습니다. 쿠키 유틸리티의 createExpiredCookie 메서드를 효과적으로 활용하고 있습니다.


41-41: Math.toIntExact 안전성 확인 완료

현재 application.yml에서 설정된

  • access-token-expiration: 1h → 3,600s
  • refresh-token-expiration: 7d → 604,800s

값 모두 Java int 최대값(2,147,483,647)을 크게 밑돌아 Math.toIntExact 호출 시 ArithmeticException 발생 위험이 없습니다.
따라서 별도의 예외 처리 없이 사용해도 무방합니다.

Copy link
Member

@stoneTiger0912 stoneTiger0912 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: 리뷰 확인했습니다.

@dungbik dungbik merged commit b883244 into develop Jul 11, 2025
3 checks passed
@dungbik dungbik deleted the feat/login branch July 11, 2025 12:02
@coderabbitai coderabbitai bot mentioned this pull request Jul 26, 2025
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants