feat: add secure on-demand HLS playback plugin
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plugin\AzuraCastOnDemandHls\Tests\Service;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use Plugin\AzuraCastOnDemandHls\Config;
|
||||
use Plugin\AzuraCastOnDemandHls\Service\CachePaths;
|
||||
use Plugin\AzuraCastOnDemandHls\Service\CleanupService;
|
||||
use Plugin\AzuraCastOnDemandHls\Service\SessionRepository;
|
||||
use Plugin\AzuraCastOnDemandHls\Tests\Support\TemporaryDirectoryTestCase;
|
||||
use Psr\Log\NullLogger;
|
||||
|
||||
#[CoversClass(CleanupService::class)]
|
||||
final class CleanupServiceTest extends TemporaryDirectoryTestCase
|
||||
{
|
||||
public function testExpiredSessionsAndUnreferencedAssetsAreRemoved(): void
|
||||
{
|
||||
$config = new Config(sessionTtl: 60, cacheTtl: 60);
|
||||
$paths = new CachePaths($config);
|
||||
$sessions = new SessionRepository($config, $paths);
|
||||
$cacheKey = str_repeat('a', 64);
|
||||
$created = $sessions->create(
|
||||
$this->temporaryDirectory,
|
||||
7,
|
||||
'abcdef123456abcdef123456',
|
||||
$cacheKey,
|
||||
str_repeat('c', 64),
|
||||
1000,
|
||||
);
|
||||
$asset = $paths->asset($this->temporaryDirectory, $cacheKey);
|
||||
mkdir($asset, 0755, true);
|
||||
file_put_contents($asset . '/master.m3u8', '#EXTM3U');
|
||||
touch($asset, 1000);
|
||||
|
||||
$cleanup = new CleanupService($config, $paths, new NullLogger());
|
||||
$result = $cleanup->run($this->temporaryDirectory, 1061);
|
||||
|
||||
self::assertSame(['sessions' => 1, 'assets' => 1], $result);
|
||||
self::assertNull($sessions->find($this->temporaryDirectory, $created['token']));
|
||||
self::assertDirectoryDoesNotExist($asset);
|
||||
}
|
||||
|
||||
public function testActiveSessionPreventsCacheDeletion(): void
|
||||
{
|
||||
$config = new Config(sessionTtl: 120, cacheTtl: 120);
|
||||
$paths = new CachePaths($config);
|
||||
$sessions = new SessionRepository($config, $paths);
|
||||
$cacheKey = str_repeat('a', 64);
|
||||
$sessions->create(
|
||||
$this->temporaryDirectory,
|
||||
7,
|
||||
'abcdef123456abcdef123456',
|
||||
$cacheKey,
|
||||
str_repeat('c', 64),
|
||||
1000,
|
||||
);
|
||||
$asset = $paths->asset($this->temporaryDirectory, $cacheKey);
|
||||
mkdir($asset, 0755, true);
|
||||
touch($asset, 1);
|
||||
|
||||
$cleanup = new CleanupService($config, $paths, new NullLogger());
|
||||
self::assertSame(['sessions' => 0, 'assets' => 0], $cleanup->run($this->temporaryDirectory, 1050));
|
||||
self::assertDirectoryExists($asset);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user