Skip to content

Commit 2ebdb3f

Browse files
committed
Add round trip tests for keys that are bytes and strings
1 parent 99ec142 commit 2ebdb3f

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

tests/test_jws.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ def test_invalid_key(self, payload):
7777
with pytest.raises(JWSError):
7878
jws.sign(payload, 'secret', algorithm='RS256')
7979

80+
@pytest.mark.parametrize("key", [
81+
b'key',
82+
'key',
83+
])
84+
def test_round_trip_with_different_key_types(self, key):
85+
signed_data = jws.sign({'testkey': 'testvalue'}, key, algorithm=ALGORITHMS.HS256)
86+
verified_bytes = jws.verify(signed_data, key, algorithms=[ALGORITHMS.HS256])
87+
verified_data = json.loads(verified_bytes.decode('utf-8'))
88+
assert 'testkey' in verified_data.keys()
89+
assert verified_data['testkey'] == 'testvalue'
90+
8091

8192
class TestHMAC(object):
8293

tests/test_jwt.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,16 @@ def test_decode(self, claims, key):
165165

166166
assert decoded == claims
167167

168+
@pytest.mark.parametrize('key', [
169+
b'key',
170+
'key',
171+
])
172+
def test_round_trip_with_different_key_types(self, key):
173+
token = jwt.encode({'testkey': 'testvalue'}, key, algorithm='HS256')
174+
verified_data = jwt.decode(token, key, algorithms=['HS256'])
175+
assert 'testkey' in verified_data.keys()
176+
assert verified_data['testkey'] == 'testvalue'
177+
168178
def test_leeway_is_int(self):
169179
pass
170180

0 commit comments

Comments
 (0)