MCPcopy Create free account
hub / github.com/Commit-Boost/commit-boost-client / test_jwt_validation

Function test_jwt_validation

crates/common/src/utils.rs:467–486  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

465
466 #[test]
467 fn test_jwt_validation() {
468 // Check valid JWT
469 let jwt = create_jwt(&ModuleId("DA_COMMIT".to_string()), "secret").unwrap();
470 let module_id = decode_jwt(jwt.clone()).unwrap();
471 assert_eq!(module_id, ModuleId("DA_COMMIT".to_string()));
472 let response = validate_jwt(jwt, "secret");
473 assert!(response.is_ok());
474
475 // Check expired JWT
476 let expired_jwt = Jwt::from("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3NDI5OTU5NDYsIm1vZHVsZSI6IkRBX0NPTU1JVCJ9.iiq4Z2ed2hk3c3c-cn2QOQJWE5XUOc5BoaIPT-I8q-s".to_string());
477 let response = validate_jwt(expired_jwt, "secret");
478 assert!(response.is_err());
479 assert_eq!(response.unwrap_err().to_string(), "ExpiredSignature");
480
481 // Check invalid signature JWT
482 let invalid_jwt = Jwt::from("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3NDI5OTU5NDYsIm1vZHVsZSI6IkRBX0NPTU1JVCJ9.w9WYdDNzgDjYTvjBkk4GGzywGNBYPxnzU2uJWzPUT1s".to_string());
483 let response = validate_jwt(invalid_jwt, "secret");
484 assert!(response.is_err());
485 assert_eq!(response.unwrap_err().to_string(), "InvalidSignature");
486 }
487}

Callers

nothing calls this directly

Calls 4

create_jwtFunction · 0.85
ModuleIdClass · 0.85
decode_jwtFunction · 0.85
validate_jwtFunction · 0.85

Tested by

no test coverage detected