@@ -10,12 +10,14 @@ import (
10
10
"time"
11
11
)
12
12
13
+ var currTime = time .Now ()
14
+
13
15
// generateExpiredFakeJWTToken generates a fake JWT token with expiration time set to the past
14
16
func generateExpiredFakeJWTToken (username string ) string {
15
17
token := jwt .New (jwt .SigningMethodHS256 )
16
18
claims := token .Claims .(jwt.MapClaims )
17
19
claims ["username" ] = username
18
- claims ["exp" ] = time . Now (). Add (- time .Hour ).Unix () // Set expiration time to 1 hour ago
20
+ claims ["exp" ] = currTime . Add (- time .Hour ).Unix () // Set expiration time to 1 hour ago
19
21
signedToken , _ := token .SignedString ([]byte ("your-secret-key" )) // Sign the token with a secret key
20
22
return signedToken
21
23
}
@@ -25,7 +27,7 @@ func generateFakeJWTTokenWithInvalidSignature(username string) string {
25
27
token := jwt .New (jwt .SigningMethodHS256 )
26
28
claims := token .Claims .(jwt.MapClaims )
27
29
claims ["username" ] = username
28
- claims ["exp" ] = time . Now (). Add (time .Hour * 24 ).Unix () // Set expiration time to 24 hours from now
30
+ claims ["exp" ] = currTime . Add (time .Hour * 24 ).Unix () // Set expiration time to 24 hours from now
29
31
signedToken , _ := token .SignedString ([]byte ("invalid-secret-key" )) // Sign the token with an invalid secret key
30
32
return signedToken
31
33
}
@@ -34,7 +36,7 @@ func generateFakeJWTTokenWithInvalidSignature(username string) string {
34
36
func generateFakeJWTToken (username string ) string {
35
37
token := jwt .NewWithClaims (jwt .SigningMethodHS512 , jwt.MapClaims {
36
38
"username" : username ,
37
- "exp" : time . Now () .Add (time .Hour * 24 ).Unix (), // Set expiration time to 24 hours from now
39
+ "exp" : currTime .Add (time .Hour * 24 ).Unix (), // Set expiration time to 24 hours from now
38
40
})
39
41
40
42
signedToken , _ := token .SignedString ([]byte (utils .Config .JwtSecret )) // No signature is needed for testing
@@ -86,7 +88,7 @@ func FuzzGetUsername(f *testing.F) {
86
88
// generateJWTToken generates a JWT token with the given claims
87
89
func generateJWTTokenFromClaims (claims jwt.MapClaims ) (string , error ) {
88
90
// Set expiration time to 24 hours from now
89
- claims ["exp" ] = time . Now () .Add (time .Hour * 24 ).Unix ()
91
+ claims ["exp" ] = currTime .Add (time .Hour * 24 ).Unix ()
90
92
91
93
// Create a new token with the claims
92
94
token := jwt .NewWithClaims (jwt .SigningMethodHS256 , claims )
0 commit comments