Files
hstream-ddl/tests/Feature/CheckPathTest.php
T

96 lines
2.7 KiB
PHP

<?php
namespace Tests\Feature;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class CheckPathTest extends TestCase
{
private function tokenize(string $value): string
{
return Crypt::encryptString($value);
}
public function test_valid_file_returns_size(): void
{
Storage::fake('local');
Storage::put('hentai-1080p/2026/Title/E01.mp4', 'fake-content');
$folder = $this->tokenize('hentai-1080p/2026/Title/E01.mp4');
$time = $this->tokenize(now()->addHours(6)->toDateTimeString());
$this->getJson("/check/{$folder}/{$time}")
->assertOk()
->assertJson([
'valid' => true,
'type' => 'file',
])
->assertJsonPath('size', strlen('fake-content'));
}
public function test_valid_directory_is_recognized(): void
{
Storage::fake('local');
Storage::put('2026/Title/E01/720/manifest.mpd', 'fake-manifest');
$folder = $this->tokenize('2026/Title');
$time = $this->tokenize(now()->addHours(6)->toDateTimeString());
$this->getJson("/check/{$folder}/{$time}")
->assertOk()
->assertJson([
'valid' => true,
'type' => 'directory',
'size' => null,
]);
}
public function test_missing_path_returns_404(): void
{
Storage::fake('local');
$folder = $this->tokenize('hentai/2026/Title/E01.mp4');
$time = $this->tokenize(now()->addHours(6)->toDateTimeString());
$this->getJson("/check/{$folder}/{$time}")
->assertStatus(404)
->assertJson(['valid' => false]);
}
public function test_expired_token_returns_410(): void
{
Storage::fake('local');
Storage::put('hentai/2026/Title/E01.mp4', 'fake-content');
$folder = $this->tokenize('hentai/2026/Title/E01.mp4');
$time = $this->tokenize(now()->subMinute()->toDateTimeString());
$this->getJson("/check/{$folder}/{$time}")
->assertStatus(410)
->assertJson(['valid' => false]);
}
public function test_invalid_token_returns_422(): void
{
Storage::fake('local');
$this->getJson('/check/not-a-token/not-a-token')
->assertStatus(422)
->assertJson(['valid' => false]);
}
public function test_path_traversal_is_rejected(): void
{
Storage::fake('local');
$folder = $this->tokenize('../../etc/passwd');
$time = $this->tokenize(now()->addHours(6)->toDateTimeString());
$this->getJson("/check/{$folder}/{$time}")
->assertStatus(422)
->assertJson(['valid' => false]);
}
}