-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1.x] Ensure logout route is authenticated (#536)
* Ensure logout route is authenticated * Formatting * Remove unused user
- Loading branch information
1 parent
9da961e
commit a725684
Showing
2 changed files
with
29 additions
and
0 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
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
namespace Laravel\Fortify\Tests; | ||
|
||
use Illuminate\Auth\Events\Logout; | ||
use Illuminate\Cache\RateLimiter; | ||
use Illuminate\Contracts\Auth\Authenticatable; | ||
use Illuminate\Foundation\Auth\User; | ||
|
@@ -404,6 +405,33 @@ public function test_case_insensitive_usernames_can_be_used() | |
$response->assertRedirect('/home'); | ||
} | ||
|
||
public function test_users_can_logout(): void | ||
{ | ||
$user = TestAuthenticationSessionUser::forceCreate([ | ||
'name' => 'Taylor Otwell', | ||
'email' => '[email protected]', | ||
'password' => bcrypt('secret'), | ||
]); | ||
Event::fake([Logout::class]); | ||
|
||
$response = $this->actingAs($user)->post('/logout'); | ||
|
||
$response->assertRedirect(); | ||
$this->assertGuest(); | ||
Event::assertDispatched(fn (Logout $logout) => $logout->user->is($user)); | ||
} | ||
|
||
public function test_must_be_authenticated_to_logout(): void | ||
{ | ||
Event::fake([Logout::class]); | ||
|
||
$response = $this->post('/logout'); | ||
|
||
$response->assertRedirect(); | ||
$this->assertGuest(); | ||
Event::assertNotDispatched(Logout::class); | ||
} | ||
|
||
protected function defineEnvironment($app) | ||
{ | ||
parent::defineEnvironment($app); | ||
|