Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix Integration tests skipped with Redis cluster #49449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
cd50683
do not drop embed label classes
xabbuh Feb 17, 2023
a8dea95
[Messenger][Cache] fixed CallbackInterface support in async expiratio…
AdamKatzDev Feb 17, 2023
bccb074
[Contracts] Fix setting $container before calling parent::setContaine…
Feb 18, 2023
eb9db6c
bug #49441 [Contracts] Fix setting $container before calling parent::…
nicolas-grekas Feb 21, 2023
e9bd2ab
bug #49422 [Cache][Messenger] fixed CallbackInterface support in asyn…
nicolas-grekas Feb 21, 2023
a1696bf
Update Redis version to 6.2.8
maxbeckers Feb 21, 2023
b4aa3ea
[Form] Skip password hashing on empty password
Seb33300 Feb 21, 2023
49092e3
bug #49459 [Form] Skip password hashing on empty password (Seb33300)
nicolas-grekas Feb 21, 2023
879b5d1
bug #49421 [TwigBridge] do not drop embed label classes (xabbuh)
nicolas-grekas Feb 21, 2023
4d84c46
[MonologBridge] FirePHPHandler::onKernelResponse throws PHP 8.1 depre…
juagarc4 Feb 16, 2023
3db2dd6
bug #49405 [MonologBridge] FirePHPHandler::onKernelResponse throws PH…
nicolas-grekas Feb 21, 2023
f7043db
[SecurityBundle] Fix `Security::login()` on specific firewall
chalasr Feb 19, 2023
0eb0ae5
bug #49446 [SecurityBundle] Fix `Security::login()` on specific firew…
nicolas-grekas Feb 21, 2023
656b43e
minor #49467 Update Redis version to 6.2.8 for integrationtests (maxb…
nicolas-grekas Feb 21, 2023
04bc1ab
[Translation] Fix merge
nicolas-grekas Feb 21, 2023
8bbc98e
Merge branch '5.4' into 6.2
nicolas-grekas Feb 21, 2023
d0d21ba
Merge branch '6.2' into 6.3
nicolas-grekas Feb 21, 2023
e263666
Fix Integration tests skipped with Redis cluster
maxbeckers Feb 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ jobs:
LDAP_USERS: a
LDAP_PASSWORDS: a
redis:
image: redis:6.0.0
image: redis:6.2.8
ports:
- 16379:6379
redis-cluster:
image: grokzen/redis-cluster:latest
image: grokzen/redis-cluster:6.2.8
ports:
- 7000:7000
- 7001:7001
Expand All @@ -61,7 +61,7 @@ jobs:
env:
STANDALONE: 1
redis-sentinel:
image: bitnami/redis-sentinel:6.0
image: bitnami/redis-sentinel:6.2.8
ports:
- 26379:26379
env:
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Monolog/Handler/FirePHPHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function onKernelResponse(ResponseEvent $event): void
}

