-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #54525 [Mailer] [Resend] Add Resend webhook signature verific…
…ation (welcoMattic) This PR was squashed before being merged into the 7.1 branch. Discussion ---------- [Mailer] [Resend] Add Resend webhook signature verification | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | no | New feature? | yes | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Issues | Fix #53554 <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead --> | License | MIT Follow up of #53554. At this time I missed webhook signature verification. To complete the Bridge before 7.1 release, here it is! I plan to add more webhook payloads in test, I asked Resend to send me example, because some are tough to reproduce. Commits ------- 8daa804 [Mailer] [Resend] Add Resend webhook signature verification
- Loading branch information
Showing
6 changed files
with
156 additions
and
4 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": "test@resend.com", | ||
"headers": [ | ||
{ | ||
"name": "Sender", | ||
"value": "test@resend.com" | ||
} | ||
], | ||
"subject": "Test subject", | ||
"to": [ | ||
"test@example.com" | ||
] | ||
}, | ||
"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('test@example.com'); | ||
$wh->setTags([]); | ||
$wh->setMetadata([ | ||
'created_at' => '2024-04-08T09:43:09.438Z', | ||
'email_id' => '172c41ce-ba6d-4281-8a7a-541faa725748', | ||
'from' => 'test@resend.com', | ||
'headers' => [ | ||
[ | ||
'name' => 'Sender', | ||
'value' => 'test@resend.com' | ||
], | ||
], | ||
'subject' => 'Test subject', | ||
'to' => [ | ||
'test@example.com', | ||
], | ||
]); | ||
$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 <fabien@symfony.com> | ||
* | ||
* 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