Skip to content

Commit af31311

Browse files
author
Peter Grant
committed
Add test with non-default headers
1 parent 78609d7 commit af31311

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/test_jwt.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ def claims():
2020
def key():
2121
return 'secret'
2222

23+
@pytest.fixture
24+
def headers():
25+
headers = {
26+
'kid': 'my-key-id',
27+
}
28+
return headers
2329

2430
class TestJWT:
2531

@@ -28,6 +34,19 @@ def test_non_default_alg(self, claims, key):
2834
decoded = jwt.decode(encoded, key, algorithms='HS384')
2935
assert claims == decoded
3036

37+
def test_non_default_alg_positional_bwcompat(self, claims, key):
38+
encoded = jwt.encode(claims, key, 'HS384')
39+
decoded = jwt.decode(encoded, key, 'HS384')
40+
assert claims == decoded
41+
42+
def test_non_default_headers(self, claims, key, headers):
43+
encoded = jwt.encode(claims, key, headers=headers)
44+
decoded = jwt.decode(encoded, key)
45+
assert claims == decoded
46+
all_headers = jwt.get_unverified_headers(encoded)
47+
custom_headers = {k: all_headers[k] for k in headers.keys()}
48+
assert custom_headers == headers
49+
3150
def test_encode(self, claims, key):
3251

3352
expected = (

0 commit comments

Comments
 (0)