$request = $event->getRequest();
if (!preg_match('{\bFirePHP/\d+\.\d+\b}', $request->headers->get('User-Agent'))
if (!preg_match('{\bFirePHP/\d+\.\d+\b}', $request->headers->get('User-Agent', ''))
&& !$request->headers->has('X-FirePHP-Version')) {
self::$sendHeaders = false;
$this->headers = [];
Expand Down
18 changes: 18 additions & 0 deletions src/Symfony/Bridge/Monolog/Tests/Handler/FirePHPHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@

class FirePHPHandlerTest extends TestCase
{
public function testOnKernelResponseShouldNotTriggerDeprecation()
{
$request = Request::create('/');
$request->headers->remove('User-Agent');

$response = new Response('foo');
$event = new ResponseEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MAIN_REQUEST, $response);

$error = null;
set_error_handler(function ($type, $message) use (&$error) { $error = $message; }, \E_DEPRECATED);

$listener = new FirePHPHandler();
$listener->onKernelResponse($event);
restore_error_handler();

$this->assertNull($error);
}

public function testLogHandling()
{
$handler = $this->createHandler();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@
{%- if required -%}
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) -%}
{%- endif -%}
{%- if parent_label_class is defined -%}
{% set embed_label_classes = parent_label_class|split(' ')|filter(class => class in ['checkbox-inline', 'radio-inline']) %}
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ embed_label_classes|join(' '))|trim}) -%}
{% endif %}
{%- if label is not same as(false) and label is empty -%}
{%- if label_format is not empty -%}
{%- set label = label_format|replace({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@
{% if errors|length > 0 -%}
{% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' error')|trim}) %}
{% endif %}
{%- if parent_label_class is defined -%}
{% set embed_label_classes = parent_label_class|split(' ')|filter(class => class in ['checkbox-inline', 'radio-inline']) %}
{%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ embed_label_classes|join(' '))|trim}) -%}
{% endif %}
{% if label is empty %}
{%- if label_format is not empty -%}
{% set label = label_format|replace({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
service_locator([
'security.token_storage' => service('security.token_storage'),
'security.authorization_checker' => service('security.authorization_checker'),
'security.user_authenticator' => service('security.user_authenticator')->ignoreOnInvalid(),
'security.authenticator.managers_locator' => service('security.authenticator.managers_locator')->ignoreOnInvalid(),
'request_stack' => service('request_stack'),
'security.firewall.map' => service('security.firewall.map'),
'security.user_checker' => service('security.user_checker'),
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/SecurityBundle/Security.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function login(UserInterface $user, string $authenticatorName = null, str

$this->container->get('security.user_checker')->checkPreAuth($user);

return $this->container->get('security.user_authenticator')->authenticateUser($user, $authenticator, $request);
return $this->container->get('security.authenticator.managers_locator')->get($firewallName)->authenticateUser($user, $authenticator, $request);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,16 @@ security:
custom_authenticators:
- 'Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\AuthenticatorBundle\ApiAuthenticator'
provider: main
second:
pattern: ^/second
form_login:
check_path: /second/login/check
custom_authenticators:
- 'Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\AuthenticatorBundle\ApiAuthenticator'
provider: main

access_control:
- { path: '^/main/login/check$', roles: IS_AUTHENTICATED_FULLY }
- { path: '^/main/logged-in$', roles: IS_AUTHENTICATED_FULLY }
- { path: '^/second/login/check$', roles: IS_AUTHENTICATED_FULLY }
- { path: '^/second/logged-in$', roles: IS_AUTHENTICATED_FULLY }
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ logged-in:
force-logout:
path: /main/force-logout
controller: Symfony\Bundle\SecurityBundle\Tests\Functional\LogoutController::logout

second-force-login:
path: /second/force-login
controller: Symfony\Bundle\SecurityBundle\Tests\Functional\ForceLoginController::welcome

second-logged-in:
path: /second/logged-in
controller: Symfony\Bundle\SecurityBundle\Tests\Functional\LoggedInController
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/SecurityBundle/Tests/SecurityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function testLogin()
->willReturnMap([
['request_stack', $requestStack],
['security.firewall.map', $firewallMap],
['security.user_authenticator', $userAuthenticator],
['security.authenticator.managers_locator', new ServiceLocator(['main' => fn () => $userAuthenticator])],
['security.user_checker', $userChecker],
])
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ function (CacheItem $item, float $startTime) {
$startTime = microtime(true);
$pool = $message->findPool($this->reverseContainer);
$callback = $message->findCallback($this->reverseContainer);
$value = $callback($item);
$save = true;
$value = $callback($item, $save);
$setMetadata($item, $startTime);
$pool->save($item->set($value));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
namespace Symfony\Component\Cache\Tests\Messenger;

use PHPUnit\Framework\TestCase;
use Psr\Cache\CacheItemInterface;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\CacheItem;
use Symfony\Component\Cache\Messenger\EarlyExpirationHandler;
use Symfony\Component\Cache\Messenger\EarlyExpirationMessage;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ReverseContainer;
use Symfony\Component\DependencyInjection\ServiceLocator;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Contracts\Cache\CallbackInterface;

class EarlyExpirationHandlerTest extends TestCase
{
Expand All @@ -37,8 +38,8 @@ public function testHandle()
$item = $pool->getItem('foo');
$item->set(234);

$computationService = new class() {
public function __invoke(CacheItem $item)
$computationService = new class() implements CallbackInterface {
public function __invoke(CacheItemInterface $item, bool &$save)
{
usleep(30000);
$item->expiresAfter(3600);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public function __construct(
*/
public function registerPassword(FormEvent $event)
{
if (null === $event->getData() || '' === $event->getData()) {
return;
}

$this->assertNotMapped($event->getForm());

$this->passwords[] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Form\Exception\InvalidConfigurationException;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\PasswordHasher\EventListener\PasswordHasherListener;
Expand Down Expand Up @@ -80,6 +81,36 @@ public function testPasswordHashSuccess()
$this->assertSame($user->getPassword(), $hashedPassword);
}

public function testPasswordHashSkippedWithEmptyPassword()
{
$oldHashedPassword = 'PreviousHashedPassword';

$user = new User();
$user->setPassword($oldHashedPassword);

$this->passwordHasher
->expects($this->never())
->method('hashPassword')
;

$this->assertEquals($user->getPassword(), $oldHashedPassword);

$form = $this->factory
->createBuilder(FormType::class, $user)
->add('plainPassword', PasswordType::class, [
'hash_property_path' => 'password',
'mapped' => false,
'required' => false,
])
->getForm()
;

$form->submit(['plainPassword' => '']);

$this->assertTrue($form->isValid());
$this->assertSame($user->getPassword(), $oldHashedPassword);
}

public function testPasswordHashSuccessWithEmptyData()
{
$user = new User();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ protected function setUp(): void
}

try {
$this->redis = new \Redis();
$this->connection = Connection::fromDsn(getenv('MESSENGER_REDIS_DSN'), ['sentinel_master' => getenv('MESSENGER_REDIS_SENTINEL_MASTER')], $this->redis);
$this->redis = $this->createRedisClient();
$this->connection = Connection::fromDsn(getenv('MESSENGER_REDIS_DSN'), ['sentinel_master' => getenv('MESSENGER_REDIS_SENTINEL_MASTER') ?: null], $this->redis);
$this->connection->cleanup();
$this->connection->setup();
} catch (\Exception $e) {
Expand Down Expand Up @@ -144,7 +144,7 @@ public function testConnectionSendDelayedMessagesWithSameContent()
public function testConnectionBelowRedeliverTimeout()
{
// lower redeliver timeout and claim interval
$connection = Connection::fromDsn(getenv('MESSENGER_REDIS_DSN'), ['sentinel_master' => getenv('MESSENGER_REDIS_SENTINEL_MASTER')], $this->redis);
$connection = Connection::fromDsn(getenv('MESSENGER_REDIS_DSN'), ['sentinel_master' => getenv('MESSENGER_REDIS_SENTINEL_MASTER') ?: null], $this->redis);

$connection->cleanup();
$connection->setup();
Expand Down Expand Up @@ -172,7 +172,7 @@ public function testConnectionClaimAndRedeliver()
// lower redeliver timeout and claim interval
$connection = Connection::fromDsn(
getenv('MESSENGER_REDIS_DSN'),
['redeliver_timeout' => 0, 'claim_interval' => 500, 'sentinel_master' => getenv('MESSENGER_REDIS_SENTINEL_MASTER')],
['redeliver_timeout' => 0, 'claim_interval' => 500, 'sentinel_master' => getenv('MESSENGER_REDIS_SENTINEL_MASTER') ?: null],

$this->redis
);
Expand Down Expand Up @@ -222,7 +222,8 @@ public function testLazySentinel()
$connection = Connection::fromDsn(getenv('MESSENGER_REDIS_DSN'),
['lazy' => true,
'delete_after_ack' => true,
'sentinel_master' => getenv('MESSENGER_REDIS_SENTINEL_MASTER'), ], $this->redis);
'sentinel_master' => getenv('MESSENGER_REDIS_SENTINEL_MASTER') ?: null,
], $this->redis);

$connection->add('1', []);
$this->assertNotEmpty($message = $connection->get());
Expand All @@ -240,11 +241,7 @@ public function testLazyCluster()
{
$this->skipIfRedisClusterUnavailable();

$connection = new Connection(
['lazy' => true],
['host' => explode(' ', getenv('REDIS_CLUSTER_HOSTS'))],
[]
);
$connection = new Connection(['lazy' => true, 'host' => explode(' ', getenv('REDIS_CLUSTER_HOSTS'))]);

$connection->add('1', []);
$this->assertNotEmpty($message = $connection->get());
Expand Down Expand Up @@ -293,7 +290,7 @@ public function testFromDsnWithMultipleHosts()
$dsn = array_map(fn ($host) => 'redis://'.$host, $hosts);
$dsn = implode(',', $dsn);

$this->assertInstanceOf(Connection::class, Connection::fromDsn($dsn, ['sentinel_master' => getenv('MESSENGER_REDIS_SENTINEL_MASTER')]));
$this->assertInstanceOf(Connection::class, Connection::fromDsn($dsn, ['sentinel_master' => getenv('MESSENGER_REDIS_SENTINEL_MASTER') ?: null]));
}

public function testJsonError()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,39 @@ protected function createRedisClient(): \Redis|Relay
{
return new Relay();
}

public function testConnectionSendAndGetDelayed()
{
self::markTestSkipped('This test doesn\'t work with relay.');
}

public function testConnectionSendDelayedMessagesWithSameContent()
{
self::markTestSkipped('This test doesn\'t work with relay.');
}

public function testLazy()
{
self::markTestSkipped('This test doesn\'t work with relay.');
}

public function testDbIndex()
{
self::markTestSkipped('This test doesn\'t work with relay.');
}

public function testGetNonBlocking()
{
self::markTestSkipped('This test doesn\'t work with relay.');
}

public function testGetAfterReject()
{
self::markTestSkipped('This test doesn\'t work with relay.');
}

public function testJsonError()
{
self::markTestSkipped('This test doesn\'t work with relay.');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private static function initializeRedis(\Redis|Relay $redis, string $host, int $
*/
private static function initializeRedisCluster(?\RedisCluster $redis, array $hosts, string|array|null $auth, array $params): \RedisCluster
{
$redis ??= new \RedisCluster(null, $hosts, $params['timeout'], $params['read_timeout'], (bool) $params['persistent'], $auth, ...\defined('Redis::SCAN_PREFIX') ? [$params['ssl'] ?? null] : []);
$redis ??= new \RedisCluster(null, $hosts, $params['timeout'], $params['read_timeout'], (bool) ($params['persistent'] ?? false), $auth, ...\defined('Redis::SCAN_PREFIX') ? [$params['ssl'] ?? null] : []);
$redis->setOption(\Redis::OPT_SERIALIZER, $params['serializer']);

return $redis;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ public function testReadForOneLocaleAndOneDomain(string $locale, string $domain,
'headers' => [
'Authorization' => 'Loco API_KEY',
],
]), $loader, new NullLogger(), 'en', 'localise.biz/api/', $this->getTranslatorBag());
]), $loader, new NullLogger(), 'en', 'localise.biz/api/');
$translatorBag = $provider->read([$domain], [$locale]);
// We don't want to assert equality of metadata here, due to the ArrayLoader usage.
foreach ($translatorBag->getCatalogues() as $catalogue) {
Expand Down Expand Up @@ -759,7 +759,7 @@ public function testReadForManyLocalesAndManyDomains(array $locales, array $doma
'headers' => [
'Authorization' => 'Loco API_KEY',
],
]), $loader, $this->getLogger(), 'en', 'localise.biz/api/', $this->getTranslatorBag());
]), $loader, $this->getLogger(), 'en', 'localise.biz/api/');
$translatorBag = $provider->read($domains, $locales);
// We don't want to assert equality of metadata here, due to the ArrayLoader usage.
foreach ($translatorBag->getCatalogues() as $catalogue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ abstract class ProviderTestCase extends TestCase
protected XliffFileDumper|MockObject $xliffFileDumper;
protected TranslatorBagInterface|MockObject $translatorBag;

abstract public static function createProvider(HttpClientInterface $client, LoaderInterface $loader, LoggerInterface $logger, string $defaultLocale, string $endpoint, TranslatorBagInterface $translatorBag = null): ProviderInterface;
abstract public static function createProvider(HttpClientInterface $client, LoaderInterface $loader, LoggerInterface $logger, string $defaultLocale, string $endpoint): ProviderInterface;

/**
* @return iterable<array{0: ProviderInterface, 1: string}>
Expand Down
9 changes: 5 additions & 4 deletions src/Symfony/Contracts/Service/ServiceSubscriberTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,13 @@ public static function getSubscribedServices(): array
#[Required]
public function setContainer(ContainerInterface $container): ?ContainerInterface
{
$this->container = $container;

$ret = null;
if (method_exists(get_parent_class(self::class) ?: '', __FUNCTION__)) {
return parent::setContainer($container);
$ret = parent::setContainer($container);
}

return null;
$this->container = $container;

return $ret;
}
}
Loading