First round of authentication tests
This commit is contained in:
parent
b50f314eda
commit
f8fa62e3d6
5 changed files with 136 additions and 6 deletions
|
@ -41,6 +41,7 @@ abstract class BrowserTestCase extends TestCase
|
|||
{
|
||||
$options = (new ChromeOptions)->addArguments([
|
||||
'--disable-gpu',
|
||||
'--disable-infobars',
|
||||
]);
|
||||
|
||||
return RemoteWebDriver::create(
|
||||
|
|
16
tests/Browser/Pages/BasePage.php
Normal file
16
tests/Browser/Pages/BasePage.php
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Tests\Browser\Pages;
|
||||
|
||||
use Laravel\Dusk\Page;
|
||||
|
||||
abstract class BasePage extends Page
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function siteElements()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
24
tests/Browser/Pages/LoginPage.php
Normal file
24
tests/Browser/Pages/LoginPage.php
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Tests\Browser\Pages;
|
||||
|
||||
class LoginPage extends BasePage
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function url(): string
|
||||
{
|
||||
return '/auth/login';
|
||||
}
|
||||
|
||||
public function elements()
|
||||
{
|
||||
return [
|
||||
'@username' => '#grid-username',
|
||||
'@password' => '#grid-password',
|
||||
'@loginButton' => '#grid-login-button',
|
||||
'@forgotPassword' => 'a[aria-label="Forgot password"]',
|
||||
];
|
||||
}
|
||||
}
|
88
tests/Browser/Processes/Authentication/LoginProcessTest.php
Normal file
88
tests/Browser/Processes/Authentication/LoginProcessTest.php
Normal file
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Tests\Browser\Processes\Authentication;
|
||||
|
||||
use Pterodactyl\Models\User;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Facebook\WebDriver\WebDriverKeys;
|
||||
use Pterodactyl\Tests\Browser\BrowserTestCase;
|
||||
use Pterodactyl\Tests\Browser\Pages\LoginPage;
|
||||
use Pterodactyl\Tests\Browser\PterodactylBrowser;
|
||||
|
||||
class LoginProcessTest extends BrowserTestCase
|
||||
{
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* Setup tests.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->user = factory(User::class)->create([
|
||||
'email' => 'test@example.com',
|
||||
'password' => Hash::make('Password123'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a user can login successfully using their email address.
|
||||
*/
|
||||
public function testLoginUsingEmail()
|
||||
{
|
||||
$this->browse(function (PterodactylBrowser $browser) {
|
||||
$browser->visit(new LoginPage)
|
||||
->waitFor('@username')
|
||||
->type('@username', 'test@example.com')
|
||||
->type('@password', 'Password123')
|
||||
->click('@loginButton')
|
||||
->waitForReload()
|
||||
->assertPathIs('/')
|
||||
->assertAuthenticatedAs($this->user);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a user can login successfully using their username.
|
||||
*/
|
||||
public function testLoginUsingUsername()
|
||||
{
|
||||
$this->browse(function (PterodactylBrowser $browser) {
|
||||
$browser->visit(new LoginPage)
|
||||
->waitFor('@username')
|
||||
->type('@username', $this->user->username)
|
||||
->type('@password', 'Password123')
|
||||
->click('@loginButton')
|
||||
->waitForReload()
|
||||
->assertPathIs('/')
|
||||
->assertAuthenticatedAs($this->user);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that entering the wrong password shows the expected error and then allows
|
||||
* us to login without clearing the username field.
|
||||
*/
|
||||
public function testLoginWithErrors()
|
||||
{
|
||||
$this->browse(function (PterodactylBrowser $browser) {
|
||||
$browser->logout()
|
||||
->visit(new LoginPage())
|
||||
->waitFor('@username')
|
||||
->type('@username', 'test@example.com')
|
||||
->type('@password', 'invalid')
|
||||
->click('@loginButton')
|
||||
->waitFor('.alert.error')
|
||||
->assertSeeIn('.alert.error', trans('auth.failed'))
|
||||
->assertValue('@username', 'test@example.com')
|
||||
->assertValue('@password', '')
|
||||
->assertFocused('@password')
|
||||
->type('@password', 'Password123')
|
||||
->keys('@password', [WebDriverKeys::ENTER])
|
||||
->waitForReload()
|
||||
->assertPathIs('/')
|
||||
->assertAuthenticatedAs($this->user);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue