Skip to content

Commit

Permalink
Extend some test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
marc1706 committed Nov 30, 2023
1 parent 55dbd4d commit 7421628
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/GithubLabelsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function dataHandleEmpty(): array
['!unset Event', [], ['Event']],
['!unset GSOC 🎓', [], ['GSOC 🎓']],
['!unset GSOC', [], ['GSOC 🎓']],
['!unset LOL', [], []], // Label does not exist
];
}

Expand Down
79 changes: 79 additions & 0 deletions tests/KernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,83 @@ public function testHandle()

$this->kernel->handle($body, $server);
}

public function testMissingEventHeader()
{
$payload = [];
$body = json_encode($payload);
$server = [
'HTTP_X_HUB_SIGNATURE' => 'sha1='.hash_hmac('sha1', $body, $this->hmacKey),
];
$listenerStub = $this->createMock('Phpbb\DevHooks\Listener\Listener');
$listenerStub
->expects($this->never())
->method('handle')
;

$this->container['listener.test_event.test'] = $listenerStub;

$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('Missing X-Github-Event header.');
$this->kernel->handle($body, $server);
}

public function testMissingSignature()
{
$body = '';
$server = [
'HTTP_X_GITHUB_EVENT' => 'test_event',
];
$listenerStub = $this->createMock('Phpbb\DevHooks\Listener\Listener');
$listenerStub
->expects($this->never())
->method('handle')
;

$this->container['listener.test_event.test'] = $listenerStub;

$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('Missing X-Hub-Signature header');
$this->kernel->handle($body, $server);
}

public function testInvalidSignature()
{
$body = '';
$server = [
'HTTP_X_HUB_SIGNATURE' => 'sha1=invalid',
'HTTP_X_GITHUB_EVENT' => 'test_event',
];
$listenerStub = $this->createMock('Phpbb\DevHooks\Listener\Listener');
$listenerStub
->expects($this->never())
->method('handle')
;

$this->container['listener.test_event.test'] = $listenerStub;

$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('Incorrect X-Hub-Signature header');
$this->kernel->handle($body, $server);
}

public function testEmptyPayload()
{
$body = '';
$server = [
'HTTP_X_HUB_SIGNATURE' => 'sha1='.hash_hmac('sha1', $body, $this->hmacKey),
'HTTP_X_GITHUB_EVENT' => 'test_event',
];
$listenerStub = $this->createMock('Phpbb\DevHooks\Listener\Listener');
$listenerStub
->expects($this->never())
->method('handle')
;

$this->container['listener.test_event.test'] = $listenerStub;

$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('Expected payload to be array.');
$this->kernel->handle($body, $server);
}
}

0 comments on commit 7421628

Please sign in to comment.