mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-11 01:24:46 +02:00
140 lines
3.6 KiB
PHP
140 lines
3.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Actions\Storage\Admin\Dump\DumpDocumentAction;
|
|
use App\Actions\Storage\Admin\Dump\DumpWikiAction;
|
|
use App\Constants\Config\DumpConstants;
|
|
use App\Enums\Auth\SpecialPermission;
|
|
use App\Features\AllowDumpDownloading;
|
|
use App\Models\Admin\Dump;
|
|
use App\Models\Auth\User;
|
|
use Illuminate\Http\Testing\File;
|
|
use Illuminate\Support\Collection;
|
|
use Illuminate\Support\Facades\Config;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Str;
|
|
use Laravel\Pennant\Feature;
|
|
use Laravel\Sanctum\Sanctum;
|
|
|
|
use function Pest\Laravel\get;
|
|
|
|
uses(Illuminate\Foundation\Testing\WithFaker::class);
|
|
|
|
test('dump downloading not allowed forbidden', function () {
|
|
Storage::fake('local');
|
|
Storage::fake(Config::get(DumpConstants::DISK_QUALIFIED));
|
|
|
|
Feature::deactivate(AllowDumpDownloading::class);
|
|
|
|
$action = new DumpWikiAction();
|
|
|
|
$action->handle();
|
|
|
|
$response = get(route('dump.latest.wiki.show'));
|
|
|
|
$response->assertForbidden();
|
|
});
|
|
|
|
test('video streaming permitted for bypass', function () {
|
|
Storage::fake('local');
|
|
$fs = Storage::fake(Config::get(DumpConstants::DISK_QUALIFIED));
|
|
|
|
Feature::activate(AllowDumpDownloading::class, fake()->boolean());
|
|
|
|
Collection::times(fake()->randomDigitNotNull(), function () {
|
|
$action = new DumpDocumentAction();
|
|
|
|
$action->handle();
|
|
});
|
|
|
|
Collection::times(fake()->randomDigitNotNull(), function () {
|
|
$action = new DumpWikiAction();
|
|
|
|
$action->handle();
|
|
});
|
|
|
|
$path = Str::of(DumpWikiAction::FILENAME_PREFIX)
|
|
->append(fake()->word())
|
|
->append('.sql')
|
|
->__toString();
|
|
|
|
$file = File::fake()->create($path);
|
|
$fsFile = $fs->putFileAs('', $file, $path);
|
|
|
|
$dump = Dump::factory()->createOne([
|
|
Dump::ATTRIBUTE_PATH => $fsFile,
|
|
]);
|
|
|
|
$user = User::factory()->withPermissions(SpecialPermission::BYPASS_FEATURE_FLAGS->value)->createOne();
|
|
|
|
Sanctum::actingAs($user);
|
|
|
|
$response = get(route('dump.latest.wiki.show'));
|
|
|
|
$response->assertDownload($dump->path);
|
|
});
|
|
|
|
test('not found if no wiki dumps', function () {
|
|
Storage::fake('local');
|
|
Storage::fake(Config::get(DumpConstants::DISK_QUALIFIED));
|
|
|
|
Feature::activate(AllowDumpDownloading::class);
|
|
|
|
$response = get(route('dump.latest.wiki.show'));
|
|
|
|
$response->assertNotFound();
|
|
});
|
|
|
|
test('not found if document dumps exist', function () {
|
|
Storage::fake('local');
|
|
Storage::fake(Config::get(DumpConstants::DISK_QUALIFIED));
|
|
|
|
Feature::activate(AllowDumpDownloading::class);
|
|
|
|
Collection::times(fake()->randomDigitNotNull(), function () {
|
|
$action = new DumpDocumentAction();
|
|
|
|
$action->handle();
|
|
});
|
|
|
|
$response = get(route('dump.latest.wiki.show'));
|
|
|
|
$response->assertNotFound();
|
|
});
|
|
|
|
test('latest wiki dump downloaded', function () {
|
|
Storage::fake('local');
|
|
$fs = Storage::fake(Config::get(DumpConstants::DISK_QUALIFIED));
|
|
|
|
Feature::activate(AllowDumpDownloading::class);
|
|
|
|
Collection::times(fake()->randomDigitNotNull(), function () {
|
|
$action = new DumpDocumentAction();
|
|
|
|
$action->handle();
|
|
});
|
|
|
|
Collection::times(fake()->randomDigitNotNull(), function () {
|
|
$action = new DumpWikiAction();
|
|
|
|
$action->handle();
|
|
});
|
|
|
|
$path = Str::of(DumpWikiAction::FILENAME_PREFIX)
|
|
->append(fake()->word())
|
|
->append('.sql')
|
|
->__toString();
|
|
|
|
$file = File::fake()->create($path);
|
|
$fsFile = $fs->putFileAs('', $file, $path);
|
|
|
|
$dump = Dump::factory()->createOne([
|
|
Dump::ATTRIBUTE_PATH => $fsFile,
|
|
]);
|
|
|
|
$response = get(route('dump.latest.wiki.show'));
|
|
|
|
$response->assertDownload($dump->path);
|
|
});
|