Skip to content

Commit

Permalink
[10.x] Test Improvements (#50763)
Browse files Browse the repository at this point in the history
Add tests to verify using `auth()->logoutOtherDevices()` will rehash the
password.

Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone authored Mar 26, 2024
1 parent cfedb23 commit 772b861
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/Integration/Auth/RehashOnLogoutOtherDevicesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Illuminate\Tests\Integration\Auth;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\Request;
use Orchestra\Testbench\Attributes\WithConfig;
use Orchestra\Testbench\Attributes\WithMigration;
use Orchestra\Testbench\Factories\UserFactory;
use Orchestra\Testbench\TestCase;

#[WithMigration]
#[WithEnv('BCRYPT_ROUNDS', 12)]
#[WithConfig('app.key', 'base64:IUHRqAQ99pZ0A1MPjbuv1D6ff3jxv0GIvS2qIW4JNU4=')]
class RehashOnLogoutOtherDevicesTest extends TestCase
{
use RefreshDatabase;

protected function defineRoutes($router)
{
$router->post('logout', function (Request $request) {
auth()->logoutOtherDevices($request->input('password'));

return response()->noContent();
})->middleware(['web', 'auth']);
}

public function testItRehashThePasswordUsingLogoutOtherDevices()
{
$this->withoutExceptionHandling();

$user = UserFactory::new()->create();

$password = $user->password;

$this->actingAs($user);

$this->post('logout', [
'password' => 'password',
])->assertStatus(204);

$user->refresh();

$this->assertNotSame($password, $user->password);
}
}

0 comments on commit 772b861

Please sign in to comment.