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 'flags.allow_dump_downloading' property is disabled. * * @return void */ public function testVideoStreamingPermittedForBypass(): void { Config::set(FlagConstants::ALLOW_DUMP_DOWNLOADING_FLAG_QUALIFIED, $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)->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 { Config::set(FlagConstants::ALLOW_DUMP_DOWNLOADING_FLAG_QUALIFIED, true); $dump = Dump::factory()->createOne(); $dump->delete(); $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 { Config::set(FlagConstants::ALLOW_DUMP_DOWNLOADING_FLAG_QUALIFIED, true); $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); } }