-
Notifications
You must be signed in to change notification settings - Fork 1
fix: Apple 로그인 identityToken 요청 호환 처리 #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
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
103 changes: 103 additions & 0 deletions
103
src/test/java/com/moru/server/domain/member/controller/AuthControllerTest.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,103 @@ | ||
| package com.moru.server.domain.member.controller; | ||
|
|
||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.verifyNoInteractions; | ||
| import static org.mockito.Mockito.when; | ||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc; | ||
| import org.springframework.http.MediaType; | ||
| import org.springframework.test.context.ActiveProfiles; | ||
| import org.springframework.test.context.bean.override.mockito.MockitoBean; | ||
| import org.springframework.test.web.servlet.MockMvc; | ||
|
|
||
| import com.moru.server.domain.member.dto.AuthRequestDTO; | ||
| import com.moru.server.domain.member.dto.AuthResponseDTO; | ||
| import com.moru.server.domain.member.entity.enums.OAuthProvider; | ||
| import com.moru.server.domain.member.service.command.auth.AuthCommandService; | ||
|
|
||
| @ActiveProfiles("test") | ||
| @SpringBootTest | ||
| @AutoConfigureMockMvc | ||
| class AuthControllerTest { | ||
|
|
||
| @Autowired | ||
| private MockMvc mockMvc; | ||
|
|
||
| @MockitoBean | ||
| private AuthCommandService authCommandService; | ||
|
|
||
| @Test | ||
| void acceptsIdentityTokenForAppleLogin() throws Exception { | ||
| AuthRequestDTO.SocialLoginRequest request = | ||
| new AuthRequestDTO.SocialLoginRequest("apple-identity-token", "apple-authorization-code"); | ||
| when(authCommandService.loginWithSocial(OAuthProvider.APPLE, request)) | ||
| .thenReturn(socialLoginResponse()); | ||
|
|
||
| mockMvc.perform(post("/auth/login/apple") | ||
| .contentType(MediaType.APPLICATION_JSON) | ||
| .content(""" | ||
| { | ||
| "identityToken": "apple-identity-token", | ||
| "authorizationCode": "apple-authorization-code" | ||
| } | ||
| """)) | ||
| .andExpect(status().isOk()) | ||
| .andExpect(jsonPath("$.isSuccess").value(true)) | ||
| .andExpect(jsonPath("$.result.memberId").value(1)); | ||
|
|
||
| verify(authCommandService).loginWithSocial(OAuthProvider.APPLE, request); | ||
| } | ||
|
|
||
| @Test | ||
| void keepsSupportingTokenForAppleLogin() throws Exception { | ||
| AuthRequestDTO.SocialLoginRequest request = | ||
| new AuthRequestDTO.SocialLoginRequest("apple-identity-token", "apple-authorization-code"); | ||
| when(authCommandService.loginWithSocial(OAuthProvider.APPLE, request)) | ||
| .thenReturn(socialLoginResponse()); | ||
|
|
||
| mockMvc.perform(post("/auth/login/apple") | ||
| .contentType(MediaType.APPLICATION_JSON) | ||
| .content(""" | ||
| { | ||
| "token": "apple-identity-token", | ||
| "authorizationCode": "apple-authorization-code" | ||
| } | ||
| """)) | ||
| .andExpect(status().isOk()) | ||
| .andExpect(jsonPath("$.isSuccess").value(true)); | ||
|
|
||
| verify(authCommandService).loginWithSocial(OAuthProvider.APPLE, request); | ||
| } | ||
|
|
||
| @Test | ||
| void rejectsAppleLoginWithoutSocialToken() throws Exception { | ||
| mockMvc.perform(post("/auth/login/apple") | ||
| .contentType(MediaType.APPLICATION_JSON) | ||
| .content(""" | ||
| { | ||
| "authorizationCode": "apple-authorization-code" | ||
| } | ||
| """)) | ||
| .andExpect(status().isBadRequest()) | ||
| .andExpect(jsonPath("$.isSuccess").value(false)) | ||
| .andExpect(jsonPath("$.code").value("COMMON400")); | ||
|
|
||
| verifyNoInteractions(authCommandService); | ||
| } | ||
|
|
||
| private AuthResponseDTO.SocialLoginResponse socialLoginResponse() { | ||
| return AuthResponseDTO.SocialLoginResponse.builder() | ||
| .memberId(1L) | ||
| .accessToken("access-token") | ||
| .refreshToken("refresh-token") | ||
| .isNewMember(true) | ||
| .onboardingCompleted(false) | ||
| .build(); | ||
| } | ||
| } |
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.
@JsonAlias는 Jackson 역직렬화에만 적용되고 springdoc이 만드는 OpenAPI 스키마엔 반영 안 된다고 합니다. @Schema description에 텍스트로만 적어놨는데, 스키마 필드 목록엔 여전히 token만 나와서 문서만 보고 연동하는 프론트 개발자는 identityToken 지원 여부를 놓칠 수 있다고 하네용.
해결법: 별도 스키마 수정까진 필요 없고, 앱 팀에 별도 공지하거나 PR 설명에 "identityToken도 받음" 명시하면 좋을 것 같습니다!