feat: add secure on-demand HLS playback plugin
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plugin\AzuraCastOnDemandHls\Tests\Service;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use Plugin\AzuraCastOnDemandHls\Config;
|
||||
use Plugin\AzuraCastOnDemandHls\Security\ResourcePath;
|
||||
use Plugin\AzuraCastOnDemandHls\Service\AssetAuthorizer;
|
||||
use Plugin\AzuraCastOnDemandHls\Service\CachePaths;
|
||||
use Plugin\AzuraCastOnDemandHls\Service\SessionRepository;
|
||||
use Plugin\AzuraCastOnDemandHls\Tests\Support\TemporaryDirectoryTestCase;
|
||||
|
||||
#[CoversClass(AssetAuthorizer::class)]
|
||||
final class AssetAuthorizerTest extends TemporaryDirectoryTestCase
|
||||
{
|
||||
public function testPlaylistAndSegmentRequireValidUnexpiredStationBoundSession(): void
|
||||
{
|
||||
$config = new Config(sessionTtl: 60, cacheTtl: 60);
|
||||
$paths = new CachePaths($config);
|
||||
$sessions = new SessionRepository($config, $paths);
|
||||
$cacheKey = str_repeat('a', 64);
|
||||
$assetDirectory = $paths->asset($this->temporaryDirectory, $cacheKey);
|
||||
mkdir($assetDirectory, 0755, true);
|
||||
file_put_contents($assetDirectory . '/master.m3u8', '#EXTM3U');
|
||||
file_put_contents($assetDirectory . '/media.m3u8', '#EXTM3U');
|
||||
file_put_contents($assetDirectory . '/segment00000.ts', 'segment');
|
||||
|
||||
$created = $sessions->create(
|
||||
$this->temporaryDirectory,
|
||||
7,
|
||||
'abcdef123456abcdef123456',
|
||||
$cacheKey,
|
||||
str_repeat('c', 64),
|
||||
1000,
|
||||
);
|
||||
$authorizer = new AssetAuthorizer($sessions, $paths);
|
||||
|
||||
self::assertNotNull($authorizer->authorize($this->temporaryDirectory, 7, $created['token'], 'master.m3u8', 1059));
|
||||
self::assertNotNull($authorizer->authorize($this->temporaryDirectory, 7, $created['token'], 'segment00000.ts', 1059));
|
||||
self::assertNull($authorizer->authorize($this->temporaryDirectory, 8, $created['token'], 'master.m3u8', 1059));
|
||||
self::assertNull($authorizer->authorize($this->temporaryDirectory, 7, $created['token'], 'master.m3u8', 1060));
|
||||
self::assertNull($authorizer->authorize($this->temporaryDirectory, 7, 'x' . substr($created['token'], 1), 'master.m3u8', 1059));
|
||||
self::assertNull($authorizer->authorize($this->temporaryDirectory, 7, $created['token'], '../master.m3u8', 1059));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user