Skip to content

Commit

Permalink
Merge branch '6.0' into 6.1
Browse files Browse the repository at this point in the history
* 6.0:
  fix merge
  [HttpClient] mark test transient
  [Mime] Fix test
  [Translation] Fix TranslationPullCommand with ICU translations
  [PropertyInfo] Fix phpstan extractor issues
  Allow package-versions-deprecated plugin
  Update security.lb.xlf
  [Notifier] Use correct factory for the msteams transport
  Fix SessionListener without session in request
  Remove direct dependency on composer/package-versions-deprecated
  Remove the unused dependency on composer/package-versions-deprecated
  [Security/Http] Fix cookie clearing on logout
  [HttpClient] fix checking for recent curl consts
  • Loading branch information
nicolas-grekas committed Dec 25, 2021
2 parents 0d6e859 + 7c5dafe commit f49cf52
Show file tree
Hide file tree
Showing 21 changed files with 233 additions and 25 deletions.
9 changes: 7 additions & 2 deletions composer.json
Expand Up @@ -122,12 +122,11 @@
"async-aws/sqs": "^1.0",
"async-aws/sns": "^1.0",
"cache/integration-tests": "dev-master",
"composer/package-versions-deprecated": "^1.8",
"doctrine/annotations": "^1.13.1",
"doctrine/collections": "~1.0",
"doctrine/data-fixtures": "^1.1",
"doctrine/dbal": "^2.13.1|^3.0",
"doctrine/orm": "^2.7.3",
"doctrine/orm": "^2.7.4",
"guzzlehttp/promises": "^1.4",
"masterminds/html5": "^2.6",
"monolog/monolog": "^1.25.1|^2",
Expand Down Expand Up @@ -161,6 +160,12 @@
"ocramius/proxy-manager": "<2.1",
"phpunit/phpunit": "<5.4.3"
},
"config": {
"allow-plugins": {
"composer/package-versions-deprecated": true,
"symfony/runtime": true
}
},
"autoload": {
"psr-4": {
"Symfony\\Bridge\\Doctrine\\": "src/Symfony/Bridge/Doctrine/",
Expand Down
5 changes: 2 additions & 3 deletions src/Symfony/Bridge/Doctrine/composer.json
Expand Up @@ -25,7 +25,6 @@
"symfony/service-contracts": "^1.1|^2|^3"
},
"require-dev": {
"composer/package-versions-deprecated": "^1.8",
"symfony/stopwatch": "^5.4|^6.0",
"symfony/cache": "^5.4|^6.0",
"symfony/config": "^5.4|^6.0",
Expand All @@ -47,13 +46,13 @@
"doctrine/collections": "~1.0",
"doctrine/data-fixtures": "^1.1",
"doctrine/dbal": "^2.13.1|^3.0",
"doctrine/orm": "^2.7.3",
"doctrine/orm": "^2.7.4",
"psr/log": "^1|^2|^3"
},
"conflict": {
"doctrine/dbal": "<2.13.1",
"doctrine/lexer": "<1.1",
"doctrine/orm": "<2.7.3",
"doctrine/orm": "<2.7.4",
"phpunit/phpunit": "<5.4.3",
"symfony/cache": "<5.4",
"symfony/dependency-injection": "<5.4",
Expand Down
1 change: 0 additions & 1 deletion src/Symfony/Bridge/ProxyManager/composer.json
Expand Up @@ -17,7 +17,6 @@
],
"require": {
"php": ">=8.0.2",
"composer/package-versions-deprecated": "^1.8",
"friendsofphp/proxy-manager-lts": "^1.0.2",
"symfony/dependency-injection": "^5.4|^6.0"
},
Expand Down
10 changes: 8 additions & 2 deletions src/Symfony/Component/HttpClient/CurlHttpClient.php
Expand Up @@ -432,8 +432,6 @@ private function validateExtraCurlOptions(array $options): void
\CURLOPT_INFILESIZE => 'body',
\CURLOPT_POSTFIELDS => 'body',
\CURLOPT_UPLOAD => 'body',
\CURLOPT_PINNEDPUBLICKEY => 'peer_fingerprint',
\CURLOPT_UNIX_SOCKET_PATH => 'bindto',
\CURLOPT_INTERFACE => 'bindto',
\CURLOPT_TIMEOUT_MS => 'max_duration',
\CURLOPT_TIMEOUT => 'max_duration',
Expand All @@ -456,6 +454,14 @@ private function validateExtraCurlOptions(array $options): void
\CURLOPT_PROGRESSFUNCTION => 'on_progress',
];

if (\defined('CURLOPT_UNIX_SOCKET_PATH')) {
$curloptsToConfig[\CURLOPT_UNIX_SOCKET_PATH] = 'bindto';
}

