async def handle_webhook( request: Request, webhook: GitHubWebhook, X_Hub_Signature_256: Optional[str] = Header(None), ): if not X_Hub_Signature_256: raise HTTPException(status_code=HTTPStatus.BAD_REQUEST, detail="Missing signature header") if not webhooks.verify_webhook(signature=X_Hub_Signature_256, body=await request.body()): raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED, detail="Signature verification failed") webhooks.handle_webhook(webhook)
def test_invalid(self): assert (webhooks.verify_webhook( signature=fixtures.github.SIGNED_HEADER, body=(fixtures.github.SIGNED_BODY + "a").encode(), ) is False)
def test_valid(self): assert (webhooks.verify_webhook( signature=fixtures.github.SIGNED_HEADER, body=fixtures.github.SIGNED_BODY.encode(), ) is True)