createOne(); $response = $this->get(route('dump.show', ['dump' => $dump])); $response->assertForbidden(); } /** * Users with the bypass feature flag permission shall be permitted to download dumps * even if the Allow Dump Downloading feature is disabled. * * @return void */ public function testVideoStreamingPermittedForBypass(): void { Feature::activate(AllowDumpDownloading::class, $this->faker->boolean()); $fs = Storage::fake(Config::get(DumpConstants::DISK_QUALIFIED)); $file = File::fake()->create($this->faker->word().'.sql'); $fsFile = $fs->putFile('', $file); $dump = Dump::factory()->createOne([ Dump::ATTRIBUTE_PATH => $fsFile, ]); $user = User::factory()->withPermissions(SpecialPermission::BYPASS_FEATURE_FLAGS->value)->createOne(); Sanctum::actingAs($user); $response = $this->get(route('dump.show', ['dump' => $dump])); $response->assertDownload($dump->path); } /** * If the dump is soft-deleted, the user shall receive a not found exception. * * @return void */ public function testCannotDownloadSoftDeletedDump(): void { Feature::activate(AllowDumpDownloading::class); $dump = Dump::factory()->trashed()->createOne(); $response = $this->get(route('dump.show', ['dump' => $dump])); $response->assertNotFound(); } /** * If dump downloading is enabled, the dump is downloaded from storage through the response. * * @return void */ public function testDownloadedThroughResponse(): void { Feature::activate(AllowDumpDownloading::class); $fs = Storage::fake(Config::get(DumpConstants::DISK_QUALIFIED)); $file = File::fake()->create($this->faker->word().'.sql'); $fsFile = $fs->putFile('', $file); $dump = Dump::factory()->createOne([ Dump::ATTRIBUTE_PATH => $fsFile, ]); $response = $this->get(route('dump.show', ['dump' => $dump])); $response->assertDownload($dump->path); } }