Skip to content

Commit

Permalink
test : 불필요한 의존성 삭제 (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
binary-ho committed Mar 12, 2024
1 parent a877b25 commit 0102f77
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gdsc.binaryho.imhere.mock;
package gdsc.binaryho.imhere.security;

import gdsc.binaryho.imhere.security.jwt.TokenPropertyHolder;
import java.time.Duration;
Expand All @@ -7,11 +7,13 @@ public class FakeTokenPropertyHolder implements TokenPropertyHolder {

private final String secret;
private final Duration accessTokenExpiration;
private final String accessTokenPrefix;


public FakeTokenPropertyHolder(String secret, Duration accessTokenExpiration) {
public FakeTokenPropertyHolder(String secret, Duration accessTokenExpiration, String accessTokenPrefix) {
this.secret = secret;
this.accessTokenExpiration = accessTokenExpiration;
this.accessTokenPrefix = accessTokenPrefix;
}

@Override
Expand All @@ -26,6 +28,6 @@ public Duration getAccessTokenExpiration() {

@Override
public String getAccessTokenPrefix() {
return "prefix";
return accessTokenPrefix;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import gdsc.binaryho.imhere.core.member.Role;
import gdsc.binaryho.imhere.core.member.infrastructure.MemberRepository;
import gdsc.binaryho.imhere.security.jwt.Token;
import gdsc.binaryho.imhere.security.jwt.TokenPropertyHolder;
import gdsc.binaryho.imhere.security.jwt.TokenUtil;
import java.util.Optional;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -40,9 +39,6 @@ public class SecurityConfigTest {
@MockBean
private MemberRepository memberRepository;

@Autowired
private TokenPropertyHolder tokenPropertyHolder;

@Test
public void 인증이_필요한_경로에_접근하면_깃허브_로그인_페이지로_Redirection_된다() throws Exception {
mockMvc.perform(post("/")
Expand All @@ -58,10 +54,9 @@ public class SecurityConfigTest {
.willReturn(Optional.of(MOCK_STUDENT));
Token token = tokenUtil.createToken(MOCK_STUDENT.getId(), Role.LECTURER);

String accessTokenPrefix = tokenPropertyHolder.getAccessTokenPrefix();
mockMvc.perform(get("/api/lecture")
.contentType(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, accessTokenPrefix + token.getAccessToken())
.header(HttpHeaders.AUTHORIZATION, token.getAccessToken())
)
.andExpect(status().is2xxSuccessful());
}
Expand All @@ -72,10 +67,9 @@ public class SecurityConfigTest {
.willReturn(Optional.of(MOCK_STUDENT));
Token token = tokenUtil.createToken(1L, Role.STUDENT);

String accessTokenPrefix = tokenPropertyHolder.getAccessTokenPrefix();
mockMvc.perform(post("/api/admin/role/1")
.contentType(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, accessTokenPrefix + token.getAccessToken())
.header(HttpHeaders.AUTHORIZATION, token.getAccessToken())
)
.andExpect(status().isForbidden());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import gdsc.binaryho.imhere.core.member.Role;
import gdsc.binaryho.imhere.mock.FixedSeoulTimeHolder;
import gdsc.binaryho.imhere.mock.FakeTokenPropertyHolder;
import gdsc.binaryho.imhere.security.FakeTokenPropertyHolder;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
Expand All @@ -27,7 +27,7 @@ public class TokenUtilTest {
private static final long ACCESS_TOKEN_EXPIRATION_TIME = 1000L * 60L * 20L;
private static final long TIME_NOW = FixedSeoulTimeHolder.FIXED_MILLISECONDS;

TokenPropertyHolder tokenPropertyHolder = new FakeTokenPropertyHolder(SECRET, Duration.ofDays(999L));
TokenPropertyHolder tokenPropertyHolder = new FakeTokenPropertyHolder(SECRET, Duration.ofDays(999L), "prefix");
TokenUtil tokenUtil = new TokenUtil(new FixedSeoulTimeHolder(), tokenPropertyHolder);

@Test
Expand Down

0 comments on commit 0102f77

Please sign in to comment.