- Add comprehensive health check system with multiple endpoints - Add Prometheus metrics endpoint - Add production logging configurations (5 strategies) - Add complete deployment documentation suite: * QUICKSTART.md - 30-minute deployment guide * DEPLOYMENT_CHECKLIST.md - Printable verification checklist * DEPLOYMENT_WORKFLOW.md - Complete deployment lifecycle * PRODUCTION_DEPLOYMENT.md - Comprehensive technical reference * production-logging.md - Logging configuration guide * ANSIBLE_DEPLOYMENT.md - Infrastructure as Code automation * README.md - Navigation hub * DEPLOYMENT_SUMMARY.md - Executive summary - Add deployment scripts and automation - Add DEPLOYMENT_PLAN.md - Concrete plan for immediate deployment - Update README with production-ready features All production infrastructure is now complete and ready for deployment.
115 lines
3.9 KiB
PHP
115 lines
3.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Framework\LiveComponents\ValueObjects\UploadSessionId;
|
|
|
|
describe('UploadSessionId Value Object', function () {
|
|
it('creates session id from valid string', function () {
|
|
$value = str_repeat('a', 32); // 32 characters
|
|
$sessionId = UploadSessionId::fromString($value);
|
|
|
|
expect($sessionId->value)->toBe($value);
|
|
expect($sessionId->toString())->toBe($value);
|
|
});
|
|
|
|
it('rejects session id shorter than 32 characters', function () {
|
|
$value = str_repeat('a', 31); // 31 characters - too short
|
|
|
|
expect(fn() => UploadSessionId::fromString($value))
|
|
->toThrow(InvalidArgumentException::class);
|
|
});
|
|
|
|
it('accepts session id longer than 32 characters', function () {
|
|
$value = str_repeat('a', 64); // 64 characters - valid
|
|
$sessionId = UploadSessionId::fromString($value);
|
|
|
|
expect($sessionId->value)->toBe($value);
|
|
});
|
|
|
|
it('rejects non-alphanumeric characters', function () {
|
|
$value = str_repeat('a', 31) . '@'; // 32 chars with special char
|
|
|
|
expect(fn() => UploadSessionId::fromString($value))
|
|
->toThrow(InvalidArgumentException::class);
|
|
});
|
|
|
|
it('accepts uppercase and lowercase alphanumeric', function () {
|
|
$value = 'abcdefghijklmnopqrstuvwxyz012345'; // 32 chars
|
|
$sessionId = UploadSessionId::fromString($value);
|
|
|
|
expect($sessionId->value)->toBe($value);
|
|
});
|
|
|
|
it('accepts mixed case alphanumeric', function () {
|
|
$value = 'AbCdEfGh12345678IjKlMnOp90123456'; // 32 chars
|
|
$sessionId = UploadSessionId::fromString($value);
|
|
|
|
expect($sessionId->value)->toBe($value);
|
|
});
|
|
|
|
it('compares session ids for equality', function () {
|
|
$value = str_repeat('a', 32);
|
|
|
|
$id1 = UploadSessionId::fromString($value);
|
|
$id2 = UploadSessionId::fromString($value);
|
|
$id3 = UploadSessionId::fromString(str_repeat('b', 32));
|
|
|
|
expect($id1->equals($id2))->toBeTrue();
|
|
expect($id1->equals($id3))->toBeFalse();
|
|
});
|
|
|
|
it('uses timing-safe comparison', function () {
|
|
// Test that equals() uses hash_equals for timing safety
|
|
$id1 = UploadSessionId::fromString(str_repeat('a', 32));
|
|
$id2 = UploadSessionId::fromString(str_repeat('a', 32));
|
|
|
|
// This tests the implementation detail that hash_equals is used
|
|
expect($id1->equals($id2))->toBeTrue();
|
|
});
|
|
|
|
it('converts to string via toString', function () {
|
|
$value = str_repeat('a', 32);
|
|
$sessionId = UploadSessionId::fromString($value);
|
|
|
|
expect($sessionId->toString())->toBe($value);
|
|
});
|
|
|
|
it('converts to string via __toString', function () {
|
|
$value = str_repeat('a', 32);
|
|
$sessionId = UploadSessionId::fromString($value);
|
|
|
|
expect((string) $sessionId)->toBe($value);
|
|
});
|
|
|
|
it('handles hex-encoded session ids', function () {
|
|
// Typical format from bin2hex(random_bytes(16))
|
|
$hexValue = bin2hex(random_bytes(16)); // 32 hex characters
|
|
$sessionId = UploadSessionId::fromString($hexValue);
|
|
|
|
expect(strlen($sessionId->value))->toBe(32);
|
|
expect(ctype_xdigit($sessionId->value))->toBeTrue();
|
|
});
|
|
|
|
it('rejects empty string', function () {
|
|
expect(fn() => UploadSessionId::fromString(''))
|
|
->toThrow(InvalidArgumentException::class);
|
|
});
|
|
|
|
it('rejects whitespace characters', function () {
|
|
$value = str_repeat('a', 31) . ' '; // 32 chars with space
|
|
|
|
expect(fn() => UploadSessionId::fromString($value))
|
|
->toThrow(InvalidArgumentException::class);
|
|
});
|
|
|
|
it('rejects special characters', function () {
|
|
$specialChars = ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '+', '='];
|
|
|
|
foreach ($specialChars as $char) {
|
|
expect(fn() => UploadSessionId::fromString(str_repeat('a', 31) . $char))
|
|
->toThrow(InvalidArgumentException::class);
|
|
}
|
|
});
|
|
});
|