forked from symfony/symfony
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add webhooks signature verification on Sweego bridges
- Loading branch information
1 parent
9b0ca99
commit 88769e8
Showing
11 changed files
with
188 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
src/Symfony/Component/Mailer/Bridge/Sweego/Tests/Webhook/Fixtures/sent.json
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
src/Symfony/Component/Mailer/Bridge/Sweego/Tests/Webhook/Fixtures/sent.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...ny/Component/Mailer/Bridge/Sweego/Tests/Webhook/SweegoWrongSignatureRequestParserTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Mailer\Bridge\Sweego\Tests\Webhook; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\Mailer\Bridge\Sweego\RemoteEvent\SweegoPayloadConverter; | ||
use Symfony\Component\Mailer\Bridge\Sweego\Webhook\SweegoRequestParser; | ||
use Symfony\Component\Webhook\Client\RequestParserInterface; | ||
use Symfony\Component\Webhook\Exception\RejectWebhookException; | ||
use Symfony\Component\Webhook\Test\AbstractRequestParserTestCase; | ||
|
||
class SweegoWrongSignatureRequestParserTest extends AbstractRequestParserTestCase | ||
{ | ||
protected function createRequestParser(): RequestParserInterface | ||
{ | ||
$this->expectException(RejectWebhookException::class); | ||
$this->expectExceptionMessage('Invalid signature.'); | ||
|
||
return new SweegoRequestParser(new SweegoPayloadConverter()); | ||
} | ||
|
||
protected function createRequest(string $payload): Request | ||
{ | ||
return Request::create('/', 'POST', [], [], [], [ | ||
'Content-Type' => 'application/json', | ||
'HTTP_webhook-id' => '9f26b9d0-13d7-410c-ba04-5019cd30e6d0', | ||
'HTTP_webhook-timestamp' => '1723737959', | ||
'HTTP_webhook-signature' => 'wrong_signature', | ||
], $payload); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
.../Component/Notifier/Bridge/Sweego/Tests/Webhook/SweegoWrongSignatureRequestParserTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Notifier\Bridge\Sweego\Tests\Webhook; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\Notifier\Bridge\Sweego\Webhook\SweegoRequestParser; | ||
use Symfony\Component\Webhook\Client\RequestParserInterface; | ||
use Symfony\Component\Webhook\Exception\RejectWebhookException; | ||
use Symfony\Component\Webhook\Test\AbstractRequestParserTestCase; | ||
|
||
class SweegoWrongSignatureRequestParserTest extends AbstractRequestParserTestCase | ||
{ | ||
protected function createRequestParser(): RequestParserInterface | ||
{ | ||
$this->expectException(RejectWebhookException::class); | ||
$this->expectExceptionMessage('Invalid signature.'); | ||
|
||
return new SweegoRequestParser(); | ||
} | ||
|
||
protected function createRequest(string $payload): Request | ||
{ | ||
return Request::create('/', 'POST', [], [], [], [ | ||
'Content-Type' => 'application/json', | ||
'HTTP_webhook-id' => 'a5ccc627-6e43-4012-bb29-f1bfe3a3d13e', | ||
'HTTP_webhook-timestamp' => '1725290740', | ||
'HTTP_webhook-signature' => 'wrong_signature', | ||
], $payload); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters