-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/woowacourse-teams/2024-d…
- Loading branch information
Showing
11 changed files
with
150 additions
and
65 deletions.
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
27 changes: 0 additions & 27 deletions
27
backend/src/main/java/ddangkong/controller/room/RejoinCookieEncryptor.java
This file was deleted.
Oops, something went wrong.
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
44 changes: 44 additions & 0 deletions
44
backend/src/main/java/ddangkong/controller/room/RoomMemberCookieEncryptor.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,44 @@ | ||
package ddangkong.controller.room; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.web.server.Cookie.SameSite; | ||
import org.springframework.http.ResponseCookie; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class RoomMemberCookieEncryptor { | ||
|
||
private static final String DEFAULT_PATH = "/api/balances/rooms"; | ||
private static final String LOCALHOST = "http://localhost"; | ||
|
||
private final EncryptionUtils encryptionUtils; | ||
|
||
private final String rejoinKey; | ||
|
||
public RoomMemberCookieEncryptor(EncryptionUtils encryptionUtils, @Value("${cookie.rejoin-key}") String rejoinKey) { | ||
this.encryptionUtils = encryptionUtils; | ||
this.rejoinKey = rejoinKey; | ||
} | ||
|
||
public ResponseCookie getEncodedCookie(Object value, String origin) { | ||
String encrypt = encryptionUtils.encrypt(String.valueOf(value)); | ||
return ResponseCookie.from(rejoinKey, encrypt) | ||
.httpOnly(true) | ||
.secure(true) | ||
.path(DEFAULT_PATH) | ||
.sameSite(getSameSiteOption(origin)) | ||
.build(); | ||
} | ||
|
||
private String getSameSiteOption(String origin) { | ||
if (origin != null && origin.startsWith(LOCALHOST)) { | ||
return SameSite.NONE.attributeValue(); | ||
} | ||
return SameSite.LAX.attributeValue(); | ||
} | ||
|
||
public Long getDecodedCookieValue(String cookieValue) { | ||
return Long.parseLong(encryptionUtils.decrypt(cookieValue)); | ||
} | ||
} |
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
10 changes: 10 additions & 0 deletions
10
backend/src/main/java/ddangkong/facade/room/dto/RoomMemberResponse.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,10 @@ | ||
package ddangkong.facade.room.dto; | ||
|
||
import ddangkong.facade.room.member.dto.MemberResponse; | ||
|
||
public record RoomMemberResponse( | ||
Long roomId, | ||
String roomUuid, | ||
MemberResponse member | ||
) { | ||
} |
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
45 changes: 45 additions & 0 deletions
45
backend/src/test/java/ddangkong/controller/room/RoomMemberCookieEncryptorTest.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,45 @@ | ||
package ddangkong.controller.room; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import ddangkong.controller.BaseControllerTest; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseCookie; | ||
|
||
class RoomMemberCookieEncryptorTest extends BaseControllerTest { | ||
|
||
@Autowired | ||
private RoomMemberCookieEncryptor roomMemberCookieEncryptor; | ||
|
||
@Nested | ||
class 방_멤버_쿠키_암호화 { | ||
|
||
@Test | ||
void 로컬_환경인_경우_SameSite는_None_이다() { | ||
// given | ||
String value = "ThisIsMySecretKe"; | ||
String origin = "http://localhost:3306/api"; | ||
|
||
// when | ||
ResponseCookie encodedCookie = roomMemberCookieEncryptor.getEncodedCookie(value, origin); | ||
|
||
// then | ||
assertThat(encodedCookie.getSameSite()).isEqualTo("None"); | ||
} | ||
|
||
@Test | ||
void 로컬_환경이_아닌_경우_SameSite는_Lax_이다() { | ||
// given | ||
String value = "ThisIsMySecretKe"; | ||
String origin = "ddangkong.kr"; | ||
|
||
// when | ||
ResponseCookie encodedCookie = roomMemberCookieEncryptor.getEncodedCookie(value, origin); | ||
|
||
// then | ||
assertThat(encodedCookie.getSameSite()).isEqualTo("Lax"); | ||
} | ||
} | ||
} |
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.