diff --git a/src/Controller/WebhookController.php b/src/Controller/WebhookController.php index f1537527..82cb21bc 100644 --- a/src/Controller/WebhookController.php +++ b/src/Controller/WebhookController.php @@ -100,6 +100,12 @@ public function postAction(Request $request): Response throw new RuntimeException('Request is too old (> 5min)'); } + if ($body === '') { + $this->logger->debug('The request body is empty, probably this request is a test from Event Subscription page on Akeneo.'); + + return new Response(); + } + /** * @TODO Could this be improved by using serializer? Is it necessary or overwork? * diff --git a/tests/Integration/Controller/WebhookControllerTest.php b/tests/Integration/Controller/WebhookControllerTest.php index 627fe02f..3ec56a5d 100644 --- a/tests/Integration/Controller/WebhookControllerTest.php +++ b/tests/Integration/Controller/WebhookControllerTest.php @@ -86,4 +86,19 @@ public function it_fails_if_secret_is_not_right(): void $itemImportResults = $this->itemImportResultRepository->findAll(); self::assertCount(0, $itemImportResults); } + + /** @test */ + public function it_accepts_test_webhook_from_akeneo(): void + { + $request = new Request([], [], [], [], [], [], null); + + $timestamp = (string) time(); + $signature = hash_hmac('sha256', $timestamp . '.', ''); + + $request->headers->set('x-akeneo-request-timestamp', $timestamp); + $request->headers->set('x-akeneo-request-signature', $signature); + $response = $this->webhookController->postAction($request); + + self::assertEquals(200, $response->getStatusCode()); + } }