Skip to content

Commit 8f43bfe

Browse files
Add test codes for refresh_token
If I had added the test codes before, I wouldn't have needed to release v1.0.2
1 parent 7018995 commit 8f43bfe

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

src/test/java/com/patternknife/securityhelper/oauth2/integration/auth/CustomerIntegrationTest.java

+27-4
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
import java.nio.charset.StandardCharsets;
3434
import java.util.Map;
3535

36-
import static org.junit.jupiter.api.Assertions.assertEquals;
37-
import static org.junit.jupiter.api.Assertions.assertTrue;
36+
import static org.junit.jupiter.api.Assertions.*;
3837
import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName;
3938
import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders;
4039
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
@@ -43,6 +42,8 @@
4342
import static org.springframework.restdocs.payload.PayloadDocumentation.relaxedResponseFields;
4443
import static org.springframework.restdocs.request.RequestDocumentation.formParameters;
4544
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
45+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
46+
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
4647
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
4748

4849
@ExtendWith(RestDocumentationExtension.class)
@@ -196,6 +197,12 @@ public void test_SameAppTokensUseSameAccessToken_EXPOSED() throws Exception {
196197
jsonResponse = new JSONObject(responseString);
197198
String accessToken2 = jsonResponse.getJSONObject("data").getString("access_token");
198199

200+
if(accessToken2.equals(accessToken)){
201+
assertNotEquals("The new access_token issued with a refresh_token should not be the same value as the existing access_token.", accessToken2, accessToken);
202+
}else{
203+
assertTrue(true, "성공");
204+
}
205+
199206
/*
200207
* LOGOUT
201208
*
@@ -246,7 +253,12 @@ public void test_SameAppTokensUseSameAccessToken_EXPOSED() throws Exception {
246253
refreshToken = jsonResponse.getJSONObject("data").getString("refresh_token");
247254
String finalAccessTokenForAppToken1 = jsonResponse.getJSONObject("data").getString("access_token");
248255

249-
256+
// Check the availability of the access token for APPTOKENAAA
257+
mockMvc.perform(get("/api/v1/customers/me")
258+
.contentType(MediaType.APPLICATION_JSON)
259+
.header(HttpHeaders.AUTHORIZATION, "Bearer " + finalAccessTokenForAppToken1))
260+
.andDo(print())
261+
.andExpect(status().isOk());
250262

251263
if(!accessTokenForAppToken1.equals(finalAccessTokenForAppToken1)){
252264
assertEquals("The Access Token corresponding to the initial app token was different.", accessTokenForAppToken1, finalAccessTokenForAppToken1);
@@ -357,6 +369,12 @@ public void test_SameAppTokensUseSameAccessToken_ORIGINAL() throws Exception {
357369
String accessToken2 = jsonResponse.getString("access_token");
358370

359371

372+
if(accessToken2.equals(accessToken)){
373+
assertNotEquals("The new access_token issued with a refresh_token should not be the same value as the existing access_token.", accessToken2, accessToken);
374+
}else{
375+
assertTrue(true, "성공");
376+
}
377+
360378
mockMvc.perform(RestDocumentationRequestBuilders.get("/api/v1/customers/me/logout")
361379
.contentType(MediaType.APPLICATION_JSON)
362380
.header(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken2))
@@ -399,7 +417,12 @@ public void test_SameAppTokensUseSameAccessToken_ORIGINAL() throws Exception {
399417
String finalAccessTokenForAppToken1 = jsonResponse.getString("access_token");
400418

401419

402-
420+
// Check the availability of the access token for APPTOKENAAA
421+
mockMvc.perform(get("/api/v1/customers/me")
422+
.contentType(MediaType.APPLICATION_JSON)
423+
.header(HttpHeaders.AUTHORIZATION, "Bearer " + finalAccessTokenForAppToken1))
424+
.andDo(print())
425+
.andExpect(status().isOk());
403426

404427
if(!accessTokenForAppToken1.equals(finalAccessTokenForAppToken1)){
405428
assertEquals("The Access Token corresponding to the initial app token was different.", accessTokenForAppToken1, finalAccessTokenForAppToken1);

0 commit comments

Comments
 (0)