Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test on jwt exception type instead of string (b0.72 backport of #3417) #3424

Merged
merged 1 commit into from
May 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions lib/pbench/test/unit/server/auth/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,7 @@ def test_token_introspect_offline_exp(self, monkeypatch, rsa_keys):

with pytest.raises(OpenIDTokenInvalid) as exc:
oidc_client.token_introspect_offline(token)
assert (
str(exc.value.__cause__) == "Signature has expired"
), f"{exc.value.__cause__}"
assert isinstance(exc.value.__cause__, jwt.exceptions.ExpiredSignatureError)

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

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

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

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