/** * @param mixed[] $headers * @param string $body */ public function handle(array $headers, $body) { if (!$this->firewall->authorize($headers, $body)) { throw new BadRequestHttpException('The request signature is not valid.'); } if (!is_array($payload = json_decode($body, true))) { throw new BadRequestHttpException('The request json body cannot be decoded.'); } $this->eventDispatcher->dispatch(WebhookEvents::HOOK, $event = new WebhookEvent($payload)); foreach ($event->getProcesses() as $process) { $this->processProducer->publish($process); } }
/** * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException * @expectedExceptionMessage The request json body cannot be decoded. */ public function testHandleWithInvalidJson() { $this->firewall->expects($this->once())->method('authorize')->with($this->identicalTo($headers = ['X-Hub-Signature' => 'sha1=aff354dfbc9e335aaec1e28f2305f34db176db1b']), $this->identicalTo($body = '{"foo":"bar"'))->will($this->returnValue(true)); $this->handler->handle($headers, $body); }
public function testAuthorizeWithUnsupportedAlgorithm() { $this->assertFalse($this->firewall->authorize(['X-Hub-Signature' => ['unsupported=52b582138706ac0c597c315cfc1a1bf177408a4d']], '{"foo":"bar"}')); }