Merge pull request #90 from z38/fix-webhook-notices

Fix notices on empty webhook requests
This commit is contained in:
Sergey Obukhov 2016-07-20 12:34:11 -07:00 committed by GitHub
commit 341e06a196
2 changed files with 9 additions and 0 deletions

View File

@ -91,6 +91,9 @@ class Mailgun{
if($postData === null) { if($postData === null) {
$postData = $_POST; $postData = $_POST;
} }
if(!isset($postData['timestamp']) || !isset($postData['token']) || !isset($postData['signature'])) {
return false;
}
$hmac = hash_hmac('sha256', "{$postData["timestamp"]}{$postData["token"]}", $this->apiKey); $hmac = hash_hmac('sha256', "{$postData["timestamp"]}{$postData["token"]}", $this->apiKey);
$sig = $postData['signature']; $sig = $postData['signature'];
if(function_exists('hash_equals')) { if(function_exists('hash_equals')) {

View File

@ -33,4 +33,10 @@ class MailgunTest extends \Mailgun\Tests\MailgunTestCase
); );
assert(!$client->verifyWebhookSignature($postData)); assert(!$client->verifyWebhookSignature($postData));
} }
public function testVerifyWebhookEmptyRequest() {
$client = new Mailgun('key-3ax6xnjp29jd6fds4gc373sgvjxteol0');
$postData = array();
assert(!$client->verifyWebhookSignature($postData));
}
} }