| 91 | #[test] |
| 92 | #[wasm_bindgen_test] |
| 93 | fn encode_with_multiple_extra_custom_headers() { |
| 94 | let my_claims = Claims { |
| 95 | sub: "b@b.com".to_string(), |
| 96 | company: "ACME".to_string(), |
| 97 | exp: OffsetDateTime::now_utc().unix_timestamp() + 10000, |
| 98 | }; |
| 99 | let mut extras = Extras::default(); |
| 100 | extras.insert("custom1".to_string(), "header1".to_string()); |
| 101 | extras.insert("custom2".to_string(), "header2".to_string()); |
| 102 | let header = Header { kid: Some("kid".to_string()), extras, ..Default::default() }; |
| 103 | let token = encode(&header, &my_claims, &EncodingKey::from_secret(b"secret").unwrap()).unwrap(); |
| 104 | let token_data = decode::<Claims>( |
| 105 | &token, |
| 106 | &DecodingKey::from_secret(b"secret").unwrap(), |
| 107 | &Validation::new(Algorithm::HS256), |
| 108 | ) |
| 109 | .unwrap(); |
| 110 | assert_eq!(my_claims, token_data.claims); |
| 111 | assert_eq!("kid", token_data.header.kid.unwrap()); |
| 112 | let extras = token_data.header.extras; |
| 113 | assert_eq!(Some("header1".to_string()), extras.get("custom1").unwrap()); |
| 114 | assert_eq!(Some("header2".to_string()), extras.get("custom2").unwrap()); |
| 115 | } |
| 116 | |
| 117 | #[test] |
| 118 | #[wasm_bindgen_test] |