Skip to content

Commit 016ba83

Browse files
committed
refactor(OauthProperties): isAllowedOrigin() 허용 범위 축소 및 로직 개선
1 parent 003cbe8 commit 016ba83

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/main/java/timeeat/client/oauth/OauthProperties.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ private void validateOrigin(String origin) {
5858

5959
public boolean isAllowedOrigin(String origin) {
6060
return allowedOrigins.stream()
61-
.anyMatch(allowedOrigin -> origin.trim().startsWith(allowedOrigin));
61+
.anyMatch(allowedOrigin -> isMatchedOrigin(allowedOrigin, origin));
62+
}
63+
64+
private boolean isMatchedOrigin(String allowedOrigin, String origin) {
65+
return origin.trim().equals(allowedOrigin)
66+
|| origin.trim().equals(allowedOrigin + "/");
6267
}
6368
}

src/test/java/timeeat/client/oauth/OauthPropertiesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import java.util.List;
77
import org.junit.jupiter.api.Nested;
8-
import org.junit.jupiter.api.Test;
98
import org.junit.jupiter.params.ParameterizedTest;
109
import org.junit.jupiter.params.provider.NullAndEmptySource;
1110
import org.junit.jupiter.params.provider.ValueSource;
@@ -56,7 +55,8 @@ class IsAllowedOrigin {
5655
assertThat(isAllowed).isTrue();
5756
}
5857

59-
@Test
58+
@ParameterizedTest
59+
@ValueSource(strings = {"https://not-allowed.com", "http://localhost:8080/path", "http://localhost:8080nono"})
6060
void 허용되지_않은_오리진인_경우_false를_반환한다() {
6161
OauthProperties oauthProperties = new OauthProperties("client-id", "/path",
6262
List.of("http://localhost:8080"));

0 commit comments

Comments
 (0)