WIP: logging_config, import orders, test refactoring (phase 3 context)
This commit is contained in:
+10
-15
@@ -2,12 +2,10 @@
|
||||
|
||||
import hashlib
|
||||
import hmac
|
||||
from unittest.mock import patch
|
||||
|
||||
from flask import Flask
|
||||
|
||||
from src.routes.whatsapp import whatsapp_bp
|
||||
from src.queue.webhook import verify_whatsapp_signature
|
||||
|
||||
|
||||
class TestWhatsAppWebhook:
|
||||
@@ -47,22 +45,19 @@ class TestWhatsAppWebhook:
|
||||
def test_post_mit_korrekter_signatur(self) -> None:
|
||||
"""POST mit korrekter Signatur → 200."""
|
||||
payload = b'{"object":"whatsapp","entry":[]}'
|
||||
secret = "test_geheim"
|
||||
sig = "sha256=" + hmac.new(
|
||||
secret.encode("utf-8"), payload, hashlib.sha256
|
||||
b"test_app_secret_123", payload, hashlib.sha256
|
||||
).hexdigest()
|
||||
|
||||
with patch("src.routes.whatsapp.verify_whatsapp_signature",
|
||||
return_value=True):
|
||||
response = self.client.post(
|
||||
"/webhook/whatsapp",
|
||||
data=payload,
|
||||
headers={"X-Hub-Signature-256": sig},
|
||||
content_type="application/json",
|
||||
)
|
||||
assert response.status_code == 200
|
||||
data = response.get_json()
|
||||
assert data["status"] == "accepted"
|
||||
response = self.client.post(
|
||||
"/webhook/whatsapp",
|
||||
data=payload,
|
||||
headers={"X-Hub-Signature-256": sig},
|
||||
content_type="application/json",
|
||||
)
|
||||
assert response.status_code == 200
|
||||
data = response.get_json()
|
||||
assert data["status"] == "accepted"
|
||||
|
||||
def test_post_mit_falscher_signatur(self) -> None:
|
||||
"""POST mit falscher Signatur → 401."""
|
||||
|
||||
Reference in New Issue
Block a user