-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding two factor auth tests and more
- Loading branch information
Showing
13 changed files
with
138 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
#auth-body{ | ||
opacity:80; | ||
} | ||
|
||
#auth-container{ | ||
border:0px !important; | ||
} | ||
|
||
#auth-heading-container{ | ||
padding-left:5px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
resources/views/includes/volt-page-dynamic-middleware-name.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Devdojo\Auth\Http\Middleware; | ||
|
||
use Closure; | ||
use Illuminate\Http\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class TwoFactorEnabled | ||
{ | ||
/** | ||
* Handle an incoming request. | ||
* | ||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next | ||
*/ | ||
public function handle(Request $request, Closure $next): Response | ||
{ | ||
if (!config('devdojo.auth.settings.enable_2fa')) { | ||
return redirect('/'); | ||
} | ||
return $next($request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
use App\Models\User; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\Hash; | ||
use Illuminate\Support\Facades\Session; | ||
|
||
beforeEach(function () { | ||
// Ensure each test starts with a clean slate | ||
|
@@ -19,41 +20,58 @@ | |
->assertRedirect('auth/login'); | ||
}); | ||
|
||
test('when user logs in and two factor auth is active, they will have the login.id session created', function(){ | ||
$user = User::factory()->create(['name' => 'Homer Simpson', 'email' => '[email protected]', 'password' => \Hash::make('DuffBeer123')]); | ||
// $this->get('auth/login') | ||
// ->seeInField('email', '[email protected]') | ||
// ->click('.auth-component-button') | ||
// ->assertSee('Password'); | ||
// dd($user->two_factor_secret); | ||
//dd(\Schema::getColumnListing('users')); | ||
//dd(env('DB_CONNECTION')); | ||
//dd($user); | ||
})->todo(); | ||
|
||
it('user can view two factor challenge page after they login', function(){ | ||
|
||
// Livewire::test('auth.register') | ||
// ->set('email', '[email protected]') | ||
// ->set('password', 'secret1234') | ||
// ->set('name', 'John Doe') | ||
// ->call('register') | ||
|
||
withANewUser()->get('auth/two-factor-challenge')->asertOK(); | ||
// $user = loginAsUser(null); | ||
// Livewire::test('auth.two-factor-challenge'); | ||
// ->assertSee('When you enabled 2FA'); | ||
})->todo(); | ||
|
||
test('when authenticated, user can view /user/two-factor-authentication page', function(){ | ||
|
||
test('User logs in when two factor disabled, the login.id session should not be created', function(){ | ||
$user = createUser(['password' => \Hash::make('password123'), 'two_factor_confirmed_at' => now()]); | ||
|
||
})->todo(); | ||
Livewire::test('auth.login') | ||
->set('email', $user->email) | ||
->set('showPasswordField', true) | ||
->set('password', 'password123') | ||
->call('authenticate') | ||
->assertHasNoErrors() | ||
->assertRedirect('/'); | ||
|
||
$this->assertTrue(!Session::has('login.id')); | ||
}); | ||
|
||
test('when authenticated, user can view /user/two-factor-authentication page and they can click enable and add auth code', function(){ | ||
test('User logs in when two factor enabled, the login.id session should be created', function(){ | ||
config()->set('devdojo.auth.settings.enable_2fa', true); | ||
$user = createUser(['password' => \Hash::make('password123'), 'two_factor_confirmed_at' => now()]); | ||
|
||
})->todo(); | ||
Livewire::test('auth.login') | ||
->set('email', $user->email) | ||
->set('showPasswordField', true) | ||
->set('password', 'password123') | ||
->call('authenticate') | ||
->assertHasNoErrors() | ||
->assertRedirect('auth/two-factor-challenge'); | ||
|
||
$this->assertTrue(Session::has('login.id')); | ||
}); | ||
|
||
// scenarios when 2FA is disabled by application admin | ||
test('if two factor auth is disabled, user can login with name and password and they will not be redirected to 2fa page, even if they have the correct two_factor table columns filled', function(){ | ||
test('User logs in without 2FA, they should not be redirected to auth/two-factor-challenge page', function(){ | ||
config()->set('devdojo.auth.settings.enable_2fa', true); | ||
$user = createUser(['password' => \Hash::make('password123')]); | ||
|
||
})->todo(); | ||
Livewire::test('auth.login') | ||
->set('email', $user->email) | ||
->set('showPasswordField', true) | ||
->set('password', 'password123') | ||
->call('authenticate') | ||
->assertHasNoErrors() | ||
->assertRedirect('/'); | ||
}); | ||
|
||
it('user cannot view two factor challenge page logging in if it\'s disabled', function(){ | ||
$user = loginAsUser(); | ||
$this->get('user/two-factor-authentication') | ||
->assertRedirect('/'); | ||
}); | ||
|
||
it('user can view two factor challenge page when it\'s enabled', function(){ | ||
config()->set('devdojo.auth.settings.enable_2fa', true); | ||
$user = loginAsUser(); | ||
$this->get('user/two-factor-authentication') | ||
->assertOk(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters