Add fole check endpoint & Update dependencies

This commit is contained in:
2026-08-05 22:01:32 +02:00
parent 0702d445b2
commit b8f7bc48e1
10 changed files with 2378 additions and 1506 deletions
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace Tests;
use Illuminate\Contracts\Console\Kernel;
trait CreatesApplication
{
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();
return $app;
}
}
+95
View File
@@ -0,0 +1,95 @@
<?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]);
}
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace Tests;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
}
View File