createOne(); $response = get(route('audio.show', ['audio' => $audio])); $response->assertForbidden(); }); test('audio streaming permitted for bypass', function (): void { Storage::fake(Config::get(AudioConstants::DEFAULT_DISK_QUALIFIED)); Feature::activate(AllowAudioStreams::class, fake()->boolean()); /** @var StreamingMethod $streamingMethod */ $streamingMethod = Arr::random(StreamingMethod::cases()); Config::set(AudioConstants::STREAMING_METHOD_QUALIFIED, $streamingMethod->value); $audio = Audio::factory()->createOne(); $user = User::factory()->withPermissions(SpecialPermission::BYPASS_FEATURE_FLAGS->value)->createOne(); Sanctum::actingAs($user); $response = get(route('audio.show', ['audio' => $audio])); $response->assertSuccessful(); }); test('cannot stream soft deleted audio', function (): void { Storage::fake(Config::get(AudioConstants::DEFAULT_DISK_QUALIFIED)); Feature::activate(AllowAudioStreams::class); $audio = Audio::factory()->trashed()->createOne(); $response = get(route('audio.show', ['audio' => $audio])); $response->assertNotFound(); }); test('invalid streaming method error', function (): void { Storage::fake(Config::get(AudioConstants::DEFAULT_DISK_QUALIFIED)); Feature::activate(AllowAudioStreams::class); Config::set(AudioConstants::STREAMING_METHOD_QUALIFIED, fake()->word()); $audio = Audio::factory()->createOne(); $response = get(route('audio.show', ['audio' => $audio])); $response->assertServerError(); }); test('streamed through response', function (): void { Storage::fake(Config::get(AudioConstants::DEFAULT_DISK_QUALIFIED)); Feature::activate(AllowAudioStreams::class); Config::set(AudioConstants::STREAMING_METHOD_QUALIFIED, StreamingMethod::RESPONSE->value); $audio = Audio::factory()->createOne(); $response = get(route('audio.show', ['audio' => $audio])); $this->assertInstanceOf(StreamedResponse::class, $response->baseResponse); }); test('streamed through nginx redirect', function (): void { Storage::fake(Config::get(AudioConstants::DEFAULT_DISK_QUALIFIED)); Feature::activate(AllowAudioStreams::class); Config::set(AudioConstants::STREAMING_METHOD_QUALIFIED, StreamingMethod::NGINX->value); $audio = Audio::factory()->createOne(); $response = get(route('audio.show', ['audio' => $audio])); $response->assertHeader('X-Accel-Redirect'); });