Skip to content

Commit 8aa8e71

Browse files
ndokosnpalaska
andauthored
Unit test on jwt exception type instead of string (b0.72 backport of #3417) (#3424)
* Check jwt exception type instead of string in the unit tests Jwt exception (specifically jwt.exception.InvalidAudienceError) has changed its string message from `Invalid Audience` to `Audience doesn't match`. In the unit test instead of checking the string message check the type of the exception. Co-authored-by: Nikhil Palaskar <[email protected]>
1 parent 89e45fb commit 8aa8e71

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

lib/pbench/test/unit/server/auth/test_auth.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -532,9 +532,7 @@ def test_token_introspect_offline_exp(self, monkeypatch, rsa_keys):
532532

533533
with pytest.raises(OpenIDTokenInvalid) as exc:
534534
oidc_client.token_introspect_offline(token)
535-
assert (
536-
str(exc.value.__cause__) == "Signature has expired"
537-
), f"{exc.value.__cause__}"
535+
assert isinstance(exc.value.__cause__, jwt.exceptions.ExpiredSignatureError)
538536

539537
def test_token_introspect_offline_aud(self, monkeypatch, rsa_keys):
540538
"""Verify .token_introspect_offline() failure via audience error"""
@@ -548,7 +546,7 @@ def test_token_introspect_offline_aud(self, monkeypatch, rsa_keys):
548546

549547
with pytest.raises(OpenIDTokenInvalid) as exc:
550548
oidc_client.token_introspect_offline(token)
551-
assert str(exc.value.__cause__) == "Invalid audience", f"{exc.value.__cause__}"
549+
assert isinstance(exc.value.__cause__, jwt.exceptions.InvalidAudienceError)
552550

553551
def test_token_introspect_offline_sig(self, monkeypatch, rsa_keys):
554552
"""Verify .token_introspect_offline() failure via signature error"""
@@ -565,9 +563,7 @@ def test_token_introspect_offline_sig(self, monkeypatch, rsa_keys):
565563
with pytest.raises(OpenIDTokenInvalid) as exc:
566564
# Make the signature invalid.
567565
oidc_client.token_introspect_offline(token + "1")
568-
assert (
569-
str(exc.value.__cause__) == "Signature verification failed"
570-
), f"{exc.value.__cause__}"
566+
assert isinstance(exc.value.__cause__, jwt.exceptions.InvalidSignatureError)
571567

572568
def test_get_userinfo(self, monkeypatch):
573569
"""Verify .get_userinfo() properly invokes Connection.get()"""

0 commit comments

Comments
 (0)