mirror of
https://github.com/projectsend/projectsend.git
synced 2026-09-17 17:15:08 +00:00
6e47d76ba6
Client file sharing, rebuilt from the ground up: a private area per client, resumable uploads, folders, groups and categories, sharing with expiry dates and download limits, comments, file versions, an activity log, a REST API, and sixteen languages. This repository begins here. ProjectSend 2 was developed privately, and that development history is not published — the previous generation remains available, with its own history, at projectsend/legacy. Free software under the GNU General Public License v2, or (at your option) any later version.
105 lines
3.5 KiB
PHP
105 lines
3.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\User;
|
|
use App\Modules\Platform\Settings\Setting;
|
|
use App\Modules\Platform\Settings\Settings;
|
|
use Inertia\Testing\AssertableInertia;
|
|
|
|
test('by default nobody is forced into two-factor setup', function () {
|
|
$this->actingAs(User::factory()->create());
|
|
|
|
$this->get('/dashboard')->assertOk();
|
|
});
|
|
|
|
test('staff enforcement walks un-enrolled staff to the 2fa setup screen', function () {
|
|
app(Settings::class)->set(Setting::TwoFactorEnforcement, 'staff');
|
|
|
|
$this->actingAs(User::factory()->create());
|
|
|
|
$this->get('/dashboard')->assertRedirect(route('two-factor.show'));
|
|
});
|
|
|
|
test('staff enforcement leaves clients alone', function () {
|
|
User::factory()->create();
|
|
app(Settings::class)->set(Setting::TwoFactorEnforcement, 'staff');
|
|
|
|
$this->actingAs(User::factory()->client()->create());
|
|
|
|
$this->get('/dashboard')->assertOk();
|
|
});
|
|
|
|
test('client enforcement walks un-enrolled clients to the 2fa setup screen', function () {
|
|
User::factory()->create();
|
|
app(Settings::class)->set(Setting::TwoFactorEnforcement, 'clients');
|
|
|
|
$this->actingAs(User::factory()->client()->create());
|
|
|
|
$this->get('/dashboard')->assertRedirect(route('two-factor.show'));
|
|
});
|
|
|
|
test('everyone enforcement covers both types', function () {
|
|
app(Settings::class)->set(Setting::TwoFactorEnforcement, 'all');
|
|
|
|
$this->actingAs(User::factory()->create());
|
|
$this->get('/dashboard')->assertRedirect(route('two-factor.show'));
|
|
|
|
$this->actingAs(User::factory()->client()->create());
|
|
$this->get('/dashboard')->assertRedirect(route('two-factor.show'));
|
|
});
|
|
|
|
test('the 2fa setup screen itself and logout stay reachable under enforcement', function () {
|
|
app(Settings::class)->set(Setting::TwoFactorEnforcement, 'all');
|
|
|
|
$this->actingAs(User::factory()->create());
|
|
|
|
$this->get('/settings/two-factor')->assertOk();
|
|
$this->post('/settings/two-factor')->assertRedirect();
|
|
$this->post('/logout')->assertRedirect('/');
|
|
});
|
|
|
|
test('enrolled users are not redirected under enforcement', function () {
|
|
app(Settings::class)->set(Setting::TwoFactorEnforcement, 'all');
|
|
|
|
$user = User::factory()->create(['two_factor_confirmed_at' => now()]);
|
|
|
|
$this->actingAs($user);
|
|
|
|
$this->get('/dashboard')->assertOk();
|
|
});
|
|
|
|
test('staff can change the enforcement setting', function () {
|
|
$this->actingAs(User::factory()->create());
|
|
|
|
$this->get('/system/settings/security')->assertInertia(
|
|
fn (AssertableInertia $page) => $page
|
|
->component('system/settings/security')
|
|
->where('two_factor_enforcement', 'none'),
|
|
);
|
|
|
|
$this->patch('/system/settings/security', [
|
|
'two_factor_enforcement' => 'clients',
|
|
'password_min_length' => 12,
|
|
'password_reject_breached' => true,
|
|
])->assertRedirect();
|
|
|
|
expect(app(Settings::class)->get(Setting::TwoFactorEnforcement))->toBe('clients');
|
|
});
|
|
|
|
test('an invalid enforcement value is rejected', function () {
|
|
$this->actingAs(User::factory()->create());
|
|
|
|
$this->patch('/system/settings/security', ['two_factor_enforcement' => 'sometimes'])
|
|
->assertSessionHasErrors('two_factor_enforcement');
|
|
});
|
|
|
|
test('clients cannot access security settings', function () {
|
|
User::factory()->create();
|
|
|
|
$this->actingAs(User::factory()->client()->create());
|
|
|
|
$this->get('/system/settings/security')->assertRedirect(route('dashboard'));
|
|
$this->patch('/system/settings/security', ['two_factor_enforcement' => 'all'])->assertForbidden();
|
|
});
|