Skip to content

Commit

Permalink
Merge branch '7.1' into 7.2
Browse files Browse the repository at this point in the history
* 7.1:
  fix CS
  Update deprecations baseline
  [Mailer][MailJet] Fix parameters for TrackClicks and TrackOpens
  [Doctrine][Messenger] Oracle sequences are suffixed with `_seq`
  drop existing schema if tests create it explicitly
  synchronize line numbers in deprecations baseline
  [HttpClient] Fix class requirement message
  Add integration test for RememberMe with pg connection
  fix: DoctrineTokenProvider not oracle compatible
  • Loading branch information
xabbuh committed Oct 18, 2024
2 parents aa2f51b + 3fcfb37 commit da97783
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 5 deletions.
10 changes: 6 additions & 4 deletions Security/RememberMe/DoctrineTokenProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@ public function __construct(

public function loadTokenBySeries(string $series): PersistentTokenInterface
{
// the alias for lastUsed works around case insensitivity in PostgreSQL
$sql = 'SELECT class, username, value, lastUsed AS last_used FROM rememberme_token WHERE series=:series';
$sql = 'SELECT class, username, value, lastUsed FROM rememberme_token WHERE series=:series';
$paramValues = ['series' => $series];
$paramTypes = ['series' => ParameterType::STRING];
$stmt = $this->conn->executeQuery($sql, $paramValues, $paramTypes);
$row = $stmt->fetchAssociative() ?: throw new TokenNotFoundException('No token found.');

return new PersistentToken($row['class'], $row['username'], $series, $row['value'], new \DateTimeImmutable($row['last_used']));
// fetching numeric because column name casing depends on platform, eg. Oracle converts all not quoted names to uppercase
$row = $stmt->fetchNumeric() ?: throw new TokenNotFoundException('No token found.');

[$class, $username, $value, $last_used] = $row;
return new PersistentToken($class, $username, $series, $value, new \DateTimeImmutable($last_used));
}

public function deleteTokenBySeries(string $series): void
Expand Down
55 changes: 55 additions & 0 deletions Tests/Security/RememberMe/DoctrineTokenProviderPostgresTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Symfony\Bridge\Doctrine\Tests\Security\RememberMe;

use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
use Doctrine\ORM\ORMSetup;
use Symfony\Bridge\Doctrine\Security\RememberMe\DoctrineTokenProvider;

/**
* @requires extension pdo_pgsql
* @group integration
*/
class DoctrineTokenProviderPostgresTest extends DoctrineTokenProviderTest
{
public static function setUpBeforeClass(): void
{
if (!getenv('POSTGRES_HOST')) {
self::markTestSkipped('Missing POSTGRES_HOST env variable');
}
}

protected function bootstrapProvider()
{
$config = class_exists(ORMSetup::class) ? ORMSetup::createConfiguration(true) : new Configuration();
if (class_exists(DefaultSchemaManagerFactory::class)) {
$config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
}

$connection = DriverManager::getConnection([
'driver' => 'pdo_pgsql',
'host' => getenv('POSTGRES_HOST'),
'user' => 'postgres',
'password' => 'password',
], $config);
$connection->{method_exists($connection, 'executeStatement') ? 'executeStatement' : 'executeUpdate'}(<<<'SQL'
DROP TABLE IF EXISTS rememberme_token;
SQL
);

$connection->{method_exists($connection, 'executeStatement') ? 'executeStatement' : 'executeUpdate'}(<<<'SQL'
CREATE TABLE rememberme_token (
series CHAR(88) UNIQUE PRIMARY KEY NOT NULL,
value VARCHAR(88) NOT NULL, -- CHAR(88) adds spaces at the end
lastUsed TIMESTAMP NOT NULL,
class VARCHAR(100) NOT NULL,
username VARCHAR(200) NOT NULL
);
SQL
);

return new DoctrineTokenProvider($connection);
}
}
2 changes: 1 addition & 1 deletion Tests/Security/RememberMe/DoctrineTokenProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace Security\RememberMe;
namespace Symfony\Bridge\Doctrine\Tests\Security\RememberMe;

use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
Expand Down

0 comments on commit da97783

Please sign in to comment.