63 lines
2.2 KiB
PHP
63 lines
2.2 KiB
PHP
<?php
|
|
|
|
use App\Livewire\Admin\Settings;
|
|
use App\Models\Operator;
|
|
use App\Support\Settings as AppSettings;
|
|
use Livewire\Livewire;
|
|
|
|
it('is voluntary by default', function () {
|
|
expect(AppSettings::bool('console.require_2fa', false))->toBeFalse();
|
|
|
|
$operator = Operator::factory()->role('Owner')->create();
|
|
|
|
$this->actingAs($operator, 'operator')->get(route('admin.overview'))->assertOk();
|
|
});
|
|
|
|
it('sends an operator without two-factor to the setup page once the switch is on', function () {
|
|
AppSettings::set('console.require_2fa', true);
|
|
|
|
$operator = Operator::factory()->role('Owner')->create();
|
|
|
|
$this->actingAs($operator, 'operator')
|
|
->get(route('admin.overview'))
|
|
->assertRedirect(route('admin.settings'));
|
|
});
|
|
|
|
it('lets an operator with confirmed two-factor through', function () {
|
|
AppSettings::set('console.require_2fa', true);
|
|
|
|
$operator = Operator::factory()->role('Owner')->create([
|
|
'two_factor_secret' => encrypt('JBSWY3DPEHPK3PXP'),
|
|
'two_factor_confirmed_at' => now(),
|
|
]);
|
|
|
|
$this->actingAs($operator, 'operator')->get(route('admin.overview'))->assertOk();
|
|
});
|
|
|
|
it('refuses to switch it on while your own account has no two-factor', function () {
|
|
// The lock-out this exists to prevent: the page that would turn it back off
|
|
// sits behind the switch. Same shape as console.allowed_ips.
|
|
$operator = Operator::factory()->role('Owner')->create();
|
|
|
|
Livewire::actingAs($operator, 'operator')->test(Settings::class)
|
|
->set('requireTwoFactor', true)
|
|
->call('saveTwoFactorPolicy')
|
|
->assertHasErrors('requireTwoFactor');
|
|
|
|
expect(AppSettings::bool('console.require_2fa', false))->toBeFalse();
|
|
});
|
|
|
|
it('allows it once your own two-factor is confirmed', function () {
|
|
$operator = Operator::factory()->role('Owner')->create([
|
|
'two_factor_secret' => encrypt('JBSWY3DPEHPK3PXP'),
|
|
'two_factor_confirmed_at' => now(),
|
|
]);
|
|
|
|
Livewire::actingAs($operator, 'operator')->test(Settings::class)
|
|
->set('requireTwoFactor', true)
|
|
->call('saveTwoFactorPolicy')
|
|
->assertHasNoErrors();
|
|
|
|
expect(AppSettings::bool('console.require_2fa', false))->toBeTrue();
|
|
});
|