if (\defined('CURLOPT_PINNEDPUBLICKEY')) {
$curloptsToConfig[\CURLOPT_PINNEDPUBLICKEY] = 'peer_fingerprint';
}

$curloptsToCheck = [
\CURLOPT_PRIVATE,
\CURLOPT_HEADERFUNCTION,
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/HttpClient/Tests/HttpClientTestCase.php
Expand Up @@ -32,6 +32,9 @@ abstract class HttpClientTestCase extends BaseHttpClientTestCase
{
private static $vulcainStarted = false;

/**
* @group transient-on-macos
*/
public function testTimeoutOnDestruct()
{
if (!method_exists(parent::class, 'testTimeoutOnDestruct')) {
Expand Down
Expand Up @@ -88,7 +88,7 @@ public function onKernelRequest(RequestEvent $event)

public function onKernelResponse(ResponseEvent $event)
{
if (!$event->isMainRequest()) {
if (!$event->isMainRequest() || (!$this->container->has('initialized_session') && !$event->getRequest()->hasSession())) {
return;
}

Expand Down
Expand Up @@ -326,6 +326,24 @@ public function testUninitializedSession()
$this->assertFalse($response->headers->has(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER));
}

public function testUninitializedSessionWithoutInitializedSession()
{
$kernel = $this->createMock(HttpKernelInterface::class);
$response = new Response();
$response->setSharedMaxAge(60);
$response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 'true');

$container = new ServiceLocator([]);

$listener = new SessionListener($container);
$listener->onKernelResponse(new ResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response));
$this->assertFalse($response->headers->has('Expires'));
$this->assertTrue($response->headers->hasCacheControlDirective('public'));
$this->assertFalse($response->headers->hasCacheControlDirective('private'));
$this->assertFalse($response->headers->hasCacheControlDirective('must-revalidate'));
$this->assertSame('60', $response->headers->getCacheControlDirective('s-maxage'));
}

public function testSurrogateMainRequestIsPublic()
{
$session = $this->createMock(Session::class);
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Mime/Tests/Header/HeadersTest.php
Expand Up @@ -283,14 +283,14 @@ public function testToArray()
public function testInReplyToAcceptsNonIdentifierValues()
{
$headers = new Headers();
$headers->addHeader('In-Reply-To', 'foobar');
$headers->addTextHeader('In-Reply-To', 'foobar');
$this->assertEquals('foobar', $headers->get('In-Reply-To')->getBody());
}

public function testReferencesAcceptsNonIdentifierValues()
{
$headers = new Headers();
$headers->addHeader('References' , 'foobar');
$headers->addTextHeader('References' , 'foobar');
$this->assertEquals('foobar', $headers->get('References')->getBody());
}

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Notifier/Transport.php
Expand Up @@ -28,7 +28,7 @@
use Symfony\Component\Notifier\Bridge\Mattermost\MattermostTransportFactory;
use Symfony\Component\Notifier\Bridge\MessageBird\MessageBirdTransportFactory;
use Symfony\Component\Notifier\Bridge\MessageMedia\MessageMediaTransportFactory;
use Symfony\Component\Notifier\Bridge\MicrosoftTeams\MicrosoftTeamsTransport;
use Symfony\Component\Notifier\Bridge\MicrosoftTeams\MicrosoftTeamsTransportFactory;
use Symfony\Component\Notifier\Bridge\Mobyt\MobytTransportFactory;
use Symfony\Component\Notifier\Bridge\Octopush\OctopushTransportFactory;
use Symfony\Component\Notifier\Bridge\OvhCloud\OvhCloudTransportFactory;
Expand Down Expand Up @@ -81,7 +81,7 @@ final class Transport
MattermostTransportFactory::class,
MessageBirdTransportFactory::class,
MessageMediaTransportFactory::class,
MicrosoftTeamsTransport::class,
MicrosoftTeamsTransportFactory::class,
MobytTransportFactory::class,
OctopushTransportFactory::class,
OvhCloudTransportFactory::class,
Expand Down
Expand Up @@ -355,7 +355,7 @@ public function constructorTypesProvider()
/**
* @dataProvider unionTypesProvider
*/
public function testExtractorUnionTypes(string $property, array $types)
public function testExtractorUnionTypes(string $property, ?array $types)
{
$this->assertEquals($types, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\DummyUnionType', $property));
}
Expand All @@ -368,6 +368,8 @@ public function unionTypesProvider(): array
['c', [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, [], [new Type(Type::BUILTIN_TYPE_STRING), new Type(Type::BUILTIN_TYPE_INT)])]],
['d', [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, [new Type(Type::BUILTIN_TYPE_STRING), new Type(Type::BUILTIN_TYPE_INT)], [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, [], [new Type(Type::BUILTIN_TYPE_STRING)])])]],
['e', [new Type(Type::BUILTIN_TYPE_OBJECT, true, Dummy::class, true, [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, [], [new Type(Type::BUILTIN_TYPE_STRING)])], [new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, [new Type(Type::BUILTIN_TYPE_INT)], [new Type(Type::BUILTIN_TYPE_STRING, false, null, true, [], [new Type(Type::BUILTIN_TYPE_OBJECT, false, DefaultValue::class)])])]), new Type(Type::BUILTIN_TYPE_OBJECT, false, ParentDummy::class)]],
['f', null],
['g', [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, [], [new Type(Type::BUILTIN_TYPE_STRING), new Type(Type::BUILTIN_TYPE_INT)])]],
];
}

