Skip to content

Commit

Permalink
Add RBAC success test with debugging information for JWT validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehrn0ush committed Oct 5, 2024
1 parent 950a8c6 commit a325232
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/auth/rbac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,34 @@ mod tests {
result
);
}

#[test]
fn test_rbac_check_success() {
dotenv::dotenv().ok(); // Ensure .env is loaded

// Retrieve the JWT_SECRET from the environment
let jwt_secret = env::var("JWT_SECRET").expect("JWT_SECRET must be set in .env");

println!("JWT Secret being used: {}", jwt_secret);

// Create claims with "admin" and "user" roles and a valid future expiration time
let claims = TestClaims {
sub: "user123".to_string(),
exp: 9999999999, // Future expiration time
roles: vec!["admin".to_string(), "user".to_string()],
};

// Generate the test JWT token using the same secret
let token = generate_test_token(claims, &jwt_secret);

println!("Generated Token: {}", token);

// Perform the RBAC check for the "admin" role
let result = rbac_check(&token, "admin");

println!("RBAC Check Result: {:?}", result);

// Ensure the result is Ok, meaning the role was validated successfully
assert!(result.is_ok(), "Expected Ok, but got: {:?}", result);
}
}

0 comments on commit a325232

Please sign in to comment.