Skip to content

Commit b23de4f

Browse files
committed
resolved comments
Signed-off-by: Saranya-jena <[email protected]>
1 parent 009ffc2 commit b23de4f

File tree

1 file changed

+6
-4
lines changed
  • chaoscenter/graphql/server/pkg/authorization/tests

1 file changed

+6
-4
lines changed

chaoscenter/graphql/server/pkg/authorization/tests/fuzz_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ import (
1010
"time"
1111
)
1212

13+
var currTime = time.Now()
14+
1315
// generateExpiredFakeJWTToken generates a fake JWT token with expiration time set to the past
1416
func generateExpiredFakeJWTToken(username string) string {
1517
token := jwt.New(jwt.SigningMethodHS256)
1618
claims := token.Claims.(jwt.MapClaims)
1719
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
1921
signedToken, _ := token.SignedString([]byte("your-secret-key")) // Sign the token with a secret key
2022
return signedToken
2123
}
@@ -25,7 +27,7 @@ func generateFakeJWTTokenWithInvalidSignature(username string) string {
2527
token := jwt.New(jwt.SigningMethodHS256)
2628
claims := token.Claims.(jwt.MapClaims)
2729
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
2931
signedToken, _ := token.SignedString([]byte("invalid-secret-key")) // Sign the token with an invalid secret key
3032
return signedToken
3133
}
@@ -34,7 +36,7 @@ func generateFakeJWTTokenWithInvalidSignature(username string) string {
3436
func generateFakeJWTToken(username string) string {
3537
token := jwt.NewWithClaims(jwt.SigningMethodHS512, jwt.MapClaims{
3638
"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
3840
})
3941

4042
signedToken, _ := token.SignedString([]byte(utils.Config.JwtSecret)) // No signature is needed for testing
@@ -86,7 +88,7 @@ func FuzzGetUsername(f *testing.F) {
8688
// generateJWTToken generates a JWT token with the given claims
8789
func generateJWTTokenFromClaims(claims jwt.MapClaims) (string, error) {
8890
// 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()
9092

9193
// Create a new token with the claims
9294
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)

0 commit comments

Comments
 (0)