|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Illuminate\Tests\Integration\Auth; |
| 4 | + |
| 5 | +use Illuminate\Foundation\Testing\RefreshDatabase; |
| 6 | +use Illuminate\Http\Request; |
| 7 | +use Orchestra\Testbench\Attributes\WithConfig; |
| 8 | +use Orchestra\Testbench\Attributes\WithMigration; |
| 9 | +use Orchestra\Testbench\Factories\UserFactory; |
| 10 | +use Orchestra\Testbench\TestCase; |
| 11 | + |
| 12 | +#[WithMigration] |
| 13 | +#[WithEnv('BCRYPT_ROUNDS', 12)] |
| 14 | +#[WithConfig('app.key', 'base64:IUHRqAQ99pZ0A1MPjbuv1D6ff3jxv0GIvS2qIW4JNU4=')] |
| 15 | +class RehashOnLogoutOtherDevicesTest extends TestCase |
| 16 | +{ |
| 17 | + use RefreshDatabase; |
| 18 | + |
| 19 | + protected function defineRoutes($router) |
| 20 | + { |
| 21 | + $router->post('logout', function (Request $request) { |
| 22 | + auth()->logoutOtherDevices($request->input('password')); |
| 23 | + |
| 24 | + return response()->noContent(); |
| 25 | + })->middleware(['web', 'auth']); |
| 26 | + } |
| 27 | + |
| 28 | + public function testItRehashThePasswordUsingLogoutOtherDevices() |
| 29 | + { |
| 30 | + $this->withoutExceptionHandling(); |
| 31 | + |
| 32 | + $user = UserFactory::new()->create(); |
| 33 | + |
| 34 | + $password = $user->password; |
| 35 | + |
| 36 | + $this->actingAs($user); |
| 37 | + |
| 38 | + $this->post('logout', [ |
| 39 | + 'password' => 'password', |
| 40 | + ])->assertStatus(204); |
| 41 | + |
| 42 | + $user->refresh(); |
| 43 | + |
| 44 | + $this->assertNotSame($password, $user->password); |
| 45 | + } |
| 46 | +} |
0 commit comments