Expand Down
Expand Up @@ -16,6 +16,9 @@
*/
class DummyUnionType
{
private const TYPE_A = 'a';
private const TYPE_B = 'b';

/**
* @var string|int
*/
Expand All @@ -40,4 +43,14 @@ class DummyUnionType
* @var (Dummy<array<mixed, string>, (int | (string<DefaultValue>)[])> | ParentDummy | null)
*/
public $e;

/**
* @var self::TYPE_*|null
*/
public $f;

/**
* @var non-empty-array<string|int>
*/
public $g;
}
5 changes: 5 additions & 0 deletions src/Symfony/Component/PropertyInfo/Util/PhpStanTypeHelper.php
Expand Up @@ -19,6 +19,7 @@
use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;
use PHPStan\PhpDocParser\Ast\Type\CallableTypeNode;
use PHPStan\PhpDocParser\Ast\Type\CallableTypeParameterNode;
use PHPStan\PhpDocParser\Ast\Type\ConstTypeNode;
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\PhpDocParser\Ast\Type\NullableTypeNode;
Expand Down Expand Up @@ -102,6 +103,10 @@ private function extractTypes(TypeNode $node, NameScope $nameScope): array
if ($node instanceof UnionTypeNode) {
$types = [];
foreach ($node->types as $type) {
if ($type instanceof ConstTypeNode) {
// It's safer to fall back to other extractors here, as resolving const types correctly is not easy at the moment
return [];
}
foreach ($this->extractTypes($type, $nameScope) as $subType) {
$types[] = $subType;
}
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" target-language="lb" datatype="plaintext" original="security.en.xlf">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="1">
<source>An authentication exception occurred.</source>
Expand Down
Expand Up @@ -40,7 +40,7 @@ public function onLogout(LogoutEvent $event): void
}

foreach ($this->cookies as $cookieName => $cookieData) {
$response->headers->clearCookie($cookieName, $cookieData['path'], $cookieData['domain']);
$response->headers->clearCookie($cookieName, $cookieData['path'], $cookieData['domain'], $cookieData['secure'] ?? false, true, $cookieData['samesite'] ?? null);
}
}

Expand Down
@@ -0,0 +1,56 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Security\Http\Tests\EventListener;

use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\Security\Http\Event\LogoutEvent;
use Symfony\Component\Security\Http\EventListener\CookieClearingLogoutListener;

class CookieClearingLogoutListenerTest extends TestCase
{
public function testLogout()
{
$response = new Response();
$event = new LogoutEvent(new Request(), null);
$event->setResponse($response);

$listener = new CookieClearingLogoutListener(['foo' => ['path' => '/foo', 'domain' => 'foo.foo', 'secure' => true, 'samesite' => Cookie::SAMESITE_STRICT], 'foo2' => ['path' => null, 'domain' => null]]);

$cookies = $response->headers->getCookies();
$this->assertCount(0, $cookies);

$listener->onLogout($event);

$cookies = $response->headers->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
$this->assertCount(2, $cookies);

$cookie = $cookies['foo.foo']['/foo']['foo'];
$this->assertEquals('foo', $cookie->getName());
$this->assertEquals('/foo', $cookie->getPath());
$this->assertEquals('foo.foo', $cookie->getDomain());
$this->assertEquals(Cookie::SAMESITE_STRICT, $cookie->getSameSite());
$this->assertTrue($cookie->isSecure());
$this->assertTrue($cookie->isCleared());

$cookie = $cookies['']['/']['foo2'];
$this->assertStringStartsWith('foo2', $cookie->getName());
$this->assertEquals('/', $cookie->getPath());
$this->assertNull($cookie->getDomain());
$this->assertNull($cookie->getSameSite());
$this->assertFalse($cookie->isSecure());
$this->assertTrue($cookie->isCleared());
}
}
Expand Up @@ -12,8 +12,10 @@
namespace Symfony\Component\Serializer\Tests\Normalizer;

