Skip to content

refactor: 액세스 토큰 JWT 클레임에 homeUniversityId를 추가 #719

Merged
Hexeong merged 3 commits into
developfrom
refactor/716-add-homeuniversityid-to-jwt-claims
May 20, 2026
Merged

refactor: 액세스 토큰 JWT 클레임에 homeUniversityId를 추가 #719
Hexeong merged 3 commits into
developfrom
refactor/716-add-homeuniversityid-to-jwt-claims

Conversation

@Hexeong
Copy link
Copy Markdown
Contributor

@Hexeong Hexeong commented May 20, 2026

관련 이슈

작업 내용

  1. refactor: 액세스 토큰 JWT 클레임에 homeUniversityId를 추가

    • generateAccessToken 메서드에 siteUser가 homeUniversityId가 null이 아니라면 claim에 추가
    • parseHomeUniversityId 메서드 추가
  2. test: 액세스 토큰 JWT 클레임에 homeUniversityId를 추가한 것에 대한 테스트 추가

    • SiteUserFixture에 국내_대학_정보_소지_사용자 메서드 추가

특이 사항

PostViewCountConcurrencyTest.게시글을_조회할_때_조회수_조작_문제를_해결한다() 메서드 CI 간헐적 실패 오류 발견

  1. 게시글을_조회할_때_조회수_동시성_문제를_해결한다 테스트가 먼저 실행됨
  2. 그 테스트의 @async 스케줄러 태스크가 asyncExecutor 큐에 남아있는 상태에서 DatabaseCleaner.clear()가 실행됨
  3. flushDb()로 Redis는 지워지지만, asyncExecutor 큐의 태스크는 남아있음
  4. 두 번째 테스트에서 같은 key 이름 (post:view:1, auto_increment 리셋)으로 새 viewCountKey 생성
  5. 오래된 큐 태스크 + 새 스케줄러 태스크가 동일한 key를 동시에 getAndDelete 시도
  6. 하나는 값을 가져가고, 다른 하나는 null을 받아 UPDATE post SET view_count = view_count + null = null 실행

근본 원인은 UpdateViewCountService.updateViewCount가 null 방어를 하지 않는 것입니다.

해당 부분은 issue로 정의하여 만들어두겠습니다.

리뷰 요구사항 (선택)

  • 현재 homeUniversityId는 최근 추가한 컬럼이기에 대부분 null일 가능성이 높으므로 기존에 배포된 서비스에 영향이 가지 않도록 homeUniversityId가 null일때 예외를 발생하지 않고 넘어가도록 구현했습니다.
  • 토큰에 반영된 homeUniversityId에 변경 이벤트 시점에 대해서 기획측에서 전달받은 내용이 없으므로, homeUniversityId 갱신에 따른 토큰 재발급 로직은 해당 기획이 정해져 작업을 할때 같이 반영하는 게 좋다고 생각해서 현재 구현에서 제외했습니다.

Hexeong added 2 commits May 20, 2026 15:31
- generateAccessToken 메서드에 siteUser가 homeUniversityId가 null이 아니라면 claim에 추가
- parseHomeUniversityId 메서드 추가
- SiteUserFixture에 국내_대학_정보_소지_사용자 메서드 추가
- AuthTokenProviderTest에 homeUniversityId 소지 여부에 따른 테스트 추가
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 20, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: de3c61c9-5466-44e8-be12-c1bc5f78db83

📥 Commits

Reviewing files that changed from the base of the PR and between 899627b and 88d2b67.

📒 Files selected for processing (1)
  • src/main/java/com/example/solidconnection/auth/service/AuthTokenProvider.java
💤 Files with no reviewable changes (1)
  • src/main/java/com/example/solidconnection/auth/service/AuthTokenProvider.java

Walkthrough

  1. AccessToken에 home_university 클레임 추가.
    HashMap 임포트, HOME_UNIVERSITY_CLAIM_KEY 상수 추가, generateAccessToken에서 role을 기본으로 넣고 siteUser.getHomeUniversityId()가 있을 때만 home_university 클레임을 추가합니다.

  2. home_university 클레임 파싱 메서드 구현.
    parseHomeUniversityId(String token)를 추가해 토큰에서 home_university 클레임을 읽고 존재 시 Long으로 변환하여 반환하며, 없으면 null을 반환합니다.

  3. 테스트 인프라 확장.
    SiteUserFixture에 homeUniversityId를 설정한 헬퍼 메서드를 추가하고 AuthTokenProviderTest에 HomeUniversityFixture 주입 및 home_university 클레임 존재/부재를 검증하는 테스트를 추가합니다.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 분

Suggested reviewers

  • wibaek
  • whqtker
  • Gyuhyeok99
  • lsy1307
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed PR 제목은 주요 변경사항인 'JWT 클레임에 homeUniversityId 추가'를 명확하게 요약하고 있으며, 간결하고 명확한 표현으로 작성되었습니다.
Description check ✅ Passed PR 설명은 템플릿 구조에 따라 관련 이슈, 작업 내용, 특이 사항을 포함하고 있으며, 구체적이고 상세한 정보를 제공합니다.
Linked Issues check ✅ Passed 코드 변경사항이 #716의 주요 목표(JWT 클레임에 homeUniversityId 추가)를 완벽히 충족하며, null 안전성도 고려되었습니다.
Out of Scope Changes check ✅ Passed 모든 변경사항이 homeUniversityId 추가라는 PR 목표에 집중되어 있으며, 범위 밖의 변경은 발견되지 않습니다.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/716-add-homeuniversityid-to-jwt-claims

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@sukangpunch sukangpunch left a comment

Choose a reason for hiding this comment

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

고생하셨습니다! 개행 관련 리뷰 하나 달았습니다!

import com.example.solidconnection.siteuser.domain.Role;
import com.example.solidconnection.siteuser.domain.SiteUser;
import com.example.solidconnection.siteuser.repository.SiteUserRepository;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

static import가 아닌데 개행이 존재합니다!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

반영했습니다!

@Hexeong Hexeong merged commit 2259e8a into develop May 20, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: JWT 토큰 클레임에 homeUniversityId를 추가

2 participants