SuperSeller3000/tests/Unit/Infrastructure/Channel/Ebay/EbayWebhookVerifierTest.php

43 lines
1.3 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace App\Tests\Unit\Infrastructure\Channel\Ebay;
use App\Infrastructure\Channel\Ebay\EbayWebhookVerifier;
use PHPUnit\Framework\TestCase;
final class EbayWebhookVerifierTest extends TestCase
{
private EbayWebhookVerifier $verifier;
protected function setUp(): void
{
$this->verifier = new EbayWebhookVerifier(
verificationToken: 'my-secret-token',
endpointUrl: 'https://example.com/webhooks/ebay',
);
}
public function testValidSignaturePasses(): void
{
$body = '{"notification":{"data":{"orderId":"123"}}}';
$expected = base64_encode(hash('sha256', $body.'my-secret-tokenhttps://example.com/webhooks/ebay', binary: true));
$this->assertTrue($this->verifier->verify($body, $expected));
}
public function testInvalidSignatureFails(): void
{
$this->assertFalse($this->verifier->verify('{"body":"x"}', 'invalidsignature'));
}
public function testChallengeResponseReturnsCorrectHash(): void
{
$challengeCode = 'abc123';
$expected = hash('sha256', $challengeCode.'my-secret-tokenhttps://example.com/webhooks/ebay');
$this->assertSame($expected, $this->verifier->challengeResponse($challengeCode));
}
}