64 lines
1.7 KiB
PHP
64 lines
1.7 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Tests\Unit\Application\Security\ValueObjects\Request;
|
||
|
|
|
||
|
|
use Application\Security\Models\ValueObjects\Request\HttpBodyHash;
|
||
|
|
|
||
|
|
covers(HttpBodyHash::class);
|
||
|
|
|
||
|
|
describe('HttpBodyHash Value Object Instantiation', function (): void {
|
||
|
|
it('accepts valid SHA256 hex hashes', function (string $input): void {
|
||
|
|
// GIVEN
|
||
|
|
$value = $input;
|
||
|
|
|
||
|
|
// WHEN
|
||
|
|
$bodyHash = new HttpBodyHash($value);
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($bodyHash->value)->toBe($value);
|
||
|
|
})->with([
|
||
|
|
hash('sha256', ''),
|
||
|
|
hash('sha256', 'payload content'),
|
||
|
|
str_repeat('a', 64),
|
||
|
|
str_repeat('F', 64),
|
||
|
|
]);
|
||
|
|
});
|
||
|
|
|
||
|
|
describe('HttpBodyHash Value Object Validation Rules', function (): void {
|
||
|
|
it('throws InvalidArgumentException when given an empty body hash', function (): void {
|
||
|
|
// GIVEN
|
||
|
|
$invalid = '';
|
||
|
|
|
||
|
|
// WHEN
|
||
|
|
$execution = fn () => new HttpBodyHash($invalid);
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($execution)->toThrow(
|
||
|
|
\InvalidArgumentException::class,
|
||
|
|
'HttpBody cannot be empty'
|
||
|
|
);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('throws InvalidArgumentException when given an invalid SHA256 hash', function (string $invalid): void {
|
||
|
|
// GIVEN
|
||
|
|
$input = $invalid;
|
||
|
|
|
||
|
|
// WHEN
|
||
|
|
$execution = fn () => new HttpBodyHash($input);
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($execution)->toThrow(
|
||
|
|
\InvalidArgumentException::class,
|
||
|
|
'HttpBody must be a valid SHA256 hash'
|
||
|
|
);
|
||
|
|
})->with([
|
||
|
|
'invalid_hash',
|
||
|
|
'12345',
|
||
|
|
str_repeat('g', 64), // Invalid hex character
|
||
|
|
str_repeat('a', 63), // 63 chars (too short)
|
||
|
|
str_repeat('a', 65), // 65 chars (too long)
|
||
|
|
]);
|
||
|
|
});
|