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 #3417

Merged
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
14 changes: 4 additions & 10 deletions lib/pbench/test/unit/server/auth/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,7 @@ def test_token_introspect_exp(self, monkeypatch, rsa_keys):

with pytest.raises(OpenIDTokenInvalid) as exc:
oidc_client.token_introspect(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_aud(self, monkeypatch, rsa_keys):
"""Verify .token_introspect() failure via audience error"""
Expand All @@ -394,7 +392,7 @@ def test_token_introspect_aud(self, monkeypatch, rsa_keys):

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

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

def test_token_introspect_alg(self, monkeypatch, rsa_keys):
"""Verify .token_introspect() failure via algorithm error"""
Expand All @@ -430,9 +426,7 @@ def test_token_introspect_alg(self, monkeypatch, rsa_keys):

with pytest.raises(OpenIDTokenInvalid) as exc:
oidc_client.token_introspect(generated_api_key)
assert (
str(exc.value.__cause__) == "The specified alg value is not allowed"
), f"{exc.value.__cause__}"
assert isinstance(exc.value.__cause__, jwt.exceptions.InvalidAlgorithmError)


@dataclass
Expand Down