Skip to content
Closed
Show file tree
Hide file tree
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
Empty file added dummy.txt
Empty file.
18 changes: 15 additions & 3 deletions livekit-api/tests/test_webhook.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import base64
import hashlib

import pytest # type: ignore
from livekit.api import AccessToken, TokenVerifier, WebhookReceiver

Expand Down Expand Up @@ -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)


Expand All @@ -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)
Loading