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 Resend webhook signature verification
- Loading branch information
1 parent
9549cc2
commit 3881e5e
Showing
6 changed files
with
155 additions
and
3 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
19 changes: 19 additions & 0 deletions
19
src/Symfony/Component/Mailer/Bridge/Resend/Tests/Webhook/Fixtures/sent.json
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,19 @@ | ||
{ | ||
"created_at": "2024-04-08T09:43:09.500Z", | ||
"data": { | ||
"created_at": "2024-04-08T09:43:09.438Z", | ||
"email_id": "172c41ce-ba6d-4281-8a7a-541faa725748", | ||
"from": "[email protected]", | ||
"headers": [ | ||
{ | ||
"name": "Sender", | ||
"value": "[email protected]" | ||
} | ||
], | ||
"subject": "Test subject", | ||
"to": [ | ||
"[email protected]" | ||
] | ||
}, | ||
"type": "email.sent" | ||
} |
26 changes: 26 additions & 0 deletions
26
src/Symfony/Component/Mailer/Bridge/Resend/Tests/Webhook/Fixtures/sent.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,26 @@ | ||
<?php | ||
|
||
use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent; | ||
|
||
$wh = new MailerDeliveryEvent(MailerDeliveryEvent::RECEIVED, '172c41ce-ba6d-4281-8a7a-541faa725748', json_decode(file_get_contents(str_replace('.php', '.json', __FILE__)), true)); | ||
$wh->setRecipientEmail('[email protected]'); | ||
$wh->setTags([]); | ||
$wh->setMetadata([ | ||
'created_at' => '2024-04-08T09:43:09.438Z', | ||
'email_id' => '172c41ce-ba6d-4281-8a7a-541faa725748', | ||
'from' => '[email protected]', | ||
'headers' => [ | ||
[ | ||
'name' => 'Sender', | ||
'value' => '[email protected]' | ||
], | ||
], | ||
'subject' => 'Test subject', | ||
'to' => [ | ||
'[email protected]', | ||
], | ||
]); | ||
$wh->setReason(''); | ||
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.u\Z', '2024-04-08T09:43:09.500000Z')); | ||
|
||
return $wh; |
41 changes: 41 additions & 0 deletions
41
src/Symfony/Component/Mailer/Bridge/Resend/Tests/Webhook/ResendRequestParserTest.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,41 @@ | ||
<?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\Resend\Tests\Webhook; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\Mailer\Bridge\Resend\RemoteEvent\ResendPayloadConverter; | ||
use Symfony\Component\Mailer\Bridge\Resend\Webhook\ResendRequestParser; | ||
use Symfony\Component\Webhook\Client\RequestParserInterface; | ||
use Symfony\Component\Webhook\Test\AbstractRequestParserTestCase; | ||
|
||
class ResendRequestParserTest extends AbstractRequestParserTestCase | ||
{ | ||
protected function createRequestParser(): RequestParserInterface | ||
{ | ||
return new ResendRequestParser(new ResendPayloadConverter()); | ||
} | ||
|
||
protected function getSecret(): string | ||
{ | ||
return 'whsec_ESwTAuuIe3yfH4DgdgI+ENsiNzPAGdp+'; | ||
} | ||
|
||
protected function createRequest(string $payload): Request | ||
{ | ||
return Request::create('/', 'POST', [], [], [], [ | ||
'Content-Type' => 'application/json', | ||
'HTTP_svix-id' => '172c41ce-ba6d-4281-8a7a-541faa725748', | ||
'HTTP_svix-timestamp' => '1712569389', | ||
'HTTP_svix-signature' => 'v1,4wjuRp64yC/2itgCQwl2xPePVwSPTdPbXLIY6IxGLTA=', | ||
], str_replace("\n", "\r\n", $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