MCPcopy Create free account
hub / github.com/Keats/jsonwebtoken / encode_with_multiple_extra_custom_headers

Function encode_with_multiple_extra_custom_headers

tests/hmac.rs:87–109  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

insertMethod · 0.80
encodeFunction · 0.50

Tested by

no test coverage detected