IpsRequestMatcher example

private readonly BrevoPayloadConverter $converter,
    ) {
    }

    protected function getRequestMatcher(): RequestMatcherInterface
    {
        return new ChainRequestMatcher([
            new MethodRequestMatcher('POST'),
            new IsJsonRequestMatcher(),
            // https://developers.brevo.com/docs/how-to-use-webhooks#securing-your-webhooks             // localhost is added for testing             new IpsRequestMatcher(['185.107.232.1/24', '1.179.112.1/20', '127.0.0.1']),
        ]);
    }

    protected function doParse(Request $request, string $secret): ?AbstractMailerEvent
    {
        $content = $request->toArray();
        if (
            !isset($content['event'])
            || !isset($content['email'])
            || !isset($content['message-id'])
            || !isset($content['ts_event'])
            
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestMatcher\IpsRequestMatcher;

class IpsRequestMatcherTest extends TestCase
{
    /** * @dataProvider getData */
    public function test($ips, bool $expected)
    {
        $matcher = new IpsRequestMatcher($ips);
        $request = Request::create('', 'GET', [][][]['REMOTE_ADDR' => '127.0.0.1']);
        $this->assertSame($expected$matcher->matches($request));
    }

    public static function getData()
    {
        return [
            [[], true],
            ['127.0.0.1', true],
            ['192.168.0.1', false],
            ['127.0.0.1', true],
            [
public function __construct(
        private readonly PostmarkPayloadConverter $converter,
    ) {
    }

    protected function getRequestMatcher(): RequestMatcherInterface
    {
        return new ChainRequestMatcher([
            new MethodRequestMatcher('POST'),
            // https://postmarkapp.com/support/article/800-ips-for-firewalls#webhooks             // localhost is added for testing             new IpsRequestMatcher(['3.134.147.250', '50.31.156.6', '50.31.156.77', '18.217.206.57', '127.0.0.1']),
            new IsJsonRequestMatcher(),
        ]);
    }

    protected function doParse(Request $request, string $secret): ?AbstractMailerEvent
    {
        $payload = $request->toArray();
        if (
            !isset($payload['RecordType'])
            || !isset($payload['MessageID'])
            || !(isset($payload['Recipient']) || isset($payload['Email']))
            
Home | Imprint | This part of the site doesn't use cookies.