Skip to content

Commit

Permalink
Merge pull request #19 from amiranagram/fix-gh-header
Browse files Browse the repository at this point in the history
[Fix] GitHub signature header
  • Loading branch information
hotmeteor authored Feb 21, 2023
2 parents 53d7cb4 + 209f2ab commit 864708c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Providers/GithubProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class GithubProvider extends AbstractProvider
*/
public function verify(Request $request): bool
{
$header = $request->header('HTTP_X_HUB_SIGNATURE_256');
$header = $request->header('X-Hub-Signature-256');
$signature = hash_hmac('sha256', $request->getContent(), $this->secret);

return hash_equals($header, $signature);
return hash_equals(substr($header, 7), $signature);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/GithubProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function test_it_can_receive_github_webhook()
{
Log::partialMock()->shouldReceive('info')->never();

$signature = '5a84f1914825f5625cb82b1a894d7c6a8a851b7908f0134149b251b3b03880ed';
$signature = 'sha256=5a84f1914825f5625cb82b1a894d7c6a8a851b7908f0134149b251b3b03880ed';

$request = Mockery::mock(Request::class);
$this->signUsing($request, $signature);
Expand All @@ -35,7 +35,7 @@ public function test_it_dispatches_matching_handler()
{
Log::partialMock()->shouldReceive('info')->withArgs(['Webhook handled.'])->andReturnNull();

$signature = '5a84f1914825f5625cb82b1a894d7c6a8a851b7908f0134149b251b3b03880ed';
$signature = 'sha256=5a84f1914825f5625cb82b1a894d7c6a8a851b7908f0134149b251b3b03880ed';

$request = Mockery::mock(Request::class);
$this->signUsing($request, $signature);
Expand Down Expand Up @@ -63,7 +63,7 @@ public function test_it_dispatches_matching_handler()
protected function signUsing(Request $request, string $signature): Request
{
$request->allows('getContent')->andReturns(json_encode($this->mockPayload()));
$request->allows('header')->with('HTTP_X_HUB_SIGNATURE_256')->andReturns($signature);
$request->allows('header')->with('X-Hub-Signature-256')->andReturns($signature);

return $request;
}
Expand Down

0 comments on commit 864708c

Please sign in to comment.