@@ -52,6 +52,7 @@ fn encode_with_custom_header() {
52
52
. unwrap ( ) ;
53
53
assert_eq ! ( my_claims, token_data. claims) ;
54
54
assert_eq ! ( "kid" , token_data. header. kid. unwrap( ) ) ;
55
+ assert ! ( token_data. header. extras. is_empty( ) ) ;
55
56
}
56
57
57
58
#[ test]
@@ -62,9 +63,9 @@ fn encode_with_extra_custom_header() {
62
63
company : "ACME" . to_string ( ) ,
63
64
exp : OffsetDateTime :: now_utc ( ) . unix_timestamp ( ) + 10000 ,
64
65
} ;
65
- let mut extra = HashMap :: with_capacity ( 1 ) ;
66
- extra . insert ( "custom" . to_string ( ) , "header" . to_string ( ) ) ;
67
- let header = Header { kid : Some ( "kid" . to_string ( ) ) , extras : Some ( extra ) , ..Default :: default ( ) } ;
66
+ let mut extras = HashMap :: with_capacity ( 1 ) ;
67
+ extras . insert ( "custom" . to_string ( ) , "header" . to_string ( ) ) ;
68
+ let header = Header { kid : Some ( "kid" . to_string ( ) ) , extras, ..Default :: default ( ) } ;
68
69
let token = encode ( & header, & my_claims, & EncodingKey :: from_secret ( b"secret" ) ) . unwrap ( ) ;
69
70
let token_data = decode :: < Claims > (
70
71
& token,
@@ -74,7 +75,7 @@ fn encode_with_extra_custom_header() {
74
75
. unwrap ( ) ;
75
76
assert_eq ! ( my_claims, token_data. claims) ;
76
77
assert_eq ! ( "kid" , token_data. header. kid. unwrap( ) ) ;
77
- assert_eq ! ( "header" , token_data. header. extras. unwrap ( ) . get( "custom" ) . unwrap( ) . as_str( ) ) ;
78
+ assert_eq ! ( "header" , token_data. header. extras. get( "custom" ) . unwrap( ) . as_str( ) ) ;
78
79
}
79
80
80
81
#[ test]
@@ -85,10 +86,10 @@ fn encode_with_multiple_extra_custom_headers() {
85
86
company : "ACME" . to_string ( ) ,
86
87
exp : OffsetDateTime :: now_utc ( ) . unix_timestamp ( ) + 10000 ,
87
88
} ;
88
- let mut extra = HashMap :: with_capacity ( 1 ) ;
89
- extra . insert ( "custom1" . to_string ( ) , "header1" . to_string ( ) ) ;
90
- extra . insert ( "custom2" . to_string ( ) , "header2" . to_string ( ) ) ;
91
- let header = Header { kid : Some ( "kid" . to_string ( ) ) , extras : Some ( extra ) , ..Default :: default ( ) } ;
89
+ let mut extras = HashMap :: with_capacity ( 2 ) ;
90
+ extras . insert ( "custom1" . to_string ( ) , "header1" . to_string ( ) ) ;
91
+ extras . insert ( "custom2" . to_string ( ) , "header2" . to_string ( ) ) ;
92
+ let header = Header { kid : Some ( "kid" . to_string ( ) ) , extras, ..Default :: default ( ) } ;
92
93
let token = encode ( & header, & my_claims, & EncodingKey :: from_secret ( b"secret" ) ) . unwrap ( ) ;
93
94
let token_data = decode :: < Claims > (
94
95
& token,
@@ -98,7 +99,7 @@ fn encode_with_multiple_extra_custom_headers() {
98
99
. unwrap ( ) ;
99
100
assert_eq ! ( my_claims, token_data. claims) ;
100
101
assert_eq ! ( "kid" , token_data. header. kid. unwrap( ) ) ;
101
- let extras = token_data. header . extras . unwrap ( ) ;
102
+ let extras = token_data. header . extras ;
102
103
assert_eq ! ( "header1" , extras. get( "custom1" ) . unwrap( ) . as_str( ) ) ;
103
104
assert_eq ! ( "header2" , extras. get( "custom2" ) . unwrap( ) . as_str( ) ) ;
104
105
}
@@ -151,7 +152,7 @@ fn decode_token_missing_parts() {
151
152
152
153
#[ test]
153
154
#[ wasm_bindgen_test]
154
- #[ should_panic( expected = "missing field `exp` " ) ]
155
+ #[ should_panic( expected = "InvalidSignature " ) ]
155
156
fn decode_token_invalid_signature ( ) {
156
157
let token =
157
158
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJiQGIuY29tIiwiY29tcGFueSI6IkFDTUUifQ.wrong" ;
0 commit comments