Release 2.23.0 (#5075)

This commit is contained in:
Kevin Papst
2024-10-03 10:34:20 +02:00
committed by GitHub
parent 40154be8f9
commit fb9a0dc499
142 changed files with 855 additions and 910 deletions

View File

@@ -25,8 +25,8 @@ class ListUserCommandTest extends KernelTestCase
{
$commandTester = $this->getCommandTester();
$output = $commandTester->getDisplay();
$this->assertStringContainsString('Username Email Roles Active PW Reset', $output);
$this->assertStringContainsString('---------- ------- ------- -------- ----------', $output);
$this->assertStringContainsString('Username Email Roles Active Authenticator', $output);
$this->assertStringContainsString('---------- ------- ------- -------- -------------', $output);
}
protected function getCommandTester(): CommandTester

View File

@@ -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());
}
}

View File

@@ -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);

View File

@@ -298,7 +298,7 @@ class ConfigurationTest extends TestCase
'registration' => false,
'password_reset' => true,
'login' => true,
'password_reset_retry_ttl' => 7200,
'password_reset_retry_ttl' => 3600,
'password_reset_token_ttl' => 86400,
],
'invoice' => [

View File

@@ -41,7 +41,6 @@ class UserTest extends TestCase
self::assertNull($user->getAccountNumber());
self::assertNull($user->getApiToken());
self::assertNull($user->getPlainApiToken());
self::assertNull($user->getPasswordRequestedAt());
self::assertFalse($user->hasTotpSecret());
self::assertNull($user->getTotpSecret());
self::assertEquals(User::DEFAULT_LANGUAGE, $user->getLanguage());
@@ -50,6 +49,7 @@ class UserTest extends TestCase
self::assertFalse($user->canSeeAllData());
self::assertFalse($user->isExportDecimal());
self::assertFalse($user->isSystemAccount());
self::assertFalse($user->isPasswordRequestNonExpired(3599));
$user->setUserIdentifier('foo');
self::assertEquals('foo', $user->getUserIdentifier());
@@ -227,20 +227,6 @@ class UserTest extends TestCase
self::assertEquals($date, $user->getRegisteredAt());
}
public function testPasswordRequestedAt(): void
{
$date = new \DateTimeImmutable('-60 minutes');
$sut = new User();
self::assertFalse($sut->isPasswordRequestNonExpired(3599));
self::assertNull($sut->getPasswordRequestedAt());
$sut->setPasswordRequestedAt($date);
self::assertEquals($date, $sut->getPasswordRequestedAt());
self::assertFalse($sut->isPasswordRequestNonExpired(3599));
// 10 seconds just to make sure it doesn't expire by accident
self::assertTrue($sut->isPasswordRequestNonExpired(3610));
}
public function testPreferences(): void
{
$user = new User();

View File

@@ -225,7 +225,6 @@ class BaseQueryTest extends TestCase
$sut->addActivity($expected2);
$this->assertEquals([$expected, $expected2], $sut->getActivities());
$this->assertEquals([], $sut->getActivityIds());
$sut->setActivities([]);
$this->assertEquals([], $sut->getActivities());
@@ -247,7 +246,11 @@ class BaseQueryTest extends TestCase
$activity->method('getId')->willReturn(27);
$sut->addActivity($activity);
$this->assertEquals([13, 27], $sut->getActivityIds());
$ids = [];
foreach ($sut->getActivities() as $activity) {
$ids[] = $activity->getId();
}
$this->assertEquals([13, 27, null, 27], $ids);
}
protected function assertCustomer(BaseQuery $sut): void

View File

@@ -24,7 +24,7 @@ class ExportQueryTest extends TimesheetQueryTest
$this->assertPage($sut);
$this->assertPageSize($sut);
$this->assertOrderBy($sut, 'begin');
$this->assertOrder($sut, ExportQuery::ORDER_ASC);
$this->assertOrder($sut);
$this->assertUser($sut);
$this->assertCustomer($sut);

View File

@@ -24,7 +24,7 @@ class InvoiceQueryTest extends TimesheetQueryTest
$this->assertPage($sut);
$this->assertPageSize($sut);
$this->assertOrderBy($sut, 'begin');
$this->assertOrder($sut, InvoiceQuery::ORDER_ASC);
$this->assertOrder($sut);
$this->assertUser($sut);
$this->assertCustomer($sut);

View File

@@ -1269,16 +1269,6 @@ parameters:
count: 1
path: Controller/Reporting/ProjectViewControllerTest.php
-
message: "#^Method App\\\\Tests\\\\Controller\\\\Security\\\\PasswordResetControllerTest\\:\\:testResetActionWithDeactivatedFeature\\(\\) has no return type specified\\.$#"
count: 1
path: Controller/Security/PasswordResetControllerTest.php
-
message: "#^Parameter \\#2 \\$haystack of method PHPUnit\\\\Framework\\\\Assert\\:\\:assertStringContainsString\\(\\) expects string, string\\|false given\\.$#"
count: 6
path: Controller/Security/PasswordResetControllerTest.php
-
message: "#^Parameter \\#2 \\$haystack of method PHPUnit\\\\Framework\\\\Assert\\:\\:assertStringContainsString\\(\\) expects string, string\\|false given\\.$#"
count: 6