Skip to content

Commit 8373e2f

Browse files
committed
refactor: 코드래빗 리뷰사항 적용
- 테스트에서 Token 생성 시, TTL을 30초로 수정 - TTL이 너무 짧으면 테스트가 간헐적으로 꺠질 위험 존재
1 parent d03f945 commit 8373e2f

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/test/java/com/example/solidconnection/security/authentication/TokenAuthenticationProviderTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ void setUp() {
4444
user = siteUserFixture.사용자();
4545
}
4646

47+
private static final long VALID_TOKEN_TTL_MS = 30 * 1000L;
48+
4749
@Test
4850
void 처리할_수_있는_타입인지를_반환한다() {
4951
// given
@@ -118,7 +120,7 @@ private String createValidToken(long id) {
118120
return Jwts.builder()
119121
.subject(String.valueOf(id))
120122
.issuedAt(new Date())
121-
.expiration(new Date(System.currentTimeMillis() + 1000))
123+
.expiration(new Date(System.currentTimeMillis() + VALID_TOKEN_TTL_MS))
122124
.signWith(Keys.hmacShaKeyFor(jwtProperties.secret().getBytes(StandardCharsets.UTF_8)))
123125
.compact();
124126
}
@@ -127,7 +129,7 @@ private String createExpiredToken() {
127129
return Jwts.builder()
128130
.subject(String.valueOf(user.getId()))
129131
.issuedAt(new Date())
130-
.expiration(new Date(System.currentTimeMillis() - 1000))
132+
.expiration(new Date(System.currentTimeMillis() - VALID_TOKEN_TTL_MS))
131133
.signWith(Keys.hmacShaKeyFor(jwtProperties.secret().getBytes(StandardCharsets.UTF_8)))
132134
.compact();
133135
}
@@ -136,7 +138,7 @@ private String createWrongSubjectTypeToken() {
136138
return Jwts.builder()
137139
.subject("subject")
138140
.issuedAt(new Date())
139-
.expiration(new Date(System.currentTimeMillis() + 1000))
141+
.expiration(new Date(System.currentTimeMillis() + VALID_TOKEN_TTL_MS))
140142
.signWith(Keys.hmacShaKeyFor(jwtProperties.secret().getBytes(StandardCharsets.UTF_8)))
141143
.compact();
142144
}

0 commit comments

Comments
 (0)