Skip to content

Commit 1658d0b

Browse files
authored
feat(verify_webhook): bytes as signature header (#119)
1 parent fbab38e commit 1658d0b

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

stream_chat/base/client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,19 @@ def create_search_params(
8989

9090
return params
9191

92-
def verify_webhook(self, request_body: bytes, x_signature: str) -> bool:
92+
def verify_webhook(
93+
self, request_body: bytes, x_signature: Union[str, bytes]
94+
) -> bool:
9395
"""
9496
Verify the signature added to a webhook event
9597
9698
:param request_body: the request body received from webhook
9799
:param x_signature: the x-signature header included in the request
98100
:return: bool
99101
"""
102+
if isinstance(x_signature, bytes):
103+
x_signature = x_signature.decode()
104+
100105
signature = hmac.new(
101106
key=self.api_secret.encode(), msg=request_body, digestmod=hashlib.sha256
102107
).hexdigest()

stream_chat/tests/async_chat/test_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ async def test_delete_users(self, client: StreamChatAsync, random_user: Dict):
153153
)
154154
assert "task_id" in response
155155

156-
for _ in range(10):
156+
for _ in range(20):
157157
response = await client.get_task(response["task_id"])
158158
if response["status"] == "completed" and response["result"][
159159
random_user["id"]
@@ -690,7 +690,7 @@ async def test_delete_channels(self, client: StreamChatAsync, channel: Channel):
690690
response = await client.delete_channels([channel.cid])
691691
assert "task_id" in response
692692

693-
for _ in range(10):
693+
for _ in range(20):
694694
response = await client.get_task(response["task_id"])
695695
if response["status"] == "completed" and response["result"][
696696
channel.cid

stream_chat/tests/test_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def test_delete_users(self, client: StreamChat, random_user: Dict):
143143
)
144144
assert "task_id" in response
145145

146-
for _ in range(10):
146+
for _ in range(20):
147147
response = client.get_task(response["task_id"])
148148
if response["status"] == "completed" and response["result"][
149149
random_user["id"]
@@ -646,7 +646,7 @@ def test_delete_channels(self, client: StreamChat, channel: Channel):
646646
response = client.delete_channels([channel.cid])
647647
assert "task_id" in response
648648

649-
for _ in range(10):
649+
for _ in range(20):
650650
response = client.get_task(response["task_id"])
651651
if response["status"] == "completed" and response["result"][
652652
channel.cid

0 commit comments

Comments
 (0)