11#[ cfg( test) ]
22mod jwt_tests {
3- use super :: * ;
43 use jwtk:: ecdsa:: EcdsaPrivateKey ;
5-
4+
5+ use crate :: messages:: utils:: { generate_access_token, generate_jwt} ;
6+
67 fn setup_test_key ( ) -> EcdsaPrivateKey {
7- // This would need a valid test key for actual testing
8- // For now, we'll just create a placeholder that would be replaced with actual test keys
9- let test_pem = "-----BEGIN EC PRIVATE KEY-----\n MHcCAQEEILULtd0+Rx4/vMF/cVZ/SYU6Fo/HlgQF==\n -----END EC PRIVATE KEY-----" ;
8+ let test_pem = "-----BEGIN EC PRIVATE KEY-----\n MHcCAQEEIFxrWIO1BpNTG1oiLRKc9fPHUuF3PHtx9RgNJAdZWhDBoAoGCCqGSM49\n AwEHoUQDQgAEdqr9eg/9hxsGwHatmOMyAQX2PfW1uj8RA4xKy3e4mUTO0+nUPlwl\n 1ZqiYMy8ciFFRu6Jj7WDU/lVrqB1HvnCgQ==\n -----END EC PRIVATE KEY-----" ;
109 EcdsaPrivateKey :: from_pem ( test_pem. as_bytes ( ) ) . expect ( "Test key creation failed" )
1110 }
12-
11+
1312 #[ test]
1413 fn test_generate_jwt_structure ( ) {
15- // This test would verify the JWT has the correct structure
16- // Would need proper test keys to actually run
17- /*
1814 let key = setup_test_key ( ) ;
1915 let api_key = "test_api_key" . to_string ( ) ;
2016 let now = 1234567890 ;
2117 let uri = "wss://test.example.com" . to_string ( ) ;
22-
2318 let token = generate_jwt ( api_key. clone ( ) , now, uri. clone ( ) , key) ;
24-
25- // Verify token is not empty
2619 assert ! ( !token. is_empty( ) ) ;
27-
28- // Verify token has three parts separated by dots
29- let parts: Vec<&str> = token.split('.').collect();
30- assert_eq!(parts.len(), 3);
31- */
20+ assert_eq ! ( token. split( '.' ) . count( ) , 3 ) ;
3221 }
33-
22+
3423 #[ test]
3524 fn test_generate_access_token ( ) {
36- // Similar to above, would verify access token generation
37- // Would need proper test keys
25+ let key = setup_test_key ( ) ;
26+ let token = generate_access_token ( "api" , key, "wss://example.com" ) ;
27+ assert ! ( !token. is_empty( ) ) ;
28+ assert_eq ! ( token. split( '.' ) . count( ) , 3 ) ;
3829 }
39- }
30+ }
0 commit comments