Skip to content

Commit a32ba83

Browse files
authored
[10.x] Test Improvements (#50744)
Add tests to verify using `auth()->logoutOtherDevices()` will rehash the password. Signed-off-by: Mior Muhammad Zaki <[email protected]>
1 parent 8c61f50 commit a32ba83

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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

Comments
 (0)