Release 2.16 (#4780)

This commit is contained in:
Kevin Papst
2024-05-01 14:24:24 +02:00
committed by GitHub
parent 8f8d228fb3
commit 99c296a751
150 changed files with 2498 additions and 1905 deletions

View File

@@ -120,19 +120,34 @@ abstract class ControllerBaseTest extends WebTestCase
default => null,
};
if ($username === null) {
throw new \Exception('Unknown username: ' . $username);
}
return $this->loginByUsername($username);
}
protected function loginByUsername(string $username): HttpKernelBrowser
{
$client = static::createClient();
if ($username !== null) {
/** @var UserRepository $userRepository */
$userRepository = $this->getPrivateService(UserRepository::class);
$user = $userRepository->findByUsername($username);
if ($user === null) {
throw new \Exception('Unknown user: ' . $username);
}
$client->loginUser($user, 'secured_area');
/** @var UserRepository $userRepository */
$userRepository = $this->getPrivateService(UserRepository::class);
$user = $userRepository->findByUsername($username);
if ($user === null) {
throw new \Exception('Unknown user: ' . $username);
}
$client->loginUser($user, 'secured_area');
return $client;
}
protected function loginUser(User $user): HttpKernelBrowser
{
$client = static::createClient();
$client->loginUser($user, 'secured_area');
return $client;
}

View File

@@ -38,7 +38,7 @@ class LayoutControllerTest extends ControllerBaseTest
$this->assertStringContainsString('href="/en/profile/' . $user->getUserIdentifier() . '"', $content);
$this->assertStringContainsString('href="/en/profile/' . $user->getUserIdentifier() . '/edit"', $content);
$this->assertStringContainsString('href="/en/profile/' . $user->getUserIdentifier() . '/prefs"', $content);
$this->assertStringContainsString('href="/en/logout?_csrf_token=', $content);
$this->assertStringContainsString('href="/en/logout', $content);
}
protected function assertHasNavigation(HttpKernelBrowser $client): void

View File

@@ -219,16 +219,7 @@ class ProfileControllerTest extends ControllerBaseTest
// cannot follow redirect here, because the password was changed and the user/password registered in the client
// are the old ones, so following the redirect would fail with "Unauthorized".
$this->tearDown();
$client = self::createClient([], [
'PHP_AUTH_USER' => UserFixtures::USERNAME_USER,
'PHP_AUTH_PW' => 'test1234',
]);
$this->request($client, '/profile/' . UserFixtures::USERNAME_USER . '/password');
$this->assertTrue($client->getResponse()->isSuccessful());
$user = $this->getUserByRole(User::ROLE_USER);
$this->assertFalse($passwordEncoder->getPasswordHasher($user)->verify($user->getPassword(), UserFixtures::DEFAULT_PASSWORD));
$this->assertTrue($passwordEncoder->getPasswordHasher($user)->verify($user->getPassword(), 'test1234'));
}
@@ -251,6 +242,9 @@ class ProfileControllerTest extends ControllerBaseTest
);
}
/**
* @legacy
*/
public function testApiTokenAction(): void
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);

View File

@@ -0,0 +1,108 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Tests\Doctrine;
use App\Doctrine\UTCDateTimeImmutableType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Doctrine\UTCDateTimeImmutableType
*/
class UTCDateTimeImmutableTypeTest extends TestCase
{
public function testGetUtc(): void
{
Type::overrideType(Types::DATETIME_MUTABLE, UTCDateTimeImmutableType::class);
/** @var UTCDateTimeImmutableType $type */
$type = Type::getType(Types::DATETIME_MUTABLE);
$this->assertInstanceOf(UTCDateTimeImmutableType::class, $type);
$utc = $type::getUtc();
$this->assertSame($utc, $type::getUtc());
$this->assertEquals('UTC', $type::getUtc()->getName());
}
/**
* @dataProvider getPlatforms
*/
public function testConvertToDatabaseValue(AbstractPlatform $platform): void
{
Type::overrideType(Types::DATETIME_MUTABLE, UTCDateTimeImmutableType::class);
/** @var UTCDateTimeImmutableType $type */
$type = Type::getType(Types::DATETIME_MUTABLE);
$result = $type->convertToDatabaseValue(null, $platform);
$this->assertNull($result);
$berlinTz = new \DateTimeZone('Europe/Berlin');
$date = new \DateTimeImmutable('2019-01-17 13:30:00');
$date = $date->setTimezone($berlinTz);
$this->assertEquals('Europe/Berlin', $date->getTimezone()->getName());
$expected = clone $date;
$expected = $expected->setTimezone($type::getUtc());
$bla = $expected->format($platform->getDateTimeFormatString());
/** @var \DateTime $result */
$result = $type->convertToDatabaseValue($date, $platform);
$this->assertEquals($bla, $result);
}
/**
* @dataProvider getPlatforms
*/
public function testConvertToPHPValue(AbstractPlatform $platform): void
{
Type::overrideType(Types::DATETIME_MUTABLE, UTCDateTimeImmutableType::class);
/** @var UTCDateTimeImmutableType $type */
$type = Type::getType(Types::DATETIME_MUTABLE);
$result = $type->convertToPHPValue(null, $platform);
$this->assertNull($result);
$result = $type->convertToPHPValue('2019-01-17 13:30:00', $platform);
$this->assertInstanceOf(\DateTimeImmutable::class, $result);
$this->assertEquals('UTC', $result->getTimezone()->getName());
$result = $result->format($platform->getDateTimeFormatString());
$this->assertEquals('2019-01-17 13:30:00', $result);
}
/**
* @dataProvider getPlatforms
*/
public function testConvertToPHPValueWithInvalidValue(AbstractPlatform $platform): void
{
$this->expectException(ConversionException::class);
Type::overrideType(Types::DATETIME_MUTABLE, UTCDateTimeImmutableType::class);
/** @var UTCDateTimeImmutableType $type */
$type = Type::getType(Types::DATETIME_MUTABLE);
$type->convertToPHPValue('201xx01-17 13:30:00', $platform);
}
/**
* @return \Doctrine\DBAL\Platforms\MySQLPlatform[][]
*/
public function getPlatforms(): array
{
return [
[new MySQLPlatform()],
];
}
}

