Skip to content

Commit f9461ad

Browse files
Copilotsamdark
andcommitted
Add comprehensive tests for GitHubWebhookAction functionality
Co-authored-by: samdark <47294+samdark@users.noreply.github.com>
1 parent 82aee0c commit f9461ad

File tree

2 files changed

+596
-9
lines changed

2 files changed

+596
-9
lines changed

components/GitHubWebhookAction.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,11 @@ public function run()
7373
/**
7474
* Validates the GitHub webhook signature
7575
*
76+
* @param string|null $payload Optional payload for testing
7677
* @throws BadRequestHttpException
7778
* @throws ForbiddenHttpException
7879
*/
79-
protected function validateSignature()
80+
protected function validateSignature($payload = null)
8081
{
8182
$secret = Yii::$app->params['github-webhook-secret'] ?? null;
8283

@@ -91,7 +92,10 @@ protected function validateSignature()
9192
throw new ForbiddenHttpException('Missing signature header');
9293
}
9394

94-
$payload = file_get_contents('php://input');
95+
if ($payload === null) {
96+
$payload = file_get_contents('php://input');
97+
}
98+
9599
$expectedSignature = 'sha256=' . hash_hmac('sha256', $payload, $secret);
96100

97101
if (!hash_equals($expectedSignature, $signature)) {

0 commit comments

Comments
 (0)