Skip to content

Commit

Permalink
Accept test webhook (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
lruozzi9 committed Dec 11, 2023
1 parent 3fcb48a commit f70c732
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Controller/WebhookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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?
*
Expand Down
15 changes: 15 additions & 0 deletions tests/Integration/Controller/WebhookControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit f70c732

Please sign in to comment.