public function it_will_return_false_on_check_fail(AbstractEvent $event, WebHookSignature $signature) { $event->getSignature()->willReturn($signature); $signature->getAlgorithm()->willReturn('sha1'); $signature->getSignature()->willReturn('abc123'); $event->getRawPayload()->willReturn('{}'); $this->check($event)->shouldReturn(false); }
/** * @param AbstractEvent $event * * @return bool */ public function check(AbstractEvent $event) { $payLoadHash = hash_hmac($event->getSignature()->getAlgorithm(), $event->getRawPayload(), $this->secret); if ($payLoadHash === $event->getSignature()->getSignature()) { return true; } else { return false; } }
/** * @param AbstractEvent $event * * @throws Exception * * @return PushPayload */ public function create(AbstractEvent $event) { if ($event instanceof PushEvent) { return new PushPayload($event->getPayload()); } elseif ($event instanceof StatusEvent) { return new StatusPayload($event->getPayload()); } elseif ($event instanceof PullRequestEvent) { return new PullRequestPayload($event->getPayload()); } throw new Exception('Unknown WebHook Event:' . get_class($event)); }