mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-05 18:23:48 +00:00
72 lines
1.9 KiB
PHP
72 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Share;
|
|
|
|
use App\Models\File;
|
|
use App\Models\Share;
|
|
use App\Services\SetupService;
|
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
|
use Tests\TestCase;
|
|
|
|
class PrivateFilesAccessTest extends TestCase
|
|
{
|
|
use DatabaseMigrations;
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->setup = app()->make(SetupService::class);
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function it_authenticate_protected_file_with_correct_password()
|
|
{
|
|
$file = File::factory(File::class)
|
|
->create();
|
|
|
|
$share = Share::factory(Share::class)
|
|
->create([
|
|
'item_id' => $file->id,
|
|
'user_id' => $file->user_id,
|
|
'type' => 'file',
|
|
'is_protected' => true,
|
|
'password' => \Hash::make('secret'),
|
|
]);
|
|
|
|
$this->postJson("/api/browse/authenticate/$share->token", [
|
|
'password' => 'secret'
|
|
])
|
|
->assertStatus(200)
|
|
->assertCookie('share_session', json_encode([
|
|
'token' => $share->token,
|
|
'authenticated' => true,
|
|
]), false);
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function it_authenticate_protected_file_with_incorrect_password()
|
|
{
|
|
$file = File::factory(File::class)
|
|
->create();
|
|
|
|
$share = Share::factory(Share::class)
|
|
->create([
|
|
'item_id' => $file->id,
|
|
'user_id' => $file->user_id,
|
|
'type' => 'file',
|
|
'is_protected' => true,
|
|
'password' => \Hash::make('secret'),
|
|
]);
|
|
|
|
$this->postJson("/api/browse/authenticate/$share->token", [
|
|
'password' => 'bad-password'
|
|
])
|
|
->assertStatus(401)
|
|
->assertCookieMissing('share_session');
|
|
}
|
|
}
|