View File

@@ -0,0 +1,73 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Tests\Export\Spreadsheet\CellFormatter;
use App\Export\Spreadsheet\CellFormatter\CellFormatterInterface;
use App\Export\Spreadsheet\CellFormatter\StringFormatter;
use App\Tests\Utils\StringHelperTest;
use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
/**
* @covers \App\Export\Spreadsheet\CellFormatter\StringFormatter
*/
class StringFormatterTest extends AbstractFormatterTest
{
protected function getFormatter(): CellFormatterInterface
{
return new StringFormatter();
}
protected function getActualValue(): string
{
return 'a simple text';
}
protected function getExpectedValue(): string
{
return 'a simple text';
}
public function assertNullValue(Cell $cell): void
{
self::assertEquals('', $cell->getValue());
}
public function testFormattedValueWithInvalidValue(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Unsupported value given, only string is supported');
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$sut = $this->getFormatter();
$sut->setFormattedValue($worksheet, 1, 1, 4711);
}
public function testWithDDEPayload(): void
{
$sut = $this->getFormatter();
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$test = new StringHelperTest();
foreach ($test->getDdeAttackStrings() as $attackString) {
$value = $attackString[0];
// PHPOffice converts that, so simply skip it
if (!str_contains($value, "\r")) {
$sut->setFormattedValue($worksheet, 1, 1, $value);
$cell = $worksheet->getCell([1, 1]);
self::assertEquals("' " . $value, $cell->getValue());
}
}
}
}

View File

@@ -12,6 +12,9 @@ namespace App\Tests\Security;
use App\Security\SessionHandler;
use Doctrine\DBAL\Connection;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\RateLimiter\RateLimiterFactory;
use Symfony\Component\RateLimiter\Storage\InMemoryStorage;
/**
* @covers \App\Security\SessionHandler
@@ -20,7 +23,11 @@ class SessionHandlerTest extends TestCase
{
public function testConstruct(): void
{
$sut = new SessionHandler($this->createMock(Connection::class));
$sut = new SessionHandler(
$this->createMock(Connection::class),
new RateLimiterFactory(['id' => 'foo', 'policy' => 'sliding_window'], new InMemoryStorage()),
new RequestStack(),
);
self::assertFalse($sut->isSessionExpired());
}

View File

@@ -22,7 +22,7 @@ class RuntimeExtensionsTest extends TestCase
{
public function testGetFilters(): void
{
$expected = ['md2html', 'desc2html', 'comment2html', 'comment1line', 'colorize', 'icon'];
$expected = ['md2html', 'desc2html', 'comment2html', 'comment1line', 'colorize', 'icon', 'sanitize_dde'];
$i = 0;
$sut = new RuntimeExtensions();

View File

@@ -78,9 +78,7 @@ class DateTimeFormatValidatorTest extends ConstraintValidatorTestCase
$this->validator->validate($input, $constraint);
$expectedFormat = \is_string($input) ? '"' . $input . '"' : $input;
$this->buildViolation('The given value is not a valid datetime format.')
$this->buildViolation('This value is not a valid datetime.')
->setCode(DateTimeFormat::INVALID_FORMAT)
->assertRaised();
}

View File

@@ -9,7 +9,7 @@
require __DIR__ . '/../vendor/autoload.php';
if (isset($_ENV['BOOTSTRAP_RESET_DATABASE']) && $_ENV['BOOTSTRAP_RESET_DATABASE'] == true) {
if (isset($_ENV['BOOTSTRAP_RESET_DATABASE']) && (bool) $_ENV['BOOTSTRAP_RESET_DATABASE'] === true) {
echo 'Re-Installing test database ...' . PHP_EOL;
exec(sprintf(