Release 2.23.0 (#5075)
This commit is contained in:
@@ -16,7 +16,7 @@ use App\Tests\Controller\ControllerBaseTest;
|
||||
*/
|
||||
class PasswordResetControllerTest extends ControllerBaseTest
|
||||
{
|
||||
private function testResetActionWithDeactivatedFeature(string $route, string $method = 'GET')
|
||||
private function testResetActionWithDeactivatedFeature(string $route, string $method = 'GET'): void
|
||||
{
|
||||
$client = self::createClient();
|
||||
$this->setSystemConfiguration('user.password_reset', false);
|
||||
@@ -39,11 +39,6 @@ class PasswordResetControllerTest extends ControllerBaseTest
|
||||
$this->testResetActionWithDeactivatedFeature('/resetting/check-email');
|
||||
}
|
||||
|
||||
public function testResetWithDeactivatedFeature(): void
|
||||
{
|
||||
$this->testResetActionWithDeactivatedFeature('/resetting/reset/1234567890');
|
||||
}
|
||||
|
||||
public function testResetRequestPageIsRendered(): void
|
||||
{
|
||||
$client = self::createClient();
|
||||
@@ -55,10 +50,11 @@ class PasswordResetControllerTest extends ControllerBaseTest
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertNotFalse($content);
|
||||
$this->assertStringContainsString('<title>Kimai – Time Tracking</title>', $content);
|
||||
$this->assertStringContainsString('Reset your password', $content);
|
||||
$this->assertStringContainsString('<form class="card-body security-password-reset" action="/en/resetting/send-email" method="post" autocomplete="off">', $content);
|
||||
$this->assertStringContainsString('<input type="text"', $content);
|
||||
$this->assertStringContainsString('<input autocomplete="username" type="text"', $content);
|
||||
$this->assertStringContainsString('id="username" name="username" required="required"', $content);
|
||||
$this->assertStringContainsString('Reset your password', $content);
|
||||
|
||||
@@ -67,14 +63,94 @@ class PasswordResetControllerTest extends ControllerBaseTest
|
||||
'username' => 'john_user',
|
||||
]);
|
||||
|
||||
$this->assertIsRedirect($client, $this->createUrl('/resetting/check-email?username=john_user'));
|
||||
$this->assertIsRedirect($client, $this->createUrl('/resetting/check-email'));
|
||||
$client->followRedirect();
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
$user = $this->loadUserFromDatabase('john_user');
|
||||
$token = $user->getConfirmationToken();
|
||||
// TODO test the actual email and provided login link
|
||||
|
||||
$this->request($client, '/resetting/reset/' . $token);
|
||||
$user = $this->loadUserFromDatabase('john_user');
|
||||
$this->assertTrue($user->requiresPasswordReset());
|
||||
}
|
||||
|
||||
public function testRequestAsLoggedInUserRedirects(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser();
|
||||
$this->request($client, '/resetting/request');
|
||||
$this->assertIsRedirect($client, $this->createUrl('/homepage'));
|
||||
}
|
||||
|
||||
public function testResetAsLoggedInUserRedirects(): void
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser();
|
||||
$this->request($client, '/resetting/send-email', 'POST');
|
||||
$this->assertIsRedirect($client, $this->createUrl('/homepage'));
|
||||
}
|
||||
|
||||
public function testResetWithMissingUsername(): void
|
||||
{
|
||||
$client = self::createClient();
|
||||
$this->request($client, '/resetting/send-email', 'POST');
|
||||
$this->assertIsRedirect($client, $this->createUrl('/resetting/check-email'));
|
||||
$client->followRedirect();
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
$content = $client->getResponse()->getContent();
|
||||
$this->assertNotFalse($content);
|
||||
$this->assertStringContainsString('An email has been sent with a link to reset your password.', $content);
|
||||
$this->assertStringContainsString('Note: You can only request a new password once every 1:00 hours.', $content);
|
||||
}
|
||||
|
||||
public function testResetWithEmptyUsername(): void
|
||||
{
|
||||
$client = self::createClient();
|
||||
$this->request($client, '/resetting/send-email', 'POST', ['username' => '']);
|
||||
$this->assertIsRedirect($client, $this->createUrl('/resetting/check-email'));
|
||||
$client->followRedirect();
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
$content = $client->getResponse()->getContent();
|
||||
$this->assertNotFalse($content);
|
||||
$this->assertStringContainsString('An email has been sent with a link to reset your password.', $content);
|
||||
$this->assertStringContainsString('Note: You can only request a new password once every 1:00 hours.', $content);
|
||||
}
|
||||
|
||||
public function testResetWithUnknownUsername(): void
|
||||
{
|
||||
$client = self::createClient();
|
||||
$this->request($client, '/resetting/send-email', 'POST', ['username' => 'foobar']);
|
||||
$this->assertIsRedirect($client, $this->createUrl('/resetting/check-email'));
|
||||
$client->followRedirect();
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
$content = $client->getResponse()->getContent();
|
||||
$this->assertNotFalse($content);
|
||||
$this->assertStringContainsString('An email has been sent with a link to reset your password.', $content);
|
||||
$this->assertStringContainsString('Note: You can only request a new password once every 1:00 hours.', $content);
|
||||
}
|
||||
|
||||
public function testResetWithKnownUsername(): void
|
||||
{
|
||||
$client = self::createClient();
|
||||
|
||||
$user = $this->loadUserFromDatabase('john_user');
|
||||
$this->assertFalse($user->requiresPasswordReset());
|
||||
|
||||
$this->request($client, '/resetting/request');
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
$form = $client->getCrawler()->filter('form')->form();
|
||||
$client->submit($form, [
|
||||
'username' => 'john_user',
|
||||
]);
|
||||
|
||||
$this->assertIsRedirect($client, $this->createUrl('/resetting/check-email'));
|
||||
$client->followRedirect();
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
$content = $client->getResponse()->getContent();
|
||||
$this->assertNotFalse($content);
|
||||
$this->assertStringContainsString('An email has been sent with a link to reset your password.', $content);
|
||||
$this->assertStringContainsString('Note: You can only request a new password once every 1:00 hours.', $content);
|
||||
|
||||
// TODO test the actual email and provided login link
|
||||
|
||||
$user = $this->loadUserFromDatabase('john_user');
|
||||
$this->assertTrue($user->requiresPasswordReset());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,8 +46,8 @@ class SecurityControllerTest extends ControllerBaseTest
|
||||
$content = $response->getContent();
|
||||
$this->assertStringContainsString('<title>Kimai – Time Tracking</title>', $content);
|
||||
$this->assertStringContainsString('<form action="/en/login_check" method="post"', $content);
|
||||
$this->assertStringContainsString('<input type="text" id="username" name="_username"', $content);
|
||||
$this->assertStringContainsString('<input id="password" name="_password" type="password"', $content);
|
||||
$this->assertStringContainsString('<input autocomplete="username" type="text" id="username" name="_username"', $content);
|
||||
$this->assertStringContainsString('<input autocomplete="new-password" id="password" name="_password" type="password"', $content);
|
||||
$this->assertStringContainsString('">Log in</button>', $content);
|
||||
$this->assertStringContainsString('<input type="hidden" name="_csrf_token" value="', $content);
|
||||
$this->assertStringNotContainsString('<a href="/en/register/"', $content);
|
||||
|
||||
Reference in New Issue
Block a user