45 lines
1.2 KiB
PHP
45 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Controller\Webhook;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|
|
|
class MailjetNewsletterWebhookSecurityTest extends WebTestCase
|
|
{
|
|
public function testWebhookRequiresBasicAuthentication(): void
|
|
{
|
|
$client = self::createClient([], [
|
|
'HTTPS' => 'on',
|
|
]);
|
|
|
|
$client->request(
|
|
'POST',
|
|
'/webhooks/mailjet/newsletter',
|
|
server: ['CONTENT_TYPE' => 'application/json'],
|
|
content: json_encode(['event' => 'open'], JSON_THROW_ON_ERROR),
|
|
);
|
|
|
|
self::assertResponseStatusCodeSame(401);
|
|
}
|
|
|
|
public function testWebhookAcceptsValidBasicAuthentication(): void
|
|
{
|
|
$client = self::createClient([], [
|
|
'HTTPS' => 'on',
|
|
'PHP_AUTH_USER' => 'mailjet',
|
|
'PHP_AUTH_PW' => 'secret',
|
|
]);
|
|
|
|
$client->request(
|
|
'POST',
|
|
'/webhooks/mailjet/newsletter',
|
|
server: ['CONTENT_TYPE' => 'application/json'],
|
|
content: json_encode(['event' => 'open'], JSON_THROW_ON_ERROR),
|
|
);
|
|
|
|
self::assertResponseIsSuccessful();
|
|
}
|
|
}
|