use Doctrine\Common\Annotations\AnnotationReader;
use PHPStan\PhpDocParser\Parser\PhpDocParser;
use PHPUnit\Framework\TestCase;
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
use Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor;
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
use Symfony\Component\Serializer\Exception\LogicException;
Expand Down Expand Up @@ -715,6 +717,22 @@ public function testAcceptJsonNumber()
$this->assertSame(10.0, $serializer->denormalize(['number' => 10], JsonNumber::class, 'jsonld')->number);
}

public function testDoesntHaveIssuesWithUnionConstTypes()
{
if (!class_exists(PhpStanExtractor::class) || !class_exists(PhpDocParser::class)) {
$this->markTestSkipped('phpstan/phpdoc-parser required for this test');
}

$extractor = new PropertyInfoExtractor([], [new PhpStanExtractor(), new PhpDocExtractor(), new ReflectionExtractor()]);
$normalizer = new ObjectNormalizer(null, null, null, $extractor);
$serializer = new Serializer([new ArrayDenormalizer(), new DateTimeNormalizer(), $normalizer]);

$this->assertSame('bar', $serializer->denormalize(['foo' => 'bar'], \get_class(new class() {
/** @var self::*|null */
public $foo;
}))->foo);
}

public function testExtractAttributesRespectsFormat()
{
$normalizer = new FormatAndContextAwareNormalizer();
Expand Down
Expand Up @@ -426,12 +426,16 @@ public function getResponsesForManyLocalesAndManyDomains(): \Generator
$expectedTranslatorBag = new TranslatorBag();
$expectedTranslatorBag->addCatalogue($arrayLoader->load([
'index.hello' => 'Hello',
'index.greetings' => 'Welcome, {firstname}!',
], 'en'));
$expectedTranslatorBag->addCatalogue($arrayLoader->load([
'index.greetings' => 'Welcome, {firstname}!',
], 'en', 'messages+intl-icu'));
$expectedTranslatorBag->addCatalogue($arrayLoader->load([
'index.hello' => 'Bonjour',
'index.greetings' => 'Bienvenue, {firstname} !',
], 'fr'));
$expectedTranslatorBag->addCatalogue($arrayLoader->load([
'index.greetings' => 'Bienvenue, {firstname} !',
], 'fr', 'messages+intl-icu'));
$expectedTranslatorBag->addCatalogue($arrayLoader->load([
'firstname.error' => 'Firstname must contains only letters.',
'lastname.error' => 'Lastname must contains only letters.',
Expand All @@ -443,7 +447,7 @@ public function getResponsesForManyLocalesAndManyDomains(): \Generator

yield [
['en', 'fr'],
['messages', 'validators'],
['messages', 'messages+intl-icu', 'validators'],
[
'en' => [
'messages' => <<<'XLIFF'
Expand All @@ -458,6 +462,19 @@ public function getResponsesForManyLocalesAndManyDomains(): \Generator
<source>index.hello</source>
<target state="translated">Hello</target>
</trans-unit>
</body>
</file>
</xliff>
XLIFF
,
'messages+intl-icu' => <<<'XLIFF'
<?xml version="1.0" encoding="UTF-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 http://docs.oasis-open.org/xliff/v1.2/os/xliff-core-1.2-strict.xsd">
<file original="https://localise.biz/user/symfony-translation-provider" source-language="en" datatype="database" tool-id="loco">
<header>
<tool tool-id="loco" tool-name="Loco" tool-version="1.0.25 20201211-1" tool-company="Loco"/>
</header>
<body>
<trans-unit id="loco:5fd89b8542e5aa5cc27457e2" resname="index.greetings" datatype="plaintext" extradata="loco:format=icu">
<source>index.greetings</source>
<target state="translated">Welcome, {firstname}!</target>
Expand Down Expand Up @@ -502,6 +519,19 @@ public function getResponsesForManyLocalesAndManyDomains(): \Generator
<source>index.hello</source>
<target state="translated">Bonjour</target>
</trans-unit>
</body>
</file>
</xliff>
XLIFF
,
'messages+intl-icu' => <<<'XLIFF'
<?xml version="1.0" encoding="UTF-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 http://docs.oasis-open.org/xliff/v1.2/os/xliff-core-1.2-strict.xsd">
<file original="https://localise.biz/user/symfony-translation-provider" source-language="en" datatype="database" tool-id="loco">
<header>
<tool tool-id="loco" tool-name="Loco" tool-version="1.0.25 20201211-1" tool-company="Loco"/>
</header>
<body>
<trans-unit id="loco:5fd89b8542e5aa5cc27457e2" resname="index.greetings" datatype="plaintext" extradata="loco:format=icu">
<source>index.greetings</source>
<target state="translated">Bienvenue, {firstname} !</target>
Expand Down

0 comments on commit f49cf52

Please sign in to comment.