-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: profile 환경에 따른 cookie 설정 분리 및 config 업데이트 #102
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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
33 changes: 0 additions & 33 deletions
33
src/main/java/com/moabam/global/common/util/CookieUtils.java
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
src/main/java/com/moabam/global/common/util/cookie/CookieDevUtils.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,22 @@ | ||
package com.moabam.global.common.util.cookie; | ||
|
||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.stereotype.Component; | ||
|
||
import jakarta.servlet.http.Cookie; | ||
|
||
@Component | ||
@Profile({"dev", "local", "test"}) | ||
public class CookieDevUtils extends CookieUtils { | ||
|
||
protected Cookie detailCookies(String name, String value, long expireTime) { | ||
Cookie cookie = new Cookie(name, value); | ||
cookie.setSecure(true); | ||
cookie.setHttpOnly(true); | ||
cookie.setPath("/"); | ||
cookie.setMaxAge((int)expireTime); | ||
cookie.setAttribute("SameSite", "None"); | ||
|
||
return cookie; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/moabam/global/common/util/cookie/CookieProdUtils.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,22 @@ | ||
package com.moabam.global.common.util.cookie; | ||
|
||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.stereotype.Component; | ||
|
||
import jakarta.servlet.http.Cookie; | ||
|
||
@Component | ||
@Profile({"prod"}) | ||
public class CookieProdUtils extends CookieUtils { | ||
|
||
protected Cookie detailCookies(String name, String value, long expireTime) { | ||
Cookie cookie = new Cookie(name, value); | ||
cookie.setSecure(true); | ||
cookie.setHttpOnly(true); | ||
cookie.setPath("/"); | ||
cookie.setMaxAge((int)expireTime); | ||
|
||
return cookie; | ||
} | ||
} | ||
|
22 changes: 22 additions & 0 deletions
22
src/main/java/com/moabam/global/common/util/cookie/CookieUtils.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,22 @@ | ||
package com.moabam.global.common.util.cookie; | ||
|
||
import jakarta.servlet.http.Cookie; | ||
|
||
public abstract class CookieUtils { | ||
|
||
public Cookie tokenCookie(String name, String value, long expireTime) { | ||
return detailCookies(name, value, expireTime); | ||
} | ||
|
||
public Cookie typeCookie(String value, long expireTime) { | ||
return detailCookies("token_type", value, expireTime); | ||
} | ||
|
||
public Cookie deleteCookie(Cookie cookie) { | ||
cookie.setMaxAge(0); | ||
cookie.setPath("/"); | ||
return cookie; | ||
} | ||
|
||
protected abstract Cookie detailCookies(String name, String value, long expireTime); | ||
} |
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
Submodule config
updated
from 4c6ff3 to b960de
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
57 changes: 57 additions & 0 deletions
57
src/test/java/com/moabam/global/common/util/CookieMakeTest.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,57 @@ | ||
package com.moabam.global.common.util; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import com.moabam.global.common.util.cookie.CookieDevUtils; | ||
import com.moabam.global.common.util.cookie.CookieProdUtils; | ||
import com.moabam.global.common.util.cookie.CookieUtils; | ||
|
||
import jakarta.servlet.http.Cookie; | ||
|
||
class CookieMakeTest { | ||
|
||
CookieUtils cookieDevUtils; | ||
CookieUtils cookieProdUtils; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
cookieDevUtils = new CookieDevUtils(); | ||
cookieProdUtils = new CookieProdUtils(); | ||
} | ||
|
||
@DisplayName("prod환경에서 cookie 생성 테스트") | ||
@Test | ||
void prodUtilsTest() { | ||
// Given | ||
Cookie cookie = cookieProdUtils.tokenCookie("access_token", "value", 10000); | ||
|
||
// When + Then | ||
assertAll( | ||
() -> assertThat(cookie.getSecure()).isTrue(), | ||
() -> assertThat(cookie.getSecure()).isTrue(), | ||
() -> assertThat(cookie.getPath()).isEqualTo("/"), | ||
() -> assertThat(cookie.getMaxAge()).isEqualTo(10000) | ||
); | ||
} | ||
|
||
@DisplayName("dev환경에서 cookie 생성 테스트") | ||
@Test | ||
void devUtilsTest() { | ||
// Given | ||
Cookie cookie = cookieDevUtils.tokenCookie("access_token", "value", 10000); | ||
|
||
// When + Then | ||
assertAll( | ||
() -> assertThat(cookie.getSecure()).isTrue(), | ||
() -> assertThat(cookie.getSecure()).isTrue(), | ||
() -> assertThat(cookie.getPath()).isEqualTo("/"), | ||
() -> assertThat(cookie.getMaxAge()).isEqualTo(10000), | ||
() -> assertThat(cookie.getAttribute("SameSite")).isEqualTo("None") | ||
); | ||
} | ||
} |
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
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.
오호 prod와 개발 서버를 나누기 위해서 결국 이렇게 됐군요...!