diff --git a/dummy.txt b/dummy.txt new file mode 100644 index 00000000..e69de29b diff --git a/livekit-api/tests/test_webhook.py b/livekit-api/tests/test_webhook.py index fc8828e5..98f424cb 100644 --- a/livekit-api/tests/test_webhook.py +++ b/livekit-api/tests/test_webhook.py @@ -1,6 +1,5 @@ import base64 import hashlib - import pytest # type: ignore from livekit.api import AccessToken, TokenVerifier, WebhookReceiver @@ -64,7 +63,7 @@ def test_bad_hash(): hash64 = base64.b64encode(hashlib.sha256("wrong_hash".encode()).digest()).decode() token.claims.sha256 = hash64 jwt = token.to_jwt() - with pytest.raises(Exception): + with pytest.raises(Exception): # Using a broad Exception for existing test receiver.receive(TEST_EVENT, jwt) @@ -77,5 +76,18 @@ def test_invalid_body(): hash64 = base64.b64encode(hashlib.sha256(body.encode()).digest()).decode() token.claims.sha256 = hash64 jwt = token.to_jwt() - with pytest.raises(Exception): + with pytest.raises(Exception): # Using a broad Exception for existing test receiver.receive(body, jwt) + + +def test_malformed_jwt(): + """ + Test that receiving a webhook with a malformed JWT string raises an error. + """ + token_verifier = TokenVerifier(TEST_API_KEY, TEST_API_SECRET) + receiver = WebhookReceiver(token_verifier) + + malformed_jwt = "this.is.not.a.valid.jwt" # A clearly malformed string + + with pytest.raises(Exception): + receiver.receive(TEST_EVENT, malformed_jwt)