- protected share authentification backend

This commit is contained in:
Peter Papp
2021-03-18 10:06:27 +01:00
parent c73e44ff01
commit 816c8c3e07
11 changed files with 117 additions and 168 deletions
-2
View File
@@ -113,8 +113,6 @@ class AuthTest extends TestCase
'email' => $user->email,
'password' => 'secret',
])->assertStatus(200);
dd($user->tokenCan('test'));
}
/**
+1 -3
View File
@@ -477,10 +477,8 @@ class SubscriptionTest extends TestCase
*/
public function it_get_all_plans_for_index_page()
{
$response = $this->getJson('/api/pricing')
$this->getJson('/api/pricing')
->assertStatus(200);
dd(json_decode($response->content(), true));
}
/**
@@ -0,0 +1,71 @@
<?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 PrivateShareContentAccessTest 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');
}
}
@@ -13,7 +13,7 @@ use Illuminate\Support\Str;
use Storage;
use Tests\TestCase;
class ShareContentAccessTest extends TestCase
class PublicShareContentAccessTest extends TestCase
{
use DatabaseMigrations;
+14 -4
View File
@@ -113,13 +113,18 @@ class ShareEditorTest extends TestCase
*/
public function editor_create_new_folder_in_shared_folder()
{
$folder = Folder::factory(Folder::class)
$user = User::factory(User::class)
->create();
$folder = Folder::factory(Folder::class)
->create([
'user_id' => $user->id,
]);
$share = Share::factory(Share::class)
->create([
'item_id' => $folder->id,
'user_id' => $folder->user_id,
'user_id' => $user->id,
'type' => 'folder',
'is_protected' => false,
'permission' => 'editor',
@@ -146,13 +151,18 @@ class ShareEditorTest extends TestCase
*/
public function editor_delete_multiple_files_in_shared_folder()
{
$folder = Folder::factory(Folder::class)
$user = User::factory(User::class)
->create();
$folder = Folder::factory(Folder::class)
->create([
'user_id' => $user->id,
]);
$share = Share::factory(Share::class)
->create([
'item_id' => $folder->id,
'user_id' => $folder->user_id,
'user_id' => $user->id,
'type' => 'folder',
'is_protected' => false,
'permission' => 'editor',