-
- @empty($qrCodeSvg)
-
-
-
- @else
-
-
- {!! $qrCodeSvg !!}
-
-
- @endempty
-
+
+
+
+
+ {{ __('or, enter the code manually') }}
+
-
-
- {{ $this->modalConfig['buttonText'] }}
-
-
-
-
-
-
-
- {{ __('or, enter the code manually') }}
-
-
-
-
-
- @empty($manualSetupKey)
-
-
-
- @else
-
-
-
-
-
-
- @endempty
-
+ }
+ }"
+ >
+
+
+
+
+
+
- @endif
-
-
+
+
+
+
+
+ @endif
+
diff --git a/resources/views/partials/head.blade.php b/resources/views/partials/head.blade.php
index dce8058..de19ac7 100644
--- a/resources/views/partials/head.blade.php
+++ b/resources/views/partials/head.blade.php
@@ -1,7 +1,7 @@
-
{{ $title ?? config('app.name') }}
+
{{ $title ?? (\App\Models\Setting::get('site_title') ?: config('app.name')) }}
@@ -11,4 +11,3 @@
@vite(['resources/css/app.css', 'resources/js/app.js'])
-@fluxAppearance
diff --git a/resources/views/partials/settings-heading.blade.php b/resources/views/partials/settings-heading.blade.php
index 925ace9..5090a47 100644
--- a/resources/views/partials/settings-heading.blade.php
+++ b/resources/views/partials/settings-heading.blade.php
@@ -1,5 +1,5 @@
-
{{ __('Settings') }}
-
{{ __('Manage your profile and account settings') }}
-
+
{{ __('Settings') }}
+
{{ __('Manage your profile and account settings') }}
+
diff --git a/resources/views/welcome.blade.php b/resources/views/welcome.blade.php
index a808a39..7bd3979 100644
--- a/resources/views/welcome.blade.php
+++ b/resources/views/welcome.blade.php
@@ -1,278 +1,17 @@
-
-
-
-
-
-
Laravel
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- @if (Route::has('login'))
-
- @auth
-
- Dashboard
-
- @else
-
- Log in
-
-
- @if (Route::has('register'))
-
- Register
-
- @endif
- @endauth
-
- @endif
-
-
-
-
-
Let's get started
-
Laravel has an incredibly rich ecosystem. We suggest starting with the following.
-
-
-
-
- {{-- Laravel Logo --}}
-
-
-
-
-
-
-
-
-
-
- {{-- Light Mode 12 SVG --}}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {{-- Dark Mode 12 SVG --}}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- @if (Route::has('login'))
-
- @endif
-
+
+
+
+
+
+
{{ \App\Models\Setting::get('site_title') ?: config('app.name', 'SealShare') }}
+ @include('partials.head')
+
+
+
+
{{ \App\Models\Setting::get('site_title') ?: config('app.name', 'SealShare') }}
+
{{ __('Secure file sharing made simple.') }}
+
{{ __('Upload Files') }}
+
+
diff --git a/routes/console.php b/routes/console.php
index 3c9adf1..61f85d1 100644
--- a/routes/console.php
+++ b/routes/console.php
@@ -2,7 +2,10 @@
use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Artisan;
+use Illuminate\Support\Facades\Schedule;
Artisan::command('inspire', function () {
$this->comment(Inspiring::quote());
})->purpose('Display an inspiring quote');
+
+Schedule::command('shares:cleanup')->hourly();
diff --git a/routes/web.php b/routes/web.php
index f755f11..6bb2a5c 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -1,11 +1,37 @@
route('upload');
})->name('home');
+Route::livewire('setup', SetupWizard::class)->name('setup');
+
+Route::livewire('system-password', SystemPasswordPrompt::class)->name('system-password');
+
+Route::middleware(['system.password'])->group(function () {
+ Route::livewire('upload', FileUploader::class)->name('upload');
+ Route::livewire('share/{share:token}/created', ShareCreated::class)->name('share.created');
+});
+
+Route::livewire('s/{share:token}', ShareDownload::class)->name('share.download');
+Route::get('s/{share:token}/download', [DownloadController::class, 'download'])->name('share.download.all');
+Route::get('s/{share:token}/download/{shareFile}', [DownloadController::class, 'downloadFile'])->name('share.download.file');
+
+Route::middleware(['auth', 'admin'])->prefix('admin')->group(function () {
+ Route::livewire('dashboard', AdminDashboard::class)->name('admin.dashboard');
+ Route::livewire('settings', AdminSettings::class)->name('admin.settings');
+});
+
Route::view('dashboard', 'dashboard')
->middleware(['auth', 'verified'])
->name('dashboard');
diff --git a/tests/Feature/Admin/AdminDashboardTest.php b/tests/Feature/Admin/AdminDashboardTest.php
new file mode 100644
index 0000000..095f0e0
--- /dev/null
+++ b/tests/Feature/Admin/AdminDashboardTest.php
@@ -0,0 +1,70 @@
+get(route('admin.dashboard'));
+
+ $response->assertRedirect(route('login'));
+});
+
+test('non-admin user cannot access admin dashboard', function () {
+ $user = User::factory()->create(['is_admin' => false]);
+
+ $response = $this->actingAs($user)->get(route('admin.dashboard'));
+
+ $response->assertForbidden();
+});
+
+test('admin can access dashboard', function () {
+ $admin = User::query()->where('is_admin', true)->first();
+
+ $response = $this->actingAs($admin)->get(route('admin.dashboard'));
+
+ $response->assertOk();
+});
+
+test('admin dashboard shows stats', function () {
+ $admin = User::query()->where('is_admin', true)->first();
+
+ $share = Share::factory()->create(['total_size' => 1024]);
+ ShareFile::factory()->create(['share_id' => $share->id]);
+
+ $response = $this->actingAs($admin)->get(route('admin.dashboard'));
+
+ $response->assertOk();
+ $response->assertSee('Total Shares');
+ $response->assertSee('Active Shares');
+ $response->assertSee('Total Files');
+ $response->assertSee('Disk Usage');
+});
+
+test('admin can delete share', function () {
+ Storage::fake('shares');
+
+ $admin = User::query()->where('is_admin', true)->first();
+
+ $share = Share::factory()->create();
+ $shareId = $share->id;
+
+ Livewire::actingAs($admin)
+ ->test(\App\Livewire\Admin\AdminDashboard::class)
+ ->call('deleteShare', $shareId);
+
+ expect(Share::query()->find($shareId))->toBeNull();
+});
+
+test('admin dashboard shows shares table', function () {
+ $admin = User::query()->where('is_admin', true)->first();
+
+ $share = Share::factory()->create(['token' => 'testtoken12345678']);
+
+ $response = $this->actingAs($admin)->get(route('admin.dashboard'));
+
+ $response->assertOk();
+ $response->assertSee('testtoken12345678');
+});
diff --git a/tests/Feature/Admin/AdminSettingsTest.php b/tests/Feature/Admin/AdminSettingsTest.php
new file mode 100644
index 0000000..962762b
--- /dev/null
+++ b/tests/Feature/Admin/AdminSettingsTest.php
@@ -0,0 +1,103 @@
+get(route('admin.settings'));
+
+ $response->assertRedirect(route('login'));
+});
+
+test('non-admin user cannot access settings', function () {
+ $user = User::factory()->create(['is_admin' => false]);
+
+ $response = $this->actingAs($user)->get(route('admin.settings'));
+
+ $response->assertForbidden();
+});
+
+test('admin can access settings page', function () {
+ $admin = User::query()->where('is_admin', true)->first();
+
+ $response = $this->actingAs($admin)->get(route('admin.settings'));
+
+ $response->assertOk();
+});
+
+test('admin can save settings', function () {
+ $admin = User::query()->where('is_admin', true)->first();
+
+ $phpMaxMb = \App\Livewire\Admin\AdminSettings::phpMaxUploadMb();
+
+ Livewire::actingAs($admin)
+ ->test(\App\Livewire\Admin\AdminSettings::class)
+ ->set('maxFileSize', min(200, $phpMaxMb))
+ ->set('maxStorageQuota', 50)
+ ->set('maxFilesPerShare', 100)
+ ->set('maxSizePerShare', 5)
+ ->set('defaultExpiration', '7d')
+ ->call('saveSettings')
+ ->assertHasNoErrors();
+
+ expect(Setting::get('max_file_size'))->toBe((string) (min(200, $phpMaxMb) * 1024 * 1024));
+ expect(Setting::get('max_storage_quota'))->toBe((string) (50 * 1024 * 1024 * 1024));
+ expect(Setting::get('max_files_per_share'))->toBe('100');
+ expect(Setting::get('max_size_per_share'))->toBe((string) (5 * 1024 * 1024 * 1024));
+ expect(Setting::get('default_expiration'))->toBe('7d');
+});
+
+test('admin can set system password', function () {
+ $admin = User::query()->where('is_admin', true)->first();
+ $phpMaxMb = \App\Livewire\Admin\AdminSettings::phpMaxUploadMb();
+
+ Livewire::actingAs($admin)
+ ->test(\App\Livewire\Admin\AdminSettings::class)
+ ->set('maxFileSize', $phpMaxMb)
+ ->set('systemPassword', 'new-system-password')
+ ->call('saveSettings')
+ ->assertHasNoErrors();
+
+ $storedPassword = Setting::get('system_password');
+ expect($storedPassword)->not->toBeNull();
+ expect(\Illuminate\Support\Facades\Hash::check('new-system-password', $storedPassword))->toBeTrue();
+});
+
+test('admin can clear system password', function () {
+ $admin = User::query()->where('is_admin', true)->first();
+
+ Setting::set('system_password', bcrypt('existing-password'));
+
+ Livewire::actingAs($admin)
+ ->test(\App\Livewire\Admin\AdminSettings::class)
+ ->call('clearSystemPassword')
+ ->assertHasNoErrors();
+
+ expect(Setting::get('system_password'))->toBeNull();
+});
+
+test('settings page loads existing values', function () {
+ $admin = User::query()->where('is_admin', true)->first();
+ $phpMaxMb = \App\Livewire\Admin\AdminSettings::phpMaxUploadMb();
+ $testSize = min(40, $phpMaxMb);
+
+ Setting::set('max_file_size', $testSize * 1024 * 1024);
+ Setting::set('max_files_per_share', 75);
+
+ Livewire::actingAs($admin)
+ ->test(\App\Livewire\Admin\AdminSettings::class)
+ ->assertSet('maxFileSize', $testSize)
+ ->assertSet('maxFilesPerShare', 75);
+});
+
+test('settings validation rejects invalid values', function () {
+ $admin = User::query()->where('is_admin', true)->first();
+
+ Livewire::actingAs($admin)
+ ->test(\App\Livewire\Admin\AdminSettings::class)
+ ->set('maxFileSize', 0)
+ ->set('maxStorageQuota', 0)
+ ->call('saveSettings')
+ ->assertHasErrors(['maxFileSize', 'maxStorageQuota']);
+});
diff --git a/tests/Feature/Auth/RegistrationTest.php b/tests/Feature/Auth/RegistrationTest.php
index 50a8530..d2b15c8 100644
--- a/tests/Feature/Auth/RegistrationTest.php
+++ b/tests/Feature/Auth/RegistrationTest.php
@@ -1,21 +1,7 @@
get(route('register'));
+test('registration is disabled', function () {
+ $response = $this->get('/register');
- $response->assertOk();
+ $response->assertNotFound();
});
-
-test('new users can register', function () {
- $response = $this->post(route('register.store'), [
- 'name' => 'John Doe',
- 'email' => 'test@example.com',
- 'password' => 'password',
- 'password_confirmation' => 'password',
- ]);
-
- $response->assertSessionHasNoErrors()
- ->assertRedirect(route('dashboard', absolute: false));
-
- $this->assertAuthenticated();
-});
\ No newline at end of file
diff --git a/tests/Feature/CleanupExpiredSharesTest.php b/tests/Feature/CleanupExpiredSharesTest.php
new file mode 100644
index 0000000..35f218a
--- /dev/null
+++ b/tests/Feature/CleanupExpiredSharesTest.php
@@ -0,0 +1,60 @@
+expired()->create();
+ $active = Share::factory()->expiresInHours(24)->create();
+ $noExpiry = Share::factory()->create(['expires_at' => null]);
+
+ $this->artisan('shares:cleanup')
+ ->expectsOutputToContain('Cleaned up 1 expired share(s)')
+ ->assertExitCode(0);
+
+ expect(Share::query()->find($expired->id))->toBeNull();
+ expect(Share::query()->find($active->id))->not->toBeNull();
+ expect(Share::query()->find($noExpiry->id))->not->toBeNull();
+});
+
+test('cleanup removes shares that reached download limit', function () {
+ Storage::fake('shares');
+
+ $reachedLimit = Share::factory()->withMaxDownloads(5)->create(['download_count' => 5]);
+ $underLimit = Share::factory()->withMaxDownloads(5)->create(['download_count' => 3]);
+
+ $this->artisan('shares:cleanup')
+ ->expectsOutputToContain('Cleaned up 1 expired share(s)')
+ ->assertExitCode(0);
+
+ expect(Share::query()->find($reachedLimit->id))->toBeNull();
+ expect(Share::query()->find($underLimit->id))->not->toBeNull();
+});
+
+test('cleanup handles no expired shares', function () {
+ Storage::fake('shares');
+
+ Share::factory()->create(['expires_at' => null]);
+
+ $this->artisan('shares:cleanup')
+ ->expectsOutputToContain('Cleaned up 0 expired share(s)')
+ ->assertExitCode(0);
+});
+
+test('cleanup removes both expired and download-limited shares', function () {
+ Storage::fake('shares');
+
+ $expired = Share::factory()->expired()->create();
+ $limitReached = Share::factory()->withMaxDownloads(1)->create(['download_count' => 1]);
+ $active = Share::factory()->create(['expires_at' => null]);
+
+ $this->artisan('shares:cleanup')
+ ->expectsOutputToContain('Cleaned up 2 expired share(s)')
+ ->assertExitCode(0);
+
+ expect(Share::query()->find($expired->id))->toBeNull();
+ expect(Share::query()->find($limitReached->id))->toBeNull();
+ expect(Share::query()->find($active->id))->not->toBeNull();
+});
diff --git a/tests/Feature/DefaultBrandingTest.php b/tests/Feature/DefaultBrandingTest.php
new file mode 100644
index 0000000..2f5962a
--- /dev/null
+++ b/tests/Feature/DefaultBrandingTest.php
@@ -0,0 +1,15 @@
+seed();
+
+ expect(Setting::get('site_title'))->toBe('SealShare');
+});
+
+test('database seeder sets default site description', function () {
+ $this->seed();
+
+ expect(Setting::get('site_description'))->toBe('Simple, secure file sharing');
+});
diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php
index a576279..fee439a 100644
--- a/tests/Feature/ExampleTest.php
+++ b/tests/Feature/ExampleTest.php
@@ -1,7 +1,7 @@
get(route('home'));
- $response->assertOk();
-});
\ No newline at end of file
+ $response->assertRedirect(route('upload'));
+});
diff --git a/tests/Feature/FileUploadTest.php b/tests/Feature/FileUploadTest.php
new file mode 100644
index 0000000..3e9eec8
--- /dev/null
+++ b/tests/Feature/FileUploadTest.php
@@ -0,0 +1,131 @@
+get(route('upload'));
+
+ $response->assertOk();
+});
+
+test('upload page requires system password when configured', function () {
+ Setting::set('system_password', bcrypt('system-secret'));
+
+ $response = $this->get(route('upload'));
+
+ $response->assertRedirect(route('system-password'));
+});
+
+test('upload page accessible after system password verified', function () {
+ Setting::set('system_password', bcrypt('system-secret'));
+
+ $response = $this->withSession(['system_password_verified' => true])
+ ->get(route('upload'));
+
+ $response->assertOk();
+});
+
+test('file upload creates share', function () {
+ Storage::fake('shares');
+
+ $file = UploadedFile::fake()->create('document.pdf', 1024);
+
+ Livewire::test(\App\Livewire\FileUploader::class)
+ ->set('files', [$file])
+ ->call('createShare')
+ ->assertRedirectContains('/share/');
+
+ expect(Share::query()->count())->toBe(1);
+
+ $share = Share::query()->first();
+ expect($share->files)->toHaveCount(1);
+ expect($share->files->first()->original_name)->toBe('document.pdf');
+});
+
+test('file upload with password creates password-protected share', function () {
+ Storage::fake('shares');
+
+ $file = UploadedFile::fake()->create('secret.txt', 512);
+
+ Livewire::test(\App\Livewire\FileUploader::class)
+ ->set('files', [$file])
+ ->set('usePassword', true)
+ ->set('password', 'my-password')
+ ->call('createShare')
+ ->assertRedirectContains('/share/');
+
+ $share = Share::query()->first();
+ expect($share->isPasswordProtected())->toBeTrue();
+});
+
+test('file upload with expiration sets expires_at', function () {
+ Storage::fake('shares');
+
+ $file = UploadedFile::fake()->create('file.txt', 256);
+
+ Livewire::test(\App\Livewire\FileUploader::class)
+ ->set('files', [$file])
+ ->set('expiration', '24h')
+ ->call('createShare')
+ ->assertRedirectContains('/share/');
+
+ $share = Share::query()->first();
+ expect($share->expires_at)->not->toBeNull();
+});
+
+test('file upload with max downloads sets limit', function () {
+ Storage::fake('shares');
+
+ $file = UploadedFile::fake()->create('file.txt', 256);
+
+ Livewire::test(\App\Livewire\FileUploader::class)
+ ->set('files', [$file])
+ ->set('maxDownloads', 5)
+ ->call('createShare')
+ ->assertRedirectContains('/share/');
+
+ $share = Share::query()->first();
+ expect($share->max_downloads)->toBe(5);
+});
+
+test('file upload requires at least one file', function () {
+ Livewire::test(\App\Livewire\FileUploader::class)
+ ->set('files', [])
+ ->call('createShare')
+ ->assertHasErrors(['files']);
+});
+
+test('file upload blocks when storage is full', function () {
+ Storage::fake('shares');
+ Setting::set('max_storage_quota', 100);
+ Share::factory()->create(['total_size' => 100]);
+
+ $file = UploadedFile::fake()->create('file.txt', 1);
+
+ Livewire::test(\App\Livewire\FileUploader::class)
+ ->set('files', [$file])
+ ->call('createShare')
+ ->assertHasErrors(['files']);
+});
+
+test('system password prompt verifies correct password', function () {
+ Setting::set('system_password', bcrypt('system-secret'));
+
+ Livewire::test(\App\Livewire\SystemPasswordPrompt::class)
+ ->set('password', 'system-secret')
+ ->call('verify')
+ ->assertRedirect(route('upload'));
+});
+
+test('system password prompt rejects incorrect password', function () {
+ Setting::set('system_password', bcrypt('system-secret'));
+
+ Livewire::test(\App\Livewire\SystemPasswordPrompt::class)
+ ->set('password', 'wrong')
+ ->call('verify')
+ ->assertHasErrors(['password']);
+});
diff --git a/tests/Feature/SecurityAuditTest.php b/tests/Feature/SecurityAuditTest.php
new file mode 100644
index 0000000..74306a4
--- /dev/null
+++ b/tests/Feature/SecurityAuditTest.php
@@ -0,0 +1,284 @@
+create('file.txt', 100);
+
+ $share = $service->createShare([
+ ['file' => $file, 'relativePath' => null],
+ ], [
+ 'password' => 'test-password-secure',
+ ]);
+
+ Livewire::test(ShareDownload::class, ['share' => $share])
+ ->set('password', 'test-password-secure')
+ ->call('verifyPassword');
+
+ expect(session('share_key_'.$share->token))->not->toBeNull();
+ expect(session('share_key_'.$share->token))->not->toBe('test-password-secure');
+ expect(strlen(session('share_key_'.$share->token)))->toBe(64);
+});
+
+// --- Rate limiting on password verification ---
+
+test('rate limiting blocks after 5 failed password attempts', function () {
+ Storage::fake('shares');
+
+ $service = app(ShareService::class);
+ $file = UploadedFile::fake()->create('file.txt', 100);
+
+ $share = $service->createShare([
+ ['file' => $file, 'relativePath' => null],
+ ], [
+ 'password' => 'correct-password',
+ ]);
+
+ $component = Livewire::test(ShareDownload::class, ['share' => $share]);
+
+ for ($i = 0; $i < 5; $i++) {
+ $component->set('password', 'wrong-password')
+ ->call('verifyPassword')
+ ->assertHasErrors(['password']);
+ }
+
+ $component->set('password', 'correct-password')
+ ->call('verifyPassword')
+ ->assertHasErrors(['password'])
+ ->assertSet('authenticated', false);
+});
+
+test('rate limiter clears after successful password verification', function () {
+ Storage::fake('shares');
+
+ $service = app(ShareService::class);
+ $file = UploadedFile::fake()->create('file.txt', 100);
+
+ $share = $service->createShare([
+ ['file' => $file, 'relativePath' => null],
+ ], [
+ 'password' => 'correct-password',
+ ]);
+
+ $component = Livewire::test(ShareDownload::class, ['share' => $share]);
+
+ $component->set('password', 'wrong-password')
+ ->call('verifyPassword')
+ ->assertHasErrors(['password']);
+
+ $component->set('password', 'correct-password')
+ ->call('verifyPassword')
+ ->assertSet('authenticated', true);
+
+ $rateLimitKey = 'share-password:'.$share->token.'|127.0.0.1';
+ expect(RateLimiter::remaining($rateLimitKey, 5))->toBe(5);
+});
+
+// --- Share password minimum length ---
+
+test('share password must be at least 8 characters', function () {
+ Storage::fake('shares');
+
+ $file = UploadedFile::fake()->create('file.txt', 100);
+
+ Livewire::test(FileUploader::class)
+ ->set('files', [$file])
+ ->set('usePassword', true)
+ ->set('password', 'short')
+ ->call('createShare')
+ ->assertHasErrors(['password']);
+});
+
+test('share password of 8 characters is accepted', function () {
+ Storage::fake('shares');
+
+ $file = UploadedFile::fake()->create('file.txt', 100);
+
+ Livewire::test(FileUploader::class)
+ ->set('files', [$file])
+ ->set('usePassword', true)
+ ->set('password', 'longenough')
+ ->call('createShare')
+ ->assertHasNoErrors(['password']);
+});
+
+// --- is_admin not mass assignable ---
+
+test('is_admin is not mass assignable on User model', function () {
+ $user = User::query()->create([
+ 'name' => 'Test User',
+ 'email' => 'mass-assign-test@example.com',
+ 'password' => bcrypt('password'),
+ 'is_admin' => true,
+ ]);
+
+ expect($user->is_admin)->toBeFalsy();
+});
+
+// --- Setup wizard guard prevents duplicate admins ---
+
+test('setup wizard createAdmin is blocked when admin already exists', function () {
+ $adminCountBefore = User::query()->where('is_admin', true)->count();
+
+ $this->post(route('setup'), [
+ 'name' => 'Second Admin',
+ 'email' => 'second-admin@example.com',
+ 'password' => 'password123',
+ 'password_confirmation' => 'password123',
+ ]);
+
+ expect(User::query()->where('email', 'second-admin@example.com')->exists())->toBeFalse();
+ expect(User::query()->where('is_admin', true)->count())->toBe($adminCountBefore);
+});
+
+// --- Content-Disposition sanitization ---
+
+test('content disposition handles special characters in filename', function () {
+ Storage::fake('shares');
+
+ $service = app(ShareService::class);
+ $encryptionService = app(FileEncryptionService::class);
+
+ $file = UploadedFile::fake()->create('normal.txt', 100);
+
+ $share = $service->createShare([
+ ['file' => $file, 'relativePath' => null],
+ ]);
+
+ $share->load('files');
+ $shareFile = $share->files->first();
+
+ $shareFile->original_name = 'file"with"quotes.txt';
+ $shareFile->save();
+
+ $encryptedDir = Storage::disk('shares')->path($share->token);
+ if (! is_dir($encryptedDir)) {
+ mkdir($encryptedDir, 0755, true);
+ }
+ $encryptedPath = $encryptedDir.'/'.basename($shareFile->stored_path);
+ $tempSource = tempnam(sys_get_temp_dir(), 'test');
+ file_put_contents($tempSource, 'test content');
+ $encryptionService->encryptFile($tempSource, $encryptedPath, $share->encryption_key);
+ unlink($tempSource);
+
+ $response = $encryptionService->decryptFileStream(
+ $encryptedPath,
+ $share->encryption_key,
+ 'file"with"quotes.txt',
+ 'text/plain',
+ 12,
+ );
+
+ $contentDisposition = $response->headers->get('Content-Disposition');
+ expect($contentDisposition)->not->toContain('file"with"quotes.txt');
+ expect($contentDisposition)->toContain('attachment');
+});
+
+// --- SVG upload rejected ---
+
+test('svg upload is rejected for site logo', function () {
+ $admin = User::query()->where('is_admin', true)->first();
+
+ $phpMaxMb = \App\Livewire\Admin\AdminSettings::phpMaxUploadMb();
+
+ Livewire::actingAs($admin)
+ ->test(\App\Livewire\Admin\AdminSettings::class)
+ ->set('maxFileSize', $phpMaxMb)
+ ->set('siteLogo', UploadedFile::fake()->create('logo.svg', 100, 'image/svg+xml'))
+ ->call('saveSettings')
+ ->assertHasErrors(['siteLogo']);
+});
+
+// --- Relative path validation (Zip Slip prevention) ---
+
+test('relative paths with directory traversal are sanitized', function () {
+ Storage::fake('shares');
+
+ $file = UploadedFile::fake()->create('file.txt', 100);
+
+ Livewire::test(FileUploader::class)
+ ->set('files', [$file])
+ ->set('relativePaths', ['../../etc/passwd'])
+ ->call('createShare')
+ ->assertRedirectContains('/share/');
+
+ $share = Share::query()->first();
+ $shareFile = $share->files->first();
+ expect($shareFile->relative_path)->toBeNull();
+});
+
+test('relative paths with absolute paths are sanitized', function () {
+ Storage::fake('shares');
+
+ $file = UploadedFile::fake()->create('file.txt', 100);
+
+ Livewire::test(FileUploader::class)
+ ->set('files', [$file])
+ ->set('relativePaths', ['/etc/passwd'])
+ ->call('createShare')
+ ->assertRedirectContains('/share/');
+
+ $share = Share::query()->first();
+ $shareFile = $share->files->first();
+ expect($shareFile->relative_path)->toBeNull();
+});
+
+test('valid relative paths are preserved', function () {
+ Storage::fake('shares');
+
+ $file = UploadedFile::fake()->create('file.txt', 100);
+
+ Livewire::test(FileUploader::class)
+ ->set('files', [$file])
+ ->set('relativePaths', ['folder/subfolder/file.txt'])
+ ->call('createShare')
+ ->assertRedirectContains('/share/');
+
+ $share = Share::query()->first();
+ $shareFile = $share->files->first();
+ expect($shareFile->relative_path)->toBe('folder/subfolder/file.txt');
+});
+
+// --- Security headers ---
+
+test('security headers are present on responses', function () {
+ $response = $this->get(route('upload'));
+
+ $response->assertHeader('X-Content-Type-Options', 'nosniff');
+ $response->assertHeader('X-Frame-Options', 'DENY');
+ $response->assertHeader('Referrer-Policy', 'strict-origin-when-cross-origin');
+ $response->assertHeader('Permissions-Policy', 'camera=(), microphone=(), geolocation=()');
+});
+
+// --- Token collision retry ---
+
+test('share service generates unique tokens', function () {
+ Storage::fake('shares');
+
+ $service = app(ShareService::class);
+
+ $shares = [];
+ for ($i = 0; $i < 5; $i++) {
+ $file = UploadedFile::fake()->create("file{$i}.txt", 100);
+ $shares[] = $service->createShare([
+ ['file' => $file, 'relativePath' => null],
+ ]);
+ }
+
+ $tokens = array_map(fn ($s) => $s->token, $shares);
+ expect(array_unique($tokens))->toHaveCount(5);
+});
diff --git a/tests/Feature/SetupWizardTest.php b/tests/Feature/SetupWizardTest.php
new file mode 100644
index 0000000..728d036
--- /dev/null
+++ b/tests/Feature/SetupWizardTest.php
@@ -0,0 +1,56 @@
+where('is_admin', true)->delete();
+
+ $response = $this->get(route('setup'));
+
+ $response->assertOk();
+});
+
+test('setup wizard redirects to upload when admin already exists', function () {
+ Livewire::test(\App\Livewire\SetupWizard::class)
+ ->assertRedirect(route('upload'));
+});
+
+test('setup wizard creates admin user', function () {
+ User::query()->where('is_admin', true)->delete();
+
+ Livewire::test(\App\Livewire\SetupWizard::class)
+ ->set('name', 'Admin User')
+ ->set('email', 'admin@example.com')
+ ->set('password', 'password123')
+ ->set('password_confirmation', 'password123')
+ ->call('createAdmin')
+ ->assertRedirect(route('admin.dashboard'));
+
+ $this->assertDatabaseHas('users', [
+ 'email' => 'admin@example.com',
+ 'is_admin' => true,
+ ]);
+
+ $admin = User::query()->where('email', 'admin@example.com')->first();
+ expect($admin)->not->toBeNull();
+ expect($admin->is_admin)->toBeTrue();
+});
+
+test('setup wizard validates required fields', function () {
+ User::query()->where('is_admin', true)->delete();
+
+ Livewire::test(\App\Livewire\SetupWizard::class)
+ ->set('name', '')
+ ->set('email', '')
+ ->set('password', '')
+ ->call('createAdmin')
+ ->assertHasErrors(['name', 'email', 'password']);
+});
+
+test('all routes redirect to setup when no admin exists', function () {
+ User::query()->where('is_admin', true)->delete();
+
+ $this->get(route('home'))->assertRedirect(route('setup'));
+ $this->get(route('login'))->assertRedirect(route('setup'));
+});
diff --git a/tests/Feature/ShareDownloadTest.php b/tests/Feature/ShareDownloadTest.php
new file mode 100644
index 0000000..6d2e560
--- /dev/null
+++ b/tests/Feature/ShareDownloadTest.php
@@ -0,0 +1,138 @@
+get(route('share.download', $share));
+
+ $response->assertOk();
+});
+
+test('share download page returns 404 for expired share', function () {
+ $share = Share::factory()->expired()->create();
+
+ $response = $this->get(route('share.download', $share));
+
+ $response->assertNotFound();
+});
+
+test('share download page returns 404 when download limit reached', function () {
+ $share = Share::factory()->withMaxDownloads(1)->create(['download_count' => 1]);
+
+ $response = $this->get(route('share.download', $share));
+
+ $response->assertNotFound();
+});
+
+test('share download page shows password form for password-protected share', function () {
+ Storage::fake('shares');
+
+ $share = createShareWithFile('secret-pass');
+
+ $response = $this->get(route('share.download', $share));
+
+ $response->assertOk();
+ $response->assertSee('password');
+});
+
+test('password verification works for protected share', function () {
+ Storage::fake('shares');
+
+ $share = createShareWithFile('my-password');
+
+ Livewire::test(\App\Livewire\ShareDownload::class, ['share' => $share])
+ ->assertSet('authenticated', false)
+ ->set('password', 'my-password')
+ ->call('verifyPassword')
+ ->assertSet('authenticated', true)
+ ->assertHasNoErrors();
+});
+
+test('wrong password is rejected', function () {
+ Storage::fake('shares');
+
+ $share = createShareWithFile('my-password');
+
+ Livewire::test(\App\Livewire\ShareDownload::class, ['share' => $share])
+ ->set('password', 'wrong-password')
+ ->call('verifyPassword')
+ ->assertSet('authenticated', false)
+ ->assertHasErrors(['password']);
+});
+
+test('non-password share shows files directly', function () {
+ Storage::fake('shares');
+
+ $share = createShareWithFile();
+
+ Livewire::test(\App\Livewire\ShareDownload::class, ['share' => $share])
+ ->assertSet('authenticated', true);
+});
+
+test('download counter increments on zip download', function () {
+ Storage::fake('shares');
+
+ $share = createShareWithFile();
+ $share->load('files');
+
+ $encryptionService = app(FileEncryptionService::class);
+ $key = $share->encryption_key;
+
+ foreach ($share->files as $file) {
+ $dir = Storage::disk('shares')->path($share->token);
+ if (! is_dir($dir)) {
+ mkdir($dir, 0755, true);
+ }
+ $encryptedPath = $dir.'/'.basename($file->stored_path);
+ $tempSource = tempnam(sys_get_temp_dir(), 'test');
+ file_put_contents($tempSource, 'test content');
+ $encryptionService->encryptFile($tempSource, $encryptedPath, $key);
+ unlink($tempSource);
+ }
+
+ $this->withSession(['share_password_'.$share->token => null])
+ ->get(route('share.download.all', $share));
+
+ expect($share->fresh()->download_count)->toBe(1);
+});
+
+test('share auto-deletes after reaching download limit', function () {
+ Storage::fake('shares');
+
+ $service = app(ShareService::class);
+ $file = UploadedFile::fake()->create('file.txt', 100);
+
+ $share = $service->createShare([
+ ['file' => $file, 'relativePath' => null],
+ ], [
+ 'max_downloads' => 1,
+ ]);
+
+ $service->recordDownload($share);
+
+ expect(Share::query()->find($share->id))->toBeNull();
+});
+
+/**
+ * Helper to create a share with an actual encrypted file.
+ */
+function createShareWithFile(?string $password = null): Share
+{
+ $service = app(ShareService::class);
+ $file = UploadedFile::fake()->create('testfile.txt', 100);
+
+ return $service->createShare([
+ ['file' => $file, 'relativePath' => null],
+ ], [
+ 'password' => $password,
+ ]);
+}
diff --git a/tests/Pest.php b/tests/Pest.php
index 40d096b..bdcb1bc 100644
--- a/tests/Pest.php
+++ b/tests/Pest.php
@@ -13,6 +13,10 @@
pest()->extend(Tests\TestCase::class)
->use(Illuminate\Foundation\Testing\RefreshDatabase::class)
+ ->beforeEach(function () {
+ // EnsureSetupComplete middleware redirects to /setup unless an admin exists.
+ \App\Models\User::factory()->admin()->create(['email' => 'admin-setup@test.com']);
+ })
->in('Feature');
/*
diff --git a/tests/Unit/FileEncryptionServiceTest.php b/tests/Unit/FileEncryptionServiceTest.php
new file mode 100644
index 0000000..61d6fe6
--- /dev/null
+++ b/tests/Unit/FileEncryptionServiceTest.php
@@ -0,0 +1,256 @@
+service = new FileEncryptionService;
+ $this->tempDir = sys_get_temp_dir().'/sealshare-test-'.uniqid();
+ mkdir($this->tempDir, 0755, true);
+});
+
+afterEach(function () {
+ if (is_dir($this->tempDir)) {
+ array_map('unlink', glob($this->tempDir.'/*'));
+ rmdir($this->tempDir);
+ }
+});
+
+test('encrypt and decrypt round-trip works', function () {
+ $sourcePath = $this->tempDir.'/source.txt';
+ $encryptedPath = $this->tempDir.'/encrypted.enc';
+ $content = 'Hello, World! This is a secret message.';
+
+ file_put_contents($sourcePath, $content);
+
+ $key = $this->service->generateRandomKey();
+
+ $this->service->encryptFile($sourcePath, $encryptedPath, $key);
+
+ expect(file_exists($encryptedPath))->toBeTrue();
+ expect(file_get_contents($encryptedPath))->not->toBe($content);
+
+ $decrypted = $this->service->decryptFile($encryptedPath, $key);
+
+ expect($decrypted)->toBe($content);
+});
+
+test('decrypt with wrong key fails', function () {
+ $sourcePath = $this->tempDir.'/source.txt';
+ $encryptedPath = $this->tempDir.'/encrypted.enc';
+
+ file_put_contents($sourcePath, 'Secret data');
+
+ $correctKey = $this->service->generateRandomKey();
+ $wrongKey = $this->service->generateRandomKey();
+
+ $this->service->encryptFile($sourcePath, $encryptedPath, $correctKey);
+
+ $this->service->decryptFile($encryptedPath, $wrongKey);
+})->throws(RuntimeException::class, 'Decryption failed');
+
+test('derive key produces consistent results', function () {
+ $password = 'my-secure-password';
+ $salt = $this->service->generateSalt();
+
+ $key1 = $this->service->deriveKey($password, $salt);
+ $key2 = $this->service->deriveKey($password, $salt);
+
+ expect($key1)->toBe($key2);
+});
+
+test('derive key with different passwords produces different keys', function () {
+ $salt = $this->service->generateSalt();
+
+ $key1 = $this->service->deriveKey('password1', $salt);
+ $key2 = $this->service->deriveKey('password2', $salt);
+
+ expect($key1)->not->toBe($key2);
+});
+
+test('derive key with different salts produces different keys', function () {
+ $password = 'same-password';
+
+ $key1 = $this->service->deriveKey($password, $this->service->generateSalt());
+ $key2 = $this->service->deriveKey($password, $this->service->generateSalt());
+
+ expect($key1)->not->toBe($key2);
+});
+
+test('generate random key returns 64 char hex string', function () {
+ $key = $this->service->generateRandomKey();
+
+ expect(strlen($key))->toBe(64);
+ expect(ctype_xdigit($key))->toBeTrue();
+});
+
+test('generate salt returns 64 char hex string', function () {
+ $salt = $this->service->generateSalt();
+
+ expect(strlen($salt))->toBe(64);
+ expect(ctype_xdigit($salt))->toBeTrue();
+});
+
+test('password-derived key encrypt/decrypt round-trip works', function () {
+ $sourcePath = $this->tempDir.'/source.txt';
+ $encryptedPath = $this->tempDir.'/encrypted.enc';
+ $content = 'Password protected content';
+
+ file_put_contents($sourcePath, $content);
+
+ $password = 'user-password';
+ $salt = $this->service->generateSalt();
+ $key = bin2hex($this->service->deriveKey($password, $salt));
+
+ $this->service->encryptFile($sourcePath, $encryptedPath, $key);
+ $decrypted = $this->service->decryptFile($encryptedPath, $key);
+
+ expect($decrypted)->toBe($content);
+});
+
+test('decrypt file stream returns streamed response', function () {
+ $sourcePath = $this->tempDir.'/source.txt';
+ $encryptedPath = $this->tempDir.'/encrypted.enc';
+ $content = 'Streamed content';
+
+ file_put_contents($sourcePath, $content);
+
+ $key = $this->service->generateRandomKey();
+ $this->service->encryptFile($sourcePath, $encryptedPath, $key);
+
+ $response = $this->service->decryptFileStream($encryptedPath, $key, 'test.txt', 'text/plain');
+
+ expect($response)->toBeInstanceOf(Symfony\Component\HttpFoundation\StreamedResponse::class);
+ expect($response->headers->get('Content-Type'))->toBe('text/plain');
+ expect($response->headers->get('Content-Disposition'))->toContain('test.txt');
+});
+
+test('chunked file has SEALCHK1 magic header', function () {
+ $sourcePath = $this->tempDir.'/source.txt';
+ $encryptedPath = $this->tempDir.'/encrypted.enc';
+
+ file_put_contents($sourcePath, 'test content');
+
+ $key = $this->service->generateRandomKey();
+ $this->service->encryptFile($sourcePath, $encryptedPath, $key);
+
+ $header = file_get_contents($encryptedPath, false, null, 0, 8);
+
+ expect($header)->toBe('SEALCHK1');
+});
+
+test('multi-chunk round-trip works', function () {
+ $sourcePath = $this->tempDir.'/large.bin';
+ $encryptedPath = $this->tempDir.'/large.enc';
+
+ // Create a file larger than one 4 MB chunk (5 MB)
+ $chunkSize = 4 * 1024 * 1024;
+ $content = random_bytes($chunkSize + (1024 * 1024));
+
+ file_put_contents($sourcePath, $content);
+
+ $key = $this->service->generateRandomKey();
+ $this->service->encryptFile($sourcePath, $encryptedPath, $key);
+ $decrypted = $this->service->decryptFile($encryptedPath, $key);
+
+ expect($decrypted)->toBe($content);
+});
+
+test('exact chunk boundary round-trip works', function () {
+ $sourcePath = $this->tempDir.'/exact.bin';
+ $encryptedPath = $this->tempDir.'/exact.enc';
+
+ // Create a file exactly equal to one chunk (4 MB)
+ $content = random_bytes(4 * 1024 * 1024);
+
+ file_put_contents($sourcePath, $content);
+
+ $key = $this->service->generateRandomKey();
+ $this->service->encryptFile($sourcePath, $encryptedPath, $key);
+ $decrypted = $this->service->decryptFile($encryptedPath, $key);
+
+ expect($decrypted)->toBe($content);
+});
+
+test('empty file round-trip works', function () {
+ $sourcePath = $this->tempDir.'/empty.bin';
+ $encryptedPath = $this->tempDir.'/empty.enc';
+
+ file_put_contents($sourcePath, '');
+
+ $key = $this->service->generateRandomKey();
+ $this->service->encryptFile($sourcePath, $encryptedPath, $key);
+ $decrypted = $this->service->decryptFile($encryptedPath, $key);
+
+ expect($decrypted)->toBe('');
+});
+
+test('legacy format backward compatibility', function () {
+ $sourcePath = $this->tempDir.'/source.txt';
+ $encryptedPath = $this->tempDir.'/legacy.enc';
+ $content = 'Legacy encrypted content';
+
+ file_put_contents($sourcePath, $content);
+
+ $key = $this->service->generateRandomKey();
+ $binaryKey = hex2bin($key);
+
+ // Manually create a legacy format file: [nonce][tag][ciphertext]
+ $nonce = random_bytes(12);
+ $tag = '';
+ $ciphertext = openssl_encrypt($content, 'aes-256-gcm', $binaryKey, OPENSSL_RAW_DATA, $nonce, $tag, '', 16);
+ file_put_contents($encryptedPath, $nonce.$tag.$ciphertext);
+
+ $decrypted = $this->service->decryptFile($encryptedPath, $key);
+
+ expect($decrypted)->toBe($content);
+});
+
+test('wrong key on chunked file throws exception', function () {
+ $sourcePath = $this->tempDir.'/source.txt';
+ $encryptedPath = $this->tempDir.'/encrypted.enc';
+
+ file_put_contents($sourcePath, 'Chunked secret data');
+
+ $correctKey = $this->service->generateRandomKey();
+ $wrongKey = $this->service->generateRandomKey();
+
+ $this->service->encryptFile($sourcePath, $encryptedPath, $correctKey);
+
+ $this->service->decryptFile($encryptedPath, $wrongKey);
+})->throws(RuntimeException::class, 'Decryption failed');
+
+test('decryptFileToCallback returns working stream resource', function () {
+ $sourcePath = $this->tempDir.'/source.txt';
+ $encryptedPath = $this->tempDir.'/encrypted.enc';
+ $content = 'Callback decrypted content';
+
+ file_put_contents($sourcePath, $content);
+
+ $key = $this->service->generateRandomKey();
+ $this->service->encryptFile($sourcePath, $encryptedPath, $key);
+
+ $callback = $this->service->decryptFileToCallback($encryptedPath, $key);
+ $resource = $callback();
+
+ expect(is_resource($resource))->toBeTrue();
+
+ $decrypted = stream_get_contents($resource);
+ fclose($resource);
+
+ expect($decrypted)->toBe($content);
+});
+
+test('decrypt file stream with file size sets content-length header', function () {
+ $sourcePath = $this->tempDir.'/source.txt';
+ $encryptedPath = $this->tempDir.'/encrypted.enc';
+ $content = 'Content with known size';
+
+ file_put_contents($sourcePath, $content);
+
+ $key = $this->service->generateRandomKey();
+ $this->service->encryptFile($sourcePath, $encryptedPath, $key);
+
+ $response = $this->service->decryptFileStream($encryptedPath, $key, 'test.txt', 'text/plain', strlen($content));
+
+ expect($response->headers->get('Content-Length'))->toBe((string) strlen($content));
+});
diff --git a/tests/Unit/ShareServiceTest.php b/tests/Unit/ShareServiceTest.php
new file mode 100644
index 0000000..28b0907
--- /dev/null
+++ b/tests/Unit/ShareServiceTest.php
@@ -0,0 +1,186 @@
+extend(Tests\TestCase::class)
+ ->use(Illuminate\Foundation\Testing\RefreshDatabase::class);
+
+beforeEach(function () {
+ Storage::fake('shares');
+ $this->service = app(ShareService::class);
+});
+
+test('create share without password stores encryption key', function () {
+ $file = UploadedFile::fake()->create('document.pdf', 1024);
+
+ $share = $this->service->createShare([
+ ['file' => $file, 'relativePath' => null],
+ ]);
+
+ expect($share)->toBeInstanceOf(Share::class);
+ expect($share->token)->toHaveLength(16);
+ expect($share->password)->toBeNull();
+ expect($share->encryption_key)->not->toBeNull();
+ expect($share->encryption_salt)->not->toBeNull();
+ expect($share->files)->toHaveCount(1);
+ expect($share->files->first()->original_name)->toBe('document.pdf');
+});
+
+test('create share with password does not store encryption key', function () {
+ $file = UploadedFile::fake()->create('secret.txt', 512);
+
+ $share = $this->service->createShare([
+ ['file' => $file, 'relativePath' => null],
+ ], [
+ 'password' => 'my-password',
+ ]);
+
+ expect($share->password)->not->toBeNull();
+ expect($share->encryption_key)->toBeNull();
+ expect(\Illuminate\Support\Facades\Hash::check('my-password', $share->password))->toBeTrue();
+});
+
+test('create share with options sets expiration and max downloads', function () {
+ $file = UploadedFile::fake()->create('file.txt', 256);
+
+ $share = $this->service->createShare([
+ ['file' => $file, 'relativePath' => null],
+ ], [
+ 'expires_at' => now()->addDay(),
+ 'max_downloads' => 5,
+ ]);
+
+ expect($share->expires_at)->not->toBeNull();
+ expect($share->max_downloads)->toBe(5);
+});
+
+test('create share with multiple files', function () {
+ $file1 = UploadedFile::fake()->create('file1.txt', 100);
+ $file2 = UploadedFile::fake()->create('file2.txt', 200);
+
+ $share = $this->service->createShare([
+ ['file' => $file1, 'relativePath' => 'folder/file1.txt'],
+ ['file' => $file2, 'relativePath' => 'folder/file2.txt'],
+ ]);
+
+ expect($share->files)->toHaveCount(2);
+ expect($share->files->first()->relative_path)->toBe('folder/file1.txt');
+});
+
+test('delete share removes files and database records', function () {
+ $file = UploadedFile::fake()->create('file.txt', 100);
+
+ $share = $this->service->createShare([
+ ['file' => $file, 'relativePath' => null],
+ ]);
+
+ $shareId = $share->id;
+ $token = $share->token;
+
+ $this->service->deleteShare($share);
+
+ expect(Share::query()->find($shareId))->toBeNull();
+ expect(ShareFile::query()->where('share_id', $shareId)->count())->toBe(0);
+ expect(Storage::disk('shares')->directories())->not->toContain($token);
+});
+
+test('verify password returns true for correct password', function () {
+ $file = UploadedFile::fake()->create('file.txt', 100);
+
+ $share = $this->service->createShare([
+ ['file' => $file, 'relativePath' => null],
+ ], [
+ 'password' => 'correct-password',
+ ]);
+
+ expect($this->service->verifyPassword($share, 'correct-password'))->toBeTrue();
+ expect($this->service->verifyPassword($share, 'wrong-password'))->toBeFalse();
+});
+
+test('verify password returns true for non-password share', function () {
+ $file = UploadedFile::fake()->create('file.txt', 100);
+
+ $share = $this->service->createShare([
+ ['file' => $file, 'relativePath' => null],
+ ]);
+
+ expect($this->service->verifyPassword($share, 'any'))->toBeTrue();
+});
+
+test('record download increments counter', function () {
+ $share = Share::factory()->create(['download_count' => 0]);
+
+ $this->service->recordDownload($share);
+
+ expect($share->fresh()->download_count)->toBe(1);
+});
+
+test('record download auto-deletes when limit reached', function () {
+ $share = Share::factory()->withMaxDownloads(1)->create(['download_count' => 0]);
+
+ $this->service->recordDownload($share);
+
+ expect(Share::query()->find($share->id))->toBeNull();
+});
+
+test('get total used space sums share sizes', function () {
+ Share::factory()->create(['total_size' => 1000]);
+ Share::factory()->create(['total_size' => 2000]);
+
+ expect($this->service->getTotalUsedSpace())->toBe(3000);
+});
+
+test('is storage full checks against quota', function () {
+ Setting::set('max_storage_quota', 1000);
+
+ Share::factory()->create(['total_size' => 999]);
+ expect($this->service->isStorageFull())->toBeFalse();
+
+ Share::factory()->create(['total_size' => 1]);
+ expect($this->service->isStorageFull())->toBeTrue();
+});
+
+test('get decryption key returns stored key for non-password share', function () {
+ $file = UploadedFile::fake()->create('file.txt', 100);
+
+ $share = $this->service->createShare([
+ ['file' => $file, 'relativePath' => null],
+ ]);
+
+ $key = $this->service->getDecryptionKey($share);
+
+ expect($key)->not->toBeNull();
+ expect(strlen($key))->toBe(64);
+});
+
+test('get decryption key derives key for password share', function () {
+ $file = UploadedFile::fake()->create('file.txt', 100);
+
+ $share = $this->service->createShare([
+ ['file' => $file, 'relativePath' => null],
+ ], [
+ 'password' => 'test-password',
+ ]);
+
+ $key = $this->service->getDecryptionKey($share, 'test-password');
+
+ expect($key)->not->toBeNull();
+ expect(strlen($key))->toBe(64);
+});
+
+test('get decryption key throws for password share without password', function () {
+ $file = UploadedFile::fake()->create('file.txt', 100);
+
+ $share = $this->service->createShare([
+ ['file' => $file, 'relativePath' => null],
+ ], [
+ 'password' => 'test-password',
+ ]);
+
+ $this->service->getDecryptionKey($share);
+})->throws(RuntimeException::class, 'Password required');
diff --git a/vite.config.js b/vite.config.js
index f65249e..f741746 100644
--- a/vite.config.js
+++ b/vite.config.js
@@ -13,7 +13,12 @@ export default defineConfig({
tailwindcss(),
],
server: {
+ host: '0.0.0.0',
+ port: 5173,
cors: true,
+ hmr: {
+ host: 'localhost',
+ },
watch: {
ignored: ['**/storage/framework/views/**'],
},