-
Notifications
You must be signed in to change notification settings - Fork 0
๐งSettings: ํ๋ก ํธ ๋ฐฐํฌ ๋๋ฉ์ธ CORS ์ถ๊ฐ #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughPost ์กฐํ ๊ธฐ๋ฅ์ ๋ฆฌํฉํ ๋งํ์ฌ category ํ๋ผ๋ฏธํฐ๋ฅผ ์ ํ์ฌํญ์ผ๋ก ๋ณ๊ฒฝํ๊ณ , PostRepository ๋ฉ์๋ ์๊ทธ๋์ฒ๋ฅผ ์ ๋ฆฌํ๋ฉฐ, ์นดํ ๊ณ ๋ฆฌ ํํฐ๋ง ๋ก์ง์ PostCategory ์ด๊ฑฐํ ๊ธฐ๋ฐ์ผ๋ก ๊ฐ์ ํ์ต๋๋ค. OAuth2 ๋ฆฌ๋ค์ด๋ ํธ URL์ ํ๋ก๋์ ํ๊ฒฝ์ผ๋ก ์ ๋ฐ์ดํธํ์ต๋๋ค. Changes
Estimated code review effort๐ฏ 2 (Simple) | โฑ๏ธ ~12๋ถ
Possibly related PRs
Suggested labels
Poem
Pre-merge checks and finishing touchesโ Failed checks (3 warnings)
โจ Finishing touches
๐งช Generate unit tests (beta)
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. Comment |
There was a problem hiding this 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
๐ Files selected for processing (5)
src/main/java/com/sku/refit/domain/post/controller/PostController.java(1 hunks)src/main/java/com/sku/refit/domain/post/repository/PostRepository.java(1 hunks)src/main/java/com/sku/refit/domain/post/service/PostServiceImpl.java(2 hunks)src/main/java/com/sku/refit/global/security/OAuth2LoginSuccessHandler.java(1 hunks)src/main/resources(1 hunks)
๐ Additional comments (5)
src/main/resources (1)
1-1: ์๋ธ๋ชจ๋ ๋ณ๊ฒฝ์ฌํญ ๊ฒ์ฆ ํ์์๋ธ๋ชจ๋ ์ปค๋ฐ ํฌ์ธํฐ๋ง ์ ๋ฐ์ดํธ๋์์ผ๋ฉฐ, ์ค์ ์ค์ ํ์ผ์ ๋ณ๊ฒฝ ๋ด์ฉ์ ํ์ธํ ์ ์์ต๋๋ค. PR ์ ๋ชฉ์์ ์ธ๊ธํ CORS ์ค์ ์ด ์ฌ๋ฐ๋ฅด๊ฒ ์ถ๊ฐ๋์๋์ง ๊ฒ์ฆ์ด ํ์ํฉ๋๋ค.
๋ค์์ ํ์ธํด์ฃผ์ธ์:
- ์๋ธ๋ชจ๋ ๋ด์ฉ ๊ฒ์ฆ:
e9738e52...์์b18f530...๋ก์ ๋ณ๊ฒฝ์์ ์ค์ ์ด๋ค ์ค์ ํ์ผ์ด ์์ ๋์๋์ง ํ์ธ- CORS ์ค์ : ํ๋ก ํธ์๋ ๋ฐฐํฌ ๋๋ฉ์ธ์ด
spring.web.cors.allowed-origins๋๋WebMvcConfigurer๋ฑ์ ์ฌ๋ฐ๋ฅด๊ฒ ์ถ๊ฐ๋์๋์ง ํ์ธ- OAuth2 ๋ฆฌ๋ค์ด๋ ํธ: PR ์ ๋ชฉ๊ณผ ์์ฝ์ ๋ฒ์ ๋ถ์ผ์น - ์ค์ ๋ก๋ Post ์กฐํ ๊ธฐ๋ฅ ๋ฆฌํฉํ ๋ง๊ณผ OAuth2 ๋ฆฌ๋ค์ด๋ ํธ URL ๋ณ๊ฒฝ๋ ํฌํจ๋์ด ์๋ ๊ฒ์ผ๋ก ๋ณด์
- ๋ณด์: CORS ์ค์ ์์ ํ์ฉ๋ ์ถ์ฒ๊ฐ ํ๋ก๋์ ํ๊ฒฝ์ ์ ์ ํ์ง ํ์ธ
๊ธฐ๋๋๋ ๊ฒฐ๊ณผ:
- CORS allowedOrigins์ ์ฌ๋ฐ๋ฅธ ๋ฐฐํฌ ๋๋ฉ์ธ ํฌํจ
- ์๊ฒฉ์ฆ๋ช (credentials)์ด ํ์ํ ๊ฒฝ์ฐ allowCredentials = true ์ค์ ํ์ธ
- HttpMethod๊ฐ ํ์ํ ๋ฒ์๋ก ์ ํ๋์ด ์๋์ง ํ์ธ
src/main/java/com/sku/refit/domain/post/controller/PostController.java (1)
71-77: ์นดํ ๊ณ ๋ฆฌ ํ๋ผ๋ฏธํฐ๋ฅผ ์ ํ์ฌํญ์ผ๋ก ๋ณ๊ฒฝ์นดํ ๊ณ ๋ฆฌ๋ฅผ ์ ํ์ฌํญ์ผ๋ก ๋ณ๊ฒฝํ์ฌ ์ ์ฒด ๊ฒ์๊ธ ์กฐํ๋ฅผ ์ง์ํ๋๋ก ๊ฐ์ ๋ ์ ์ ์ข์ต๋๋ค. ์๋น์ค ๋ ์ด์ด์ ๋ก์ง๊ณผ๋ ์ผ๊ด์ฑ ์๊ฒ ์ฐ๋๋ฉ๋๋ค.
์ฐธ๊ณ : ์ด ๋ณ๊ฒฝ์ฌํญ์ PR ์ ๋ชฉ("ํ๋ก ํธ ๋ฐฐํฌ ๋๋ฉ์ธ CORS ์ถ๊ฐ")๊ณผ๋ ์ง์ ์ ์ธ ์ฐ๊ด์ด ์์ด ๋ณด์ ๋๋ค. PR์ ๋ฒ์๋ฅผ ๋ช ํํ ํ๋ ๊ฒ์ด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค.
src/main/java/com/sku/refit/domain/post/service/PostServiceImpl.java (1)
215-215: ์ปค์ ๊ณ์ฐ ๋ฐฉ์ ๋ณ๊ฒฝ ํ์ธ
posts.get(posts.size() - 1)๋ก ์ง์ ์ธ๋ฑ์ค ์ ๊ทผํ๋๋ก ๋ณ๊ฒฝ๋ ๊ฒ์ ๊ฐ๊ฒฐํ๋ฉฐ, ์์posts.isEmpty()์ฒดํฌ๋ก ์ธํดIndexOutOfBoundsException์ด ๋ฐ์ํ์ง ์์ผ๋ฏ๋ก ์์ ํฉ๋๋ค.src/main/java/com/sku/refit/domain/post/repository/PostRepository.java (1)
21-23: ์๋ก์ด ๋ฆฌํฌ์งํ ๋ฆฌ ๋ฉ์๋ ์ถ๊ฐ ํ์ธ์ปค์ ๊ธฐ๋ฐ ํ์ด์ง๋ค์ด์ ์ ์ง์ํ๊ธฐ ์ํ ์๋ก์ด ๋ฉ์๋๋ค์ด ์ ์ ํ๊ฒ ์ถ๊ฐ๋์์ต๋๋ค:
findByIdLessThan: ์นดํ ๊ณ ๋ฆฌ ํํฐ ์์ด ID ๊ธฐ๋ฐ ์ปค์ ํ์ด์งfindByPostCategoryAndIdLessThan: ์นดํ ๊ณ ๋ฆฌ ํํฐ์ ID ๊ธฐ๋ฐ ์ปค์ ํ์ด์ง๋ฉ์๋ ์๊ทธ๋์ฒ๊ฐ Spring Data JPA ๋ช ๋ช ๊ท์น์ ๋ง์ผ๋ฉฐ, ์๋น์ค ๋ ์ด์ด์ ๋ฆฌํฉํ ๋ง๋ ๋ก์ง๊ณผ ์ผ๊ด์ฑ ์๊ฒ ์ฐ๋๋ฉ๋๋ค.
src/main/java/com/sku/refit/global/security/OAuth2LoginSuccessHandler.java (1)
71-71: CORS ์ค์ ์ด ํ๋ก๋์ ๋๋ฉ์ธ์ ํ์ฉํ๋์ง ํ์ธ ํ์OAuth2 ์ธ์ฆ ์ฑ๊ณต ํ
https://refit-lab.vercel.app๋ก ๋ฆฌ๋ค์ด๋ ํธํ๋ ์ฝ๋๋ ์ ์ ํฉ๋๋ค. ๋ค๋ง CorsConfig.java์์ CORS ์ค์ ์ด${cors.allowed-origins}ํ๊ฒฝ ๋ณ์๋ก ์ธ๋ถํ๋์ด ์๊ธฐ ๋๋ฌธ์, ์ค์ ๋ฐฐํฌ ํ๊ฒฝ์์ ์ด ๋๋ฉ์ธ์ด ์ค์ ๋์ด ์๋์ง ํ์ธ์ด ํ์์ ๋๋ค. ์ฝ๋๋ฒ ์ด์ค ๋ด ์ค์ ํ์ผ์์๋ ์ค์ ํ์ฉ ๋๋ฉ์ธ ๊ฐ์ ํ์ธํ ์ ์์ผ๋ฏ๋ก, ๋ฐฐํฌ ํ๊ฒฝ ๋ณ์๋ ์ธ๋ถ ์ค์ ์๋ฒ์์https://refit-lab.vercel.app์ดcors.allowed-origins์ ํฌํจ๋์ด ์๋์ง ๊ฒ์ฆํด ์ฃผ์ธ์.
| if (category == null || category.isBlank()) { | ||
| if (lastPostId == null) { | ||
| posts = postRepository.findAll(pageable).getContent(); | ||
| } else { | ||
| posts = postRepository.findByIdLessThan(lastPostId, pageable).getContent(); | ||
| } | ||
| } else { | ||
| posts = | ||
| postRepository | ||
| .findByPostCategoryContainingAndIdLessThan(category, lastPostId, pageable) | ||
| .getContent(); | ||
| PostCategory postCategory; | ||
| try { | ||
| postCategory = PostCategory.valueOf(category); | ||
| } catch (IllegalArgumentException e) { | ||
| throw new CustomException(PostErrorCode.INVALID_CATEGORY); | ||
| } | ||
|
|
||
| if (lastPostId == null) { | ||
| posts = postRepository.findByPostCategory(postCategory, pageable).getContent(); | ||
| } else { | ||
| posts = | ||
| postRepository | ||
| .findByPostCategoryAndIdLessThan(postCategory, lastPostId, pageable) | ||
| .getContent(); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๐งฉ Analysis chain
๐ Script executed:
#!/bin/bash
# Find PostService test files
fd "PostService.*Test\.java$|PostService.*Spec\.java$" --type f
# Also search more broadly for test files
fd ".*Test\.java$" --type f | grep -i post | head -20Repository: refit-lab/refit-be
Length of output: 44
๐ Script executed:
# Search for getPostsByCategory tests
rg -n "getPostsByCategory|getPostByCategory" --type java -g "*Test.java" -A 5 -B 2Repository: refit-lab/refit-be
Length of output: 210
๐ Script executed:
# Let's also check the structure of the src directory
git ls-files | grep -E "src/(test|main)" | head -30Repository: refit-lab/refit-be
Length of output: 2189
๐ Script executed:
#!/bin/bash
# Search for all Test.java files without filters
find . -name "*Test.java" -o -name "*Spec.java" 2>/dev/null | head -50Repository: refit-lab/refit-be
Length of output: 44
๐ Script executed:
# Check if test directory exists
ls -la | grep -i test
find . -maxdepth 2 -type d -name "*test*" 2>/dev/nullRepository: refit-lab/refit-be
Length of output: 72
๐ Script executed:
# Get a complete picture of repository structure
git ls-files | cut -d'/' -f1,2 | sort | uniq -c | head -20Repository: refit-lab/refit-be
Length of output: 500
๐ Script executed:
# Search for PostService in any Java file to understand the codebase better
rg -n "class PostService" --type javaRepository: refit-lab/refit-be
Length of output: 187
๐ Script executed:
#!/bin/bash
# List all files in src/test directory
find src/test -type f 2>/dev/null | head -50Repository: refit-lab/refit-be
Length of output: 116
๐ Script executed:
# List directory structure of src/test
ls -la src/test 2>/dev/null
find src/test -type d 2>/dev/nullRepository: refit-lab/refit-be
Length of output: 311
๐ Script executed:
# Search for any Java files in src/test
git ls-files | grep "src/test"Repository: refit-lab/refit-be
Length of output: 116
๐ Script executed:
# Search for PostService references in entire codebase including test
rg -l "PostService" --type java | head -20Repository: refit-lab/refit-be
Length of output: 270
๐ Script executed:
#!/bin/bash
# Check the only test file to see if it tests PostService
cat src/test/java/com/sku/refit/RefitApplicationTests.javaRepository: refit-lab/refit-be
Length of output: 302
๐ Script executed:
# Check the PostService interface to see the actual method name
rg -n "getPostsByCategory|getPostByCategory|getPost" src/main/java/com/sku/refit/domain/post/service/PostService.java -A 3Repository: refit-lab/refit-be
Length of output: 276
๐ Script executed:
# Check the full PostServiceImpl around the reviewed lines
sed -n '140,190p' src/main/java/com/sku/refit/domain/post/service/PostServiceImpl.java | cat -nRepository: refit-lab/refit-be
Length of output: 2042
getPostsByCategory ๋ฉ์๋์ ๋ํ ํ
์คํธ ์ผ์ด์ค ์์ฑ ํ์
์นดํ ๊ณ ๋ฆฌ ํํฐ๋ง ๋ก์ง ๋ฆฌํฉํ ๋ง์ผ๋ก ํ์ ์์ ์ฑ์ด ๊ฐ์ ๋์์ต๋๋ค. ๋ค๋ง ํ์ฌ ์ด ๋ฉ์๋์ ๋ํ ํ ์คํธ ์ปค๋ฒ๋ฆฌ์ง๊ฐ ์ ํ ์์ต๋๋ค. ๋ค์ ๋ชจ๋ ์คํ ๊ฒฝ๋ก์ ๋ํ ํ ์คํธ ์ผ์ด์ค๋ฅผ ์ถ๊ฐํด์ผ ํฉ๋๋ค:
- category๊ฐ null/blank์ด๊ณ lastPostId๊ฐ null์ธ ๊ฒฝ์ฐ
- category๊ฐ null/blank์ด๊ณ lastPostId๊ฐ ์กด์ฌํ๋ ๊ฒฝ์ฐ
- ์ ํจํ category์ด๊ณ lastPostId๊ฐ null์ธ ๊ฒฝ์ฐ
- ์ ํจํ category์ด๊ณ lastPostId๊ฐ ์กด์ฌํ๋ ๊ฒฝ์ฐ
- ์๋ชป๋ category ํ์์ผ๋ก
CustomException(PostErrorCode.INVALID_CATEGORY)๋ฐ์ํ๋ ๊ฒฝ์ฐ
๐ค Prompt for AI Agents
In src/main/java/com/sku/refit/domain/post/service/PostServiceImpl.java around
lines 158 to 180, there are five untested execution paths in getPostsByCategory;
add unit tests that cover: (1) category null/blank with lastPostId null, (2)
category null/blank with lastPostId present, (3) valid category with lastPostId
null, (4) valid category with lastPostId present, and (5) invalid category
string that throws CustomException(PostErrorCode.INVALID_CATEGORY). Implement
tests using your projectโs test framework (JUnit) and mocking (Mockito) to stub
postRepository responses (return Page or List as expected) and verify the
service returns the repository results and/or throws the expected exception;
assert repository method selection (verify correct repository method called for
each scenario) and validate returned content or the thrown CustomException with
the correct error code.
Summary by CodeRabbit
๋ฆด๋ฆฌ์ค ๋ ธํธ
๋ฒ๊ทธ ์์
๊ฐ์ ์ฌํญ
โ๏ธ Tip: You can customize this high-level summary in your review settings.