Skip to content

Skip two factor authentication tests when the feature is disabled #1095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions stubs/pest-tests/inertia/TwoFactorAuthenticationSettingsTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use App\Models\User;
use Laravel\Fortify\Features;

test('two factor authentication can be enabled', function () {
$this->actingAs($user = User::factory()->create());
Expand All @@ -11,7 +12,9 @@

expect($user->fresh()->two_factor_secret)->not->toBeNull();
expect($user->fresh()->recoveryCodes())->toHaveCount(8);
});
})->skip(function () {
return ! Features::canManageTwoFactorAuthentication();
}, 'Two factor authentication is not enabled.');

test('recovery codes can be regenerated', function () {
$this->actingAs($user = User::factory()->create());
Expand All @@ -27,7 +30,9 @@

expect($user->recoveryCodes())->toHaveCount(8);
expect(array_diff($user->recoveryCodes(), $user->fresh()->recoveryCodes()))->toHaveCount(8);
});
})->skip(function () {
return ! Features::canManageTwoFactorAuthentication();
}, 'Two factor authentication is not enabled.');

test('two factor authentication can be disabled', function () {
$this->actingAs($user = User::factory()->create());
Expand All @@ -41,4 +46,6 @@
$this->delete('/user/two-factor-authentication');

expect($user->fresh()->two_factor_secret)->toBeNull();
});
})->skip(function () {
return ! Features::canManageTwoFactorAuthentication();
}, 'Two factor authentication is not enabled.');
13 changes: 10 additions & 3 deletions stubs/pest-tests/livewire/TwoFactorAuthenticationSettingsTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use App\Models\User;
use Laravel\Fortify\Features;
use Laravel\Jetstream\Http\Livewire\TwoFactorAuthenticationForm;
use Livewire\Livewire;

Expand All @@ -16,7 +17,9 @@

expect($user->two_factor_secret)->not->toBeNull();
expect($user->recoveryCodes())->toHaveCount(8);
});
})->skip(function () {
return ! Features::canManageTwoFactorAuthentication();
}, 'Two factor authentication is not enabled.');

test('recovery codes can be regenerated', function () {
$this->actingAs($user = User::factory()->create());
Expand All @@ -33,7 +36,9 @@

expect($user->recoveryCodes())->toHaveCount(8);
expect(array_diff($user->recoveryCodes(), $user->fresh()->recoveryCodes()))->toHaveCount(8);
});
})->skip(function () {
return ! Features::canManageTwoFactorAuthentication();
}, 'Two factor authentication is not enabled.');

test('two factor authentication can be disabled', function () {
$this->actingAs($user = User::factory()->create());
Expand All @@ -48,4 +53,6 @@
$component->call('disableTwoFactorAuthentication');

expect($user->fresh()->two_factor_secret)->toBeNull();
});
})->skip(function () {
return ! Features::canManageTwoFactorAuthentication();
}, 'Two factor authentication is not enabled.');
13 changes: 13 additions & 0 deletions stubs/tests/inertia/TwoFactorAuthenticationSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Fortify\Features;
use Tests\TestCase;

class TwoFactorAuthenticationSettingsTest extends TestCase
Expand All @@ -12,6 +13,10 @@ class TwoFactorAuthenticationSettingsTest extends TestCase

public function test_two_factor_authentication_can_be_enabled()
{
if (! Features::canManageTwoFactorAuthentication()) {
return $this->markTestSkipped('Two factor authentication is not enabled.');
}

$this->actingAs($user = User::factory()->create());

$this->withSession(['auth.password_confirmed_at' => time()]);
Expand All @@ -24,6 +29,10 @@ public function test_two_factor_authentication_can_be_enabled()

public function test_recovery_codes_can_be_regenerated()
{
if (! Features::canManageTwoFactorAuthentication()) {
return $this->markTestSkipped('Two factor authentication is not enabled.');
}

$this->actingAs($user = User::factory()->create());

$this->withSession(['auth.password_confirmed_at' => time()]);
Expand All @@ -41,6 +50,10 @@ public function test_recovery_codes_can_be_regenerated()

public function test_two_factor_authentication_can_be_disabled()
{
if (! Features::canManageTwoFactorAuthentication()) {
return $this->markTestSkipped('Two factor authentication is not enabled.');
}

$this->actingAs($user = User::factory()->create());

$this->withSession(['auth.password_confirmed_at' => time()]);
Expand Down
13 changes: 13 additions & 0 deletions stubs/tests/livewire/TwoFactorAuthenticationSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Fortify\Features;
use Laravel\Jetstream\Http\Livewire\TwoFactorAuthenticationForm;
use Livewire\Livewire;
use Tests\TestCase;
Expand All @@ -14,6 +15,10 @@ class TwoFactorAuthenticationSettingsTest extends TestCase

public function test_two_factor_authentication_can_be_enabled()
{
if (! Features::canManageTwoFactorAuthentication()) {
return $this->markTestSkipped('Two factor authentication is not enabled.');
}

$this->actingAs($user = User::factory()->create());

$this->withSession(['auth.password_confirmed_at' => time()]);
Expand All @@ -29,6 +34,10 @@ public function test_two_factor_authentication_can_be_enabled()

public function test_recovery_codes_can_be_regenerated()
{
if (! Features::canManageTwoFactorAuthentication()) {
return $this->markTestSkipped('Two factor authentication is not enabled.');
}

$this->actingAs($user = User::factory()->create());

$this->withSession(['auth.password_confirmed_at' => time()]);
Expand All @@ -47,6 +56,10 @@ public function test_recovery_codes_can_be_regenerated()

public function test_two_factor_authentication_can_be_disabled()
{
if (! Features::canManageTwoFactorAuthentication()) {
return $this->markTestSkipped('Two factor authentication is not enabled.');
}

$this->actingAs($user = User::factory()->create());

$this->withSession(['auth.password_confirmed_at' => time()]);
Expand Down