78 lines
2.2 KiB
PHP
78 lines
2.2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Tests\Unit\Application\Security\ValueObjects;
|
||
|
|
|
||
|
|
use Application\Security\Models\ValueObjects\ClientSecret;
|
||
|
|
|
||
|
|
covers(ClientSecret::class);
|
||
|
|
|
||
|
|
describe('ClientSecret Value Object Instantiation', function (): void {
|
||
|
|
it('accepts valid client secrets', function (string $input): void {
|
||
|
|
// GIVEN
|
||
|
|
$value = $input;
|
||
|
|
|
||
|
|
// WHEN
|
||
|
|
$clientSecret = new ClientSecret($value);
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($clientSecret->value)->toBe($value);
|
||
|
|
})->with([
|
||
|
|
'arcadia_sec_' . str_repeat('b', 86),
|
||
|
|
str_repeat('s', 86),
|
||
|
|
str_repeat('s', 98),
|
||
|
|
str_repeat('s', 120),
|
||
|
|
]);
|
||
|
|
});
|
||
|
|
|
||
|
|
describe('ClientSecret Value Object Validation Rules', function (): void {
|
||
|
|
it('throws InvalidArgumentException when given an empty or whitespace-only client secret', function (string $invalid): void {
|
||
|
|
// GIVEN
|
||
|
|
$input = $invalid;
|
||
|
|
|
||
|
|
// WHEN
|
||
|
|
$execution = fn () => new ClientSecret($input);
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($execution)->toThrow(
|
||
|
|
\InvalidArgumentException::class,
|
||
|
|
'ClientSecret cannot be empty.'
|
||
|
|
);
|
||
|
|
})->with(['', ' ']);
|
||
|
|
|
||
|
|
it('throws InvalidArgumentException when client secret contains invalid characters', function (string $invalid): void {
|
||
|
|
// GIVEN
|
||
|
|
$input = $invalid;
|
||
|
|
|
||
|
|
// WHEN
|
||
|
|
$execution = fn () => new ClientSecret($input);
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($execution)->toThrow(
|
||
|
|
\InvalidArgumentException::class,
|
||
|
|
'ClientSecret can only contain alphanumeric characters, dashes, and underscores.'
|
||
|
|
);
|
||
|
|
})->with([
|
||
|
|
'arcadia_sec_invalid_chars_@!' . str_repeat('a', 60),
|
||
|
|
'arcadia_sec with spaces in between' . str_repeat('a', 60),
|
||
|
|
]);
|
||
|
|
|
||
|
|
it('throws InvalidArgumentException when client secret has an invalid length', function (string $invalid): void {
|
||
|
|
// GIVEN
|
||
|
|
$input = $invalid;
|
||
|
|
|
||
|
|
// WHEN
|
||
|
|
$execution = fn () => new ClientSecret($input);
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($execution)->toThrow(
|
||
|
|
\InvalidArgumentException::class,
|
||
|
|
'ClientSecret must be between 86 and 120 characters long.'
|
||
|
|
);
|
||
|
|
})->with([
|
||
|
|
str_repeat('a', 85),
|
||
|
|
str_repeat('a', 121),
|
||
|
|
]);
|
||
|
|
});
|