@@ -15,21 +15,34 @@ def use_embedded_jwk(obj: GuestProtocol) -> Key:
1515
1616
1717class TestJWT (TestCase ):
18+ oct_key = OctKey .generate_key ()
19+
20+ def test_default_type (self ):
21+ data = jwt .encode ({"alg" : "HS256" }, {"sub" : "a" }, self .oct_key )
22+ token = jwt .decode (data , self .oct_key )
23+ self .assertEqual (token .header ["typ" ], "JWT" )
24+
25+ data = jwt .encode ({"alg" : "HS256" }, {"sub" : "a" }, self .oct_key , default_type = None )
26+ token = jwt .decode (data , self .oct_key )
27+ self .assertNotIn ("typ" , token .header )
28+
29+ data = jwt .encode ({"alg" : "HS256" }, {"sub" : "a" }, self .oct_key , default_type = "jwt+at" )
30+ token = jwt .decode (data , self .oct_key )
31+ self .assertEqual (token .header ["typ" ], "jwt+at" )
32+
1833 def test_invalid_payload (self ):
19- key = OctKey .import_key ("secret" )
20- data = jws .serialize_compact ({"alg" : "HS256" }, b"hello" , key )
21- self .assertRaises (InvalidPayloadError , jwt .decode , data , key )
34+ data = jws .serialize_compact ({"alg" : "HS256" }, b"hello" , self .oct_key )
35+ self .assertRaises (InvalidPayloadError , jwt .decode , data , self .oct_key )
2236
2337 def test_claims_registry (self ):
24- key = OctKey .import_key ("secret" )
25- data = jwt .encode ({"alg" : "HS256" }, {"sub" : "a" }, key )
26- token = jwt .decode (data , key )
38+ data = jwt .encode ({"alg" : "HS256" }, {"sub" : "a" }, self .oct_key )
39+ token = jwt .decode (data , self .oct_key )
2740
2841 claims_registry = jwt .JWTClaimsRegistry (iss = {"essential" : True })
2942 self .assertRaises (MissingClaimError , claims_registry .validate , token .claims )
3043
31- data = jwt .encode ({"alg" : "HS256" }, {"iss" : "a" }, key )
32- obj = jwt .decode (data , key )
44+ data = jwt .encode ({"alg" : "HS256" }, {"iss" : "a" }, self . oct_key )
45+ obj = jwt .decode (data , self . oct_key )
3346 self .assertEqual (obj .claims ["iss" ], "a" )
3447
3548 def test_jwe_format (self ):
0 commit comments