mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Dusk: improve speed and safety (#13370)
* Dusk: improve speed Instead of refreshing the database between tests, just cleanup all side effects. Update UserFactory to upstream so hash never has to be generated for default * Actually, migrate, but not fresh
This commit is contained in:
@@ -22,14 +22,12 @@ class UserFactory extends Factory
|
|||||||
*/
|
*/
|
||||||
public function definition()
|
public function definition()
|
||||||
{
|
{
|
||||||
static $password;
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'auth_type' => 'mysql',
|
'auth_type' => 'mysql',
|
||||||
'username' => $this->faker->unique()->userName,
|
'username' => $this->faker->unique()->userName,
|
||||||
'realname' => $this->faker->name,
|
'realname' => $this->faker->name,
|
||||||
'email' => $this->faker->safeEmail,
|
'email' => $this->faker->safeEmail,
|
||||||
'password' => $password ?: $password = bcrypt('secret'),
|
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
|
||||||
'level' => 1,
|
'level' => 1,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@@ -4,7 +4,7 @@ namespace LibreNMS\Tests\Browser;
|
|||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\UserPref;
|
use App\Models\UserPref;
|
||||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
use Hash;
|
||||||
use Laravel\Dusk\Browser;
|
use Laravel\Dusk\Browser;
|
||||||
use LibreNMS\Config;
|
use LibreNMS\Config;
|
||||||
use LibreNMS\Tests\Browser\Pages\LoginPage;
|
use LibreNMS\Tests\Browser\Pages\LoginPage;
|
||||||
@@ -18,7 +18,11 @@ use LibreNMS\Tests\DuskTestCase;
|
|||||||
*/
|
*/
|
||||||
class LoginTest extends DuskTestCase
|
class LoginTest extends DuskTestCase
|
||||||
{
|
{
|
||||||
use DatabaseMigrations;
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
$this->artisan('migrate');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws \Throwable
|
* @throws \Throwable
|
||||||
@@ -28,8 +32,7 @@ class LoginTest extends DuskTestCase
|
|||||||
$this->browse(function (Browser $browser) {
|
$this->browse(function (Browser $browser) {
|
||||||
$password = 'some_password';
|
$password = 'some_password';
|
||||||
$user = User::factory()->create([
|
$user = User::factory()->create([
|
||||||
/** @phpstan-ignore-next-line */
|
'password' => Hash::make($password),
|
||||||
'password' => password_hash($password, PASSWORD_DEFAULT),
|
|
||||||
]); /** @var User $user */
|
]); /** @var User $user */
|
||||||
$browser->visit(new LoginPage())
|
$browser->visit(new LoginPage())
|
||||||
->type('username', $user->username)
|
->type('username', $user->username)
|
||||||
@@ -54,8 +57,7 @@ class LoginTest extends DuskTestCase
|
|||||||
$this->browse(function (Browser $browser) {
|
$this->browse(function (Browser $browser) {
|
||||||
$password = 'another_password';
|
$password = 'another_password';
|
||||||
$user = User::factory()->create([
|
$user = User::factory()->create([
|
||||||
/** @phpstan-ignore-next-line */
|
'password' => Hash::make($password),
|
||||||
'password' => password_hash($password, PASSWORD_DEFAULT),
|
|
||||||
]); /** @var User $user */
|
]); /** @var User $user */
|
||||||
Config::persist('twofactor', true); // set to db
|
Config::persist('twofactor', true); // set to db
|
||||||
UserPref::setPref($user, 'twofactor', [
|
UserPref::setPref($user, 'twofactor', [
|
||||||
@@ -78,6 +80,7 @@ class LoginTest extends DuskTestCase
|
|||||||
->logout();
|
->logout();
|
||||||
|
|
||||||
$user->delete();
|
$user->delete();
|
||||||
|
\App\Models\Config::where('config_name', 'twofactor')->delete();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user