Repository navigation
refactor/#126-auth: 인증 API 요청 및 쿠키 호환성 수정 #127
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
61126dc
fix: 소셜 계정 조회 API 요청 형식 호환성 수정
jeong1112 f923a03
test: 전화번호 인증 API 요청 및 응답 테스트 추가
jeong1112 76129bb
fix: 웹 인증 갱신 쿠키 이름을 레거시와 일치
jeong1112 09280e6
test: 웹 및 앱 토큰 갱신 API 테스트 추가
jeong1112 3c8ebcb
feat : CORS 요청 허용 겅로 추가
jeong1112 a6be0ff
fix: 공식 홈페이지 CORS 도메인 및 세션 헤더 허용
jeong1112 4322b16
refactor: 인증 및 어드민 갱신 쿠키 이름 상수화
jeong1112 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
api/src/main/java/org/sopt/makers/api/common/security/CookieConstant.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package org.sopt.makers.api.common.security; | ||
|
|
||
| public final class CookieConstant { | ||
| public static final String AUTH_REFRESH_TOKEN_COOKIE = "Refresh-Token"; | ||
| public static final String ADMIN_REFRESH_TOKEN_COOKIE = "refreshToken"; | ||
|
|
||
| private CookieConstant() {} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,11 @@ private SecurityConstant() {} | |
| "http://localhost:5173", | ||
| "https://sopt-internal-dev.sopt.org", | ||
| "https://playground.sopt.org", | ||
| "https://sopt.org", | ||
| "https://www.sopt.org", | ||
| "https://www.dev.sopt.org", | ||
| "https://admins.sopt.org", | ||
| "https://dev.admins.sopt.org", | ||
|
Comment on lines
+24
to
+28
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 공홈 Origin인 https://www.sopt.org가 포함돼야 하지 않나요??
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아이쿠 |
||
| "https://sopt-auth-frontend-test.pages.dev", | ||
| "https://sopt-org-frontend-git-test-daeuns-projects-025386f4.vercel.app", | ||
| "https://sopt-operation-frontend-3yc.pages.dev" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 0 additions & 6 deletions
6
...rc/main/java/org/sopt/makers/api/controller/auth/dto/GetSocialAccountPlatformRequest.java
This file was deleted.
Oops, something went wrong.
97 changes: 97 additions & 0 deletions
97
api/src/test/java/org/sopt/makers/api/common/config/CorsConfigTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| package org.sopt.makers.api.common.config; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.ValueSource; | ||
| import org.springframework.http.HttpHeaders; | ||
| import org.springframework.mock.web.MockHttpServletRequest; | ||
| import org.springframework.mock.web.MockHttpServletResponse; | ||
| import org.springframework.web.cors.DefaultCorsProcessor; | ||
|
|
||
| class CorsConfigTest { | ||
| @ParameterizedTest | ||
| @ValueSource( | ||
| strings = { | ||
| "https://sopt.org", | ||
| "https://www.sopt.org", | ||
| "https://www.dev.sopt.org", | ||
| "https://admins.sopt.org", | ||
| "https://dev.admins.sopt.org" | ||
| }) | ||
| @DisplayName("공식 홈페이지와 관리자 페이지의 API 키 사전 요청을 허용한다") | ||
| void allowsPageOrigins(String origin) throws Exception { | ||
| MockHttpServletRequest request = preflight(origin); | ||
| MockHttpServletResponse response = new MockHttpServletResponse(); | ||
|
|
||
| boolean allowed = | ||
| new DefaultCorsProcessor() | ||
| .processRequest( | ||
| new CorsConfig().corsConfigurationSource().getCorsConfiguration(request), | ||
| request, | ||
| response); | ||
|
|
||
| assertThat(allowed).isTrue(); | ||
| assertThat(response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)).isEqualTo(origin); | ||
| assertThat(response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS)) | ||
| .containsIgnoringCase("api-key") | ||
| .containsIgnoringCase("X-Api-Key") | ||
| .containsIgnoringCase("X-Service-Name") | ||
| .containsIgnoringCase("Authorization"); | ||
| assertThat(response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS)).isEqualTo("true"); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("공식 홈페이지의 솝트스토리 조회에 세션 ID 헤더를 허용한다") | ||
| void allowsSessionIdHeader() throws Exception { | ||
| MockHttpServletRequest request = new MockHttpServletRequest("OPTIONS", "/v2/soptstory"); | ||
| request.addHeader(HttpHeaders.ORIGIN, "https://www.sopt.org"); | ||
| request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET"); | ||
| request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS, "session-id"); | ||
| MockHttpServletResponse response = new MockHttpServletResponse(); | ||
|
|
||
| boolean allowed = | ||
| new DefaultCorsProcessor() | ||
| .processRequest( | ||
| new CorsConfig().corsConfigurationSource().getCorsConfiguration(request), | ||
| request, | ||
| response); | ||
|
|
||
| assertThat(allowed).isTrue(); | ||
| assertThat(response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)) | ||
| .isEqualTo("https://www.sopt.org"); | ||
| assertThat(response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS)) | ||
| .containsIgnoringCase("session-id"); | ||
| assertThat(response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS)).contains("GET"); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("등록되지 않은 도메인의 사전 요청을 차단한다") | ||
| void rejectsUnknownOrigin() throws Exception { | ||
| MockHttpServletRequest request = preflight("https://unregistered.example.com"); | ||
| MockHttpServletResponse response = new MockHttpServletResponse(); | ||
|
|
||
| boolean allowed = | ||
| new DefaultCorsProcessor() | ||
| .processRequest( | ||
| new CorsConfig().corsConfigurationSource().getCorsConfiguration(request), | ||
| request, | ||
| response); | ||
|
|
||
| assertThat(allowed).isFalse(); | ||
| assertThat(response.getStatus()).isEqualTo(403); | ||
| assertThat(response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)).isNull(); | ||
| } | ||
|
|
||
| private MockHttpServletRequest preflight(String origin) { | ||
| MockHttpServletRequest request = new MockHttpServletRequest("OPTIONS", "/v2/admin"); | ||
| request.addHeader(HttpHeaders.ORIGIN, origin); | ||
| request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "POST"); | ||
| request.addHeader( | ||
| HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS, | ||
| "Content-Type, Authorization, api-key, X-Api-Key, X-Service-Name"); | ||
| return request; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
쿠키 이름들이 여러 메서드에 흩어져서 선언돼있는데 공통 상수로 추출할 수 있지 않을까 합니다!
CookieFactory.java:13 "refreshToken"
AdminAuthController.java:34
AuthController.java:43