mirror of
https://github.com/librenms/librenms.git
synced 2024-09-22 02:48:37 +00:00
6e6e54cb98
* Rewrite user management. Error management Revert edituser legacy page Connect user permissions button to legacy page for now. Implement user creation Refine form Remove PingCheck.php accidental add :) Fixes for redirection and deletion More fixes: realname accidental validation setting, hide can modify for read-only auths Use a panel to improve style Add icon to panel-title Not allowed to delete own user (at least via the click of a button) Use request validation to reduce complexity of controller. Improve protection against users doing things they should not. Switch to horizontal form and not nearly as wide of layout :) delete without refresh. Fix for buttons Include all users (not just from this auth) Hide the auth column if there is only one auth type Show username if real name isn't set Don't allow creation of demo users via the webui a fix to the lnms user:add command, it didn't set auth_id update edituser.inc.php to current just redirect to users page * Remove TwoFactorTest for now * Update edituser.inc.php * Update .env.dusk.testing * Enable 2fa for 2fa test...
83 lines
2.4 KiB
PHP
83 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace LibreNMS\Tests\Browser;
|
|
|
|
use App\Models\User;
|
|
use App\Models\UserPref;
|
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
|
use Laravel\Dusk\Browser;
|
|
use LibreNMS\Config;
|
|
use LibreNMS\Tests\Browser\Pages\LoginPage;
|
|
use LibreNMS\Tests\Browser\Pages\TwoFactorPage;
|
|
use LibreNMS\Tests\DuskTestCase;
|
|
|
|
/**
|
|
* Class LoginTest
|
|
* @package LibreNMS\Tests\Browser
|
|
* @group browser
|
|
*/
|
|
class LoginTest extends DuskTestCase
|
|
{
|
|
use DatabaseMigrations;
|
|
|
|
/**
|
|
* @throws \Throwable
|
|
*/
|
|
public function testUserCanLogin()
|
|
{
|
|
$this->browse(function (Browser $browser) {
|
|
$password = 'some_password';
|
|
$user = factory(User::class)->create([
|
|
'password' => password_hash($password, PASSWORD_DEFAULT)
|
|
]);
|
|
|
|
$browser->visit(new LoginPage())
|
|
->type('username', $user->username)
|
|
->type('password', 'wrong_password')
|
|
->press('@login')
|
|
->assertPathIs('/login')
|
|
->type('username', $user->username)
|
|
->type('password', $password)
|
|
->press('@login')
|
|
->assertPathIs('/')
|
|
->logout();
|
|
|
|
$user->delete();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @throws \Throwable
|
|
*/
|
|
public function test2faLogin()
|
|
{
|
|
$this->browse(function (Browser $browser) {
|
|
$password = 'another_password';
|
|
$user = factory(User::class)->create([
|
|
'password' => password_hash($password, PASSWORD_DEFAULT)
|
|
]);
|
|
Config::set('twofactor', true, true); // set to db
|
|
UserPref::setPref($user, 'twofactor', [
|
|
'key' => '5P3FLXBX7NU3ZBFOTWZL2GL5MKFEWBOA', // known key: 634456, 613687, 064292
|
|
'fails' => 0,
|
|
'last' => 0,
|
|
'counter' => 1,
|
|
]);
|
|
|
|
$browser->visit(new LoginPage())
|
|
->type('username', $user->username)
|
|
->type('password', $password)
|
|
->press('#login')
|
|
->on(new TwoFactorPage())
|
|
->assertFocused('@input')
|
|
->keys('@input', '999999', '{enter}') // try the wrong code first
|
|
->assertPathIs('/2fa')
|
|
->keys('@input', '634456', '{enter}')
|
|
->assertPathIs('/')
|
|
->logout();
|
|
|
|
$user->delete();
|
|
});
|
|
}
|
|
}
|