-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Refactor test utility classes - Use kotlin top level functions…
… and variables
- Loading branch information
Showing
8 changed files
with
47 additions
and
57 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
4 changes: 2 additions & 2 deletions
4
src/test/kotlin/com/template/integration/user/UserGetInfoTest.kt
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,38 +4,35 @@ import io.jsonwebtoken.Jwts | |
import io.jsonwebtoken.SignatureAlgorithm | ||
import java.util.* | ||
|
||
object TestUtils { | ||
const val EMAIL = "[email protected]" | ||
const val NAME = "testUserName" | ||
const val PASSWORD = "testPassword" | ||
const val USER_ID = 1 | ||
const val TOKEN = "token" | ||
const val JWT_SECRET = "TestJwtSecretKey" | ||
const val JWT_ACCESS_TOKEN_EXP = 86400000 | ||
const val JWT_REFRESH_TOKEN_EXP = 604800000 | ||
const val EXTRA_TIME = 2000000 | ||
|
||
const val EMAIL = "[email protected]" | ||
const val NAME = "testUserName" | ||
const val PASSWORD = "testPassword" | ||
const val USER_ID = 1 | ||
const val TOKEN = "token" | ||
const val JWT_SECRET = "TestJwtSecretKey" | ||
const val JWT_ACCESS_TOKEN_EXP = 86400000 | ||
const val JWT_REFRESH_TOKEN_EXP = 604800000 | ||
const val EXTRA_TIME = 2000000 | ||
|
||
fun generateExpiredToken(exp: Int, secret: String): String { | ||
val realExp = EXTRA_TIME + exp | ||
val claims: MutableMap<String, Any> = mutableMapOf() | ||
claims["userId"] = USER_ID | ||
return Jwts.builder() | ||
.setClaims(claims) | ||
.setIssuedAt(Date(System.currentTimeMillis() - realExp)) | ||
.setExpiration(Date(System.currentTimeMillis() - EXTRA_TIME)) | ||
.signWith(SignatureAlgorithm.HS256, secret) | ||
.compact() | ||
} | ||
fun generateExpiredToken(exp: Int, secret: String): String { | ||
val realExp = EXTRA_TIME + exp | ||
val claims: MutableMap<String, Any> = mutableMapOf() | ||
claims["userId"] = USER_ID | ||
return Jwts.builder() | ||
.setClaims(claims) | ||
.setIssuedAt(Date(System.currentTimeMillis() - realExp)) | ||
.setExpiration(Date(System.currentTimeMillis() - EXTRA_TIME)) | ||
.signWith(SignatureAlgorithm.HS256, secret) | ||
.compact() | ||
} | ||
|
||
fun generateOtherSignatureToken(exp: Int): String { | ||
val claims: MutableMap<String, Any> = mutableMapOf() | ||
claims["userId"] = USER_ID | ||
return Jwts.builder() | ||
.setClaims(claims) | ||
.setIssuedAt(Date(System.currentTimeMillis())) | ||
.setExpiration(Date(System.currentTimeMillis() + exp)) | ||
.signWith(SignatureAlgorithm.HS256, "Other Signature") | ||
.compact() | ||
} | ||
fun generateOtherSignatureToken(exp: Int): String { | ||
val claims: MutableMap<String, Any> = mutableMapOf() | ||
claims["userId"] = USER_ID | ||
return Jwts.builder() | ||
.setClaims(claims) | ||
.setIssuedAt(Date(System.currentTimeMillis())) | ||
.setExpiration(Date(System.currentTimeMillis() + exp)) | ||
.signWith(SignatureAlgorithm.HS256, "Other Signature") | ||
.compact() | ||
} |