58 lines
1.7 KiB
PHP
58 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Application\Security\ValueObjects\Request;
|
|
|
|
use Application\Security\Models\ValueObjects\Request\RequestSignature;
|
|
|
|
covers(RequestSignature::class);
|
|
|
|
describe('RequestSignature Value Object Instantiation', function (): void {
|
|
it('instantiates successfully with a valid 64-character hex signature', function (): void {
|
|
// GIVEN
|
|
$validSignature = hash_hmac('sha256', 'test_payload', 'secret_key');
|
|
|
|
// WHEN
|
|
$signature = new RequestSignature($validSignature);
|
|
|
|
// THEN
|
|
expect($signature->value)->toBe($validSignature);
|
|
});
|
|
});
|
|
|
|
describe('RequestSignature Value Object Validation Rules', function (): void {
|
|
it('throws InvalidArgumentException when given an empty signature', function (string $invalid): void {
|
|
// GIVEN
|
|
$input = $invalid;
|
|
|
|
// WHEN
|
|
$execution = fn () => new RequestSignature($input);
|
|
|
|
// THEN
|
|
expect($execution)->toThrow(
|
|
\InvalidArgumentException::class,
|
|
'RequestSignature cannot be empty.'
|
|
);
|
|
})->with(['', ' ']);
|
|
|
|
it('throws InvalidArgumentException when signature format is invalid', function (string $invalid): void {
|
|
// GIVEN
|
|
$input = $invalid;
|
|
|
|
// WHEN
|
|
$execution = fn () => new RequestSignature($input);
|
|
|
|
// THEN
|
|
expect($execution)->toThrow(
|
|
\InvalidArgumentException::class,
|
|
'RequestSignature must be a valid 64-character hex HMAC-SHA256 string.'
|
|
);
|
|
})->with([
|
|
'invalid_hex',
|
|
'123456',
|
|
str_repeat('g', 64), // Invalid hex character 'g'
|
|
str_repeat('a', 63), // 63 chars (too short)
|
|
str_repeat('a', 65), // 65 chars (too long)
|
|
]);
|
|
});
|