-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
logout시 refreshtoken이 삭제되는 api 구현 (#632)
* feat: 로그아웃 API 구현 * refactor: refreshtoken delete api 이름 변경 * refactor: dev에 localhost:3000 cors 추가 * refactor: 리뷰반영 deleteMapping -> patchMapping으로 변경 * test: doPring 제거 * test: 인스턴스 변수 띄어쓰기 추가 * test: repositoryTestConfig에 persistMember 추가 및 리팩토링 * test: given when then 에서 컨벤션 일관화
- Loading branch information
Showing
21 changed files
with
320 additions
and
31 deletions.
There are no files selected for viewing
Submodule secret
updated
from 03b602 to 83ee50
This file contains 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,25 @@ | ||
ifndef::snippets[] | ||
:snippets: ../../../build/generated-snippets | ||
endif::[] | ||
:doctype: book | ||
:icons: font | ||
:source-highlighter: highlight.js | ||
:toc: left | ||
:toclevels: 3 | ||
:sectlinks: | ||
:operation-http-request-title: Example Request | ||
:operation-http-response-title: Example Response | ||
|
||
==== *로그아웃 API* | ||
|
||
===== *Http Request* | ||
|
||
include::{snippets}/../../build/generated-snippets/oauth-logout-api-test/logout/http-request.adoc[] | ||
|
||
===== *Http Request Headers* | ||
|
||
include::{snippets}/../../build/generated-snippets/oauth-logout-api-test/logout/request-headers.adoc[] | ||
|
||
===== *Http Response* | ||
|
||
include::{snippets}/../../build/generated-snippets/oauth-logout-api-test/logout/http-response.adoc[] |
This file contains 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 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 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 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 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 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
67 changes: 67 additions & 0 deletions
67
backend/baton/src/test/java/touch/baton/assure/oauth/OauthDeleteAssuredTest.java
This file contains 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,67 @@ | ||
package touch.baton.assure.oauth; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import touch.baton.config.AssuredTestConfig; | ||
import touch.baton.config.infra.auth.oauth.authcode.FakeAuthCodes; | ||
import touch.baton.domain.common.exception.ClientErrorCode; | ||
import touch.baton.domain.oauth.command.OauthType; | ||
import touch.baton.domain.oauth.command.token.Tokens; | ||
import touch.baton.fixture.domain.MemberFixture; | ||
|
||
@SuppressWarnings("NonAsciiCharacters") | ||
class OauthDeleteAssuredTest extends AssuredTestConfig { | ||
|
||
@Test | ||
void 로그아웃을_성공한다() { | ||
// given | ||
OauthAssuredSupport | ||
.클라이언트_요청() | ||
.소셜_로그인을_위한_리다이렉트_URL을_요청한다(OauthType.GITHUB) | ||
|
||
.서버_응답() | ||
.소셜_로그인을_위한_리다이렉트_URL_요청_성공을_검증한다(); | ||
|
||
final Tokens 액세스_토큰과_리프레시_토큰 = OauthAssuredSupport | ||
.클라이언트_요청() | ||
.AuthCode를_통해_소셜_토큰을_발급_받은_후_사용자를_회원가입_한다(OauthType.GITHUB, FakeAuthCodes.ethanAuthCode()) | ||
|
||
.서버_응답() | ||
.AuthCode를_통해_소셜_토큰_발급_및_사용자_회원가입에_성공한다() | ||
.액세스_토큰과_리프레시_토큰을_반환한다(MemberFixture.createEthan()); | ||
|
||
// when, then | ||
OauthAssuredSupport | ||
.클라이언트_요청() | ||
.로그아웃을_요청한다(액세스_토큰과_리프레시_토큰.accessToken()) | ||
|
||
.서버_응답() | ||
.로그아웃이_성공한다(); | ||
} | ||
|
||
@Test | ||
void 액세스_토큰이_없이_로그아웃을_요청하면_실패한다() { | ||
// given | ||
OauthAssuredSupport | ||
.클라이언트_요청() | ||
.소셜_로그인을_위한_리다이렉트_URL을_요청한다(OauthType.GITHUB) | ||
|
||
.서버_응답() | ||
.소셜_로그인을_위한_리다이렉트_URL_요청_성공을_검증한다(); | ||
|
||
final Tokens 액세스_토큰과_리프레시_토큰 = OauthAssuredSupport | ||
.클라이언트_요청() | ||
.AuthCode를_통해_소셜_토큰을_발급_받은_후_사용자를_회원가입_한다(OauthType.GITHUB, FakeAuthCodes.ethanAuthCode()) | ||
|
||
.서버_응답() | ||
.AuthCode를_통해_소셜_토큰_발급_및_사용자_회원가입에_성공한다() | ||
.액세스_토큰과_리프레시_토큰을_반환한다(MemberFixture.createEthan()); | ||
|
||
// when, then | ||
OauthAssuredSupport | ||
.클라이언트_요청() | ||
.액세스_토큰_없이_로그아웃을_요청한다() | ||
|
||
.서버_응답() | ||
.오류가_발생한다(ClientErrorCode.OAUTH_AUTHORIZATION_VALUE_IS_NULL); | ||
} | ||
} |
This file contains 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
39 changes: 39 additions & 0 deletions
39
backend/baton/src/test/java/touch/baton/document/oauth/OauthLogoutApiTest.java
This file contains 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,39 @@ | ||
package touch.baton.document.oauth; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import touch.baton.config.RestdocsConfig; | ||
import touch.baton.domain.member.command.Member; | ||
import touch.baton.fixture.domain.MemberFixture; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.apache.http.HttpHeaders.AUTHORIZATION; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; | ||
import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders; | ||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.patch; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
class OauthLogoutApiTest extends RestdocsConfig { | ||
|
||
@DisplayName("로그아웃을 하면 리프레시 토큰이 삭제된다.") | ||
@Test | ||
void logout() throws Exception { | ||
// given, when | ||
final Member ethan = MemberFixture.createEthan(); | ||
final String accessToken = getAccessTokenBySocialId(ethan.getSocialId().getValue()); | ||
given(oauthMemberCommandRepository.findBySocialId(any())).willReturn(Optional.ofNullable(ethan)); | ||
|
||
// then | ||
mockMvc.perform(patch("/api/v1/oauth/logout") | ||
.header(AUTHORIZATION, "Bearer " + accessToken)) | ||
.andExpect(status().isNoContent()) | ||
.andDo(restDocs.document( | ||
requestHeaders( | ||
headerWithName("Authorization").description("Access Token") | ||
) | ||
)); | ||
} | ||
} |
This file contains 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 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 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 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
Oops, something went wrong.