Skip to content

Commit 72fe817

Browse files
committed
add tests for missing issuers and keys
1 parent 4f3aaf6 commit 72fe817

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

tests/test_04_key_jar.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import pytest
77

8-
from cryptojwt.exception import JWKESTException
8+
from cryptojwt.exception import JWKESTException, IssuerNotFound
99
from cryptojwt.jwe.jwenc import JWEnc
1010
from cryptojwt.jws.jws import JWS
1111
from cryptojwt.jws.jws import factory
@@ -799,8 +799,8 @@ def test_get_decrypt_keys():
799799
keys = kj.get_jwt_decrypt_keys(jwt)
800800
assert keys
801801

802-
keys = kj.get_jwt_decrypt_keys(jwt, aud='Bob')
803-
assert keys
802+
with pytest.raises(IssuerNotFound):
803+
keys = kj.get_jwt_decrypt_keys(jwt, aud='Bob')
804804

805805

806806
def test_update_keyjar():

tests/test_09_jwt.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import os
22

3+
import pytest
4+
5+
from cryptojwt.exception import JWKESTException, IssuerNotFound
6+
from cryptojwt.jws.exception import NoSuitableSigningKeys
37
from cryptojwt.jwt import JWT
48
from cryptojwt.jwt import pick_key
59
from cryptojwt.key_bundle import KeyBundle
@@ -64,6 +68,29 @@ def test_jwt_pack_and_unpack():
6468
assert set(info.keys()) == {'iat', 'iss', 'sub'}
6569

6670

71+
def test_jwt_pack_and_unpack_unknown_issuer():
72+
alice = JWT(key_jar=ALICE_KEY_JAR, iss=ALICE, sign_alg='RS256')
73+
payload = {'sub': 'sub'}
74+
_jwt = alice.pack(payload=payload)
75+
76+
kj = KeyJar()
77+
bob = JWT(key_jar=kj, iss=BOB, allowed_sign_algs=["RS256"])
78+
with pytest.raises(IssuerNotFound):
79+
info = bob.unpack(_jwt)
80+
81+
82+
def test_jwt_pack_and_unpack_unknown_key():
83+
alice = JWT(key_jar=ALICE_KEY_JAR, iss=ALICE, sign_alg='RS256')
84+
payload = {'sub': 'sub'}
85+
_jwt = alice.pack(payload=payload)
86+
87+
kj = KeyJar()
88+
kj.add_kb(ALICE, KeyBundle())
89+
bob = JWT(key_jar=kj, iss=BOB, allowed_sign_algs=["RS256"])
90+
with pytest.raises(NoSuitableSigningKeys):
91+
info = bob.unpack(_jwt)
92+
93+
6794
def test_jwt_pack_and_unpack_with_lifetime():
6895
alice = JWT(key_jar=ALICE_KEY_JAR, iss=ALICE, lifetime=600)
6996
payload = {'sub': 'sub'}

0 commit comments

Comments
 (0)