Skip to content

Commit 0920bb5

Browse files
Merge branch '6.4' into 7.1
* 6.4: [HttpClient] Fix processing a NativeResponse after its client has been reset [Security] Throw an explicit error when authenticating a token with a null user translation to hebrew
2 parents 39b5b8f + 7e396bb commit 0920bb5

File tree

6 files changed

+85
-20
lines changed

6 files changed

+85
-20
lines changed

src/Symfony/Component/HttpClient/Response/NativeResponse.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function __construct(
7979
};
8080

8181
$this->canary = new Canary(static function () use ($multi, $id) {
82-
if (null !== ($host = $multi->openHandles[$id][6] ?? null) && 0 >= --$multi->hosts[$host]) {
82+
if (null !== ($host = $multi->openHandles[$id][6] ?? null) && isset($multi->hosts[$host]) && 0 >= --$multi->hosts[$host]) {
8383
unset($multi->hosts[$host]);
8484
}
8585
unset($multi->openHandles[$id], $multi->handlesActivity[$id]);
@@ -123,7 +123,7 @@ private function open(): void
123123
throw new TransportException($msg);
124124
}
125125

126-
$this->logger?->info(sprintf('%s for "%s".', $msg, $url ?? $this->url));
126+
$this->logger?->info(\sprintf('%s for "%s".', $msg, $url ?? $this->url));
127127
});
128128

129129
try {
@@ -142,7 +142,7 @@ private function open(): void
142142
$this->info['request_header'] = $this->info['url']['path'].$this->info['url']['query'];
143143
}
144144

145-
$this->info['request_header'] = sprintf("> %s %s HTTP/%s \r\n", $context['http']['method'], $this->info['request_header'], $context['http']['protocol_version']);
145+
$this->info['request_header'] = \sprintf("> %s %s HTTP/%s \r\n", $context['http']['method'], $this->info['request_header'], $context['http']['protocol_version']);
146146
$this->info['request_header'] .= implode("\r\n", $context['http']['header'])."\r\n\r\n";
147147

148148
if (\array_key_exists('peer_name', $context['ssl']) && null === $context['ssl']['peer_name']) {
@@ -159,7 +159,7 @@ private function open(): void
159159
break;
160160
}
161161

162-
$this->logger?->info(sprintf('Redirecting: "%s %s"', $this->info['http_code'], $url ?? $this->url));
162+
$this->logger?->info(\sprintf('Redirecting: "%s %s"', $this->info['http_code'], $url ?? $this->url));
163163
}
164164
} catch (\Throwable $e) {
165165
$this->close();
@@ -294,15 +294,15 @@ private static function perform(ClientState $multi, ?array &$responses = null):
294294

295295
if (null === $e) {
296296
if (0 < $remaining) {
297-
$e = new TransportException(sprintf('Transfer closed with %s bytes remaining to read.', $remaining));
297+
$e = new TransportException(\sprintf('Transfer closed with %s bytes remaining to read.', $remaining));
298298
} elseif (-1 === $remaining && fwrite($buffer, '-') && '' !== stream_get_contents($buffer, -1, 0)) {
299299
$e = new TransportException('Transfer closed with outstanding data remaining from chunked response.');
300300
}
301301
}
302302

303303
$multi->handlesActivity[$i][] = null;
304304
$multi->handlesActivity[$i][] = $e;
305-
if (null !== ($host = $multi->openHandles[$i][6] ?? null) && 0 >= --$multi->hosts[$host]) {
305+
if (null !== ($host = $multi->openHandles[$i][6] ?? null) && isset($multi->hosts[$host]) && 0 >= --$multi->hosts[$host]) {
306306
unset($multi->hosts[$host]);
307307
}
308308
unset($multi->openHandles[$i]);

src/Symfony/Component/HttpClient/Tests/HttpClientTestCase.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,4 +700,17 @@ public function testPostToGetRedirect(int $status)
700700
$this->assertSame('GET', $body['REQUEST_METHOD']);
701701
$this->assertSame('/', $body['REQUEST_URI']);
702702
}
703+
704+
public function testResponseCanBeProcessedAfterClientReset()
705+
{
706+
$client = $this->getHttpClient(__FUNCTION__);
707+
$response = $client->request('GET', 'http://127.0.0.1:8057/timeout-body');
708+
$stream = $client->stream($response);
709+
710+
$response->getStatusCode();
711+
$client->reset();
712+
$stream->current();
713+
714+
$this->addToAssertionCount(1);
715+
}
703716
}

src/Symfony/Component/Security/Http/Firewall/ContextListener.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ public function authenticate(RequestEvent $event): void
123123
]);
124124

125125
if ($token instanceof TokenInterface) {
126+
if (!$token->getUser()) {
127+
throw new \UnexpectedValueException(\sprintf('Cannot authenticate a "%s" token because it doesn\'t store a user.', $token::class));
128+
}
129+
126130
$originalToken = $token;
127131
$token = $this->refreshUser($token);
128132

src/Symfony/Component/Security/Http/Tests/Firewall/ContextListenerTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use Symfony\Component\Security\Core\User\UserInterface;
3737
use Symfony\Component\Security\Core\User\UserProviderInterface;
3838
use Symfony\Component\Security\Http\Firewall\ContextListener;
39+
use Symfony\Component\Security\Http\Tests\Fixtures\NullUserToken;
3940
use Symfony\Contracts\Service\ServiceLocatorTrait;
4041

4142
class ContextListenerTest extends TestCase
@@ -58,6 +59,30 @@ public function testUserProvidersNeedToImplementAnInterface()
5859
$this->handleEventWithPreviousSession([new \stdClass()]);
5960
}
6061

62+
public function testTokenReturnsNullUser()
63+
{
64+
$tokenStorage = new TokenStorage();
65+
$tokenStorage->setToken(new NullUserToken());
66+
67+
$session = new Session(new MockArraySessionStorage());
68+
$session->set('_security_context_key', serialize($tokenStorage->getToken()));
69+
70+
$request = new Request();
71+
$request->setSession($session);
72+
$request->cookies->set('MOCKSESSID', true);
73+
74+
$listener = new ContextListener($tokenStorage, [], 'context_key');
75+
76+
$this->expectException(\UnexpectedValueException::class);
77+
$this->expectExceptionMessage('Cannot authenticate a "Symfony\Component\Security\Http\Tests\Fixtures\NullUserToken" token because it doesn\'t store a user.');
78+
79+
$listener->authenticate(new RequestEvent(
80+
$this->createMock(HttpKernelInterface::class),
81+
$request,
82+
HttpKernelInterface::MAIN_REQUEST,
83+
));
84+
}
85+
6186
public function testOnKernelResponseWillAddSession()
6287
{
6388
$session = $this->runSessionOnKernelResponse(
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Security\Http\Tests\Fixtures;
13+
14+
use Symfony\Component\Security\Core\Authentication\Token\AbstractToken;
15+
use Symfony\Component\Security\Core\User\UserInterface;
16+
17+
class NullUserToken extends AbstractToken
18+
{
19+
public function getUser(): ?UserInterface
20+
{
21+
return null;
22+
}
23+
}

src/Symfony/Component/Validator/Resources/translations/validators.he.xlf

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
</trans-unit>
137137
<trans-unit id="37" resname="This is not a valid IP address.">
138138
<source>This value is not a valid IP address.</source>
139-
<target state="needs-review-translation">ערך זה אינו כתובת IP תקפה.</target>
139+
<target>ערך זה אינו כתובת IP תקפה.</target>
140140
</trans-unit>
141141
<trans-unit id="38">
142142
<source>This value is not a valid language.</source>
@@ -192,7 +192,7 @@
192192
</trans-unit>
193193
<trans-unit id="51" resname="No temporary folder was configured in php.ini.">
194194
<source>No temporary folder was configured in php.ini, or the configured folder does not exist.</source>
195-
<target state="needs-review-translation">לא הוגדרה תיקייה זמנית ב-php.ini, או שהתיקייה המוגדרת אינה קיימת.</target>
195+
<target>לא הוגדרה תיקייה זמנית ב-php.ini, או שהתיקייה המוגדרת אינה קיימת.</target>
196196
</trans-unit>
197197
<trans-unit id="52">
198198
<source>Cannot write temporary file to disk.</source>
@@ -224,7 +224,7 @@
224224
</trans-unit>
225225
<trans-unit id="59" resname="This is not a valid International Bank Account Number (IBAN).">
226226
<source>This value is not a valid International Bank Account Number (IBAN).</source>
227-
<target state="needs-review-translation">ערך זה אינו מספר חשבון בנק בינלאומי (IBAN) תקף.</target>
227+
<target>ערך זה אינו מספר זה"ב (IBAN) תקף.</target>
228228
</trans-unit>
229229
<trans-unit id="60">
230230
<source>This value is not a valid ISBN-10.</source>
@@ -312,15 +312,15 @@
312312
</trans-unit>
313313
<trans-unit id="81" resname="This is not a valid Business Identifier Code (BIC).">
314314
<source>This value is not a valid Business Identifier Code (BIC).</source>
315-
<target state="needs-review-translation">ערך זה אינו קוד מזהה עסקי (BIC) תקף.</target>
315+
<target>ערך זה אינו קוד מזהה עסקי (BIC) תקף.</target>
316316
</trans-unit>
317317
<trans-unit id="82">
318318
<source>Error</source>
319319
<target>שגיאה</target>
320320
</trans-unit>
321321
<trans-unit id="83" resname="This is not a valid UUID.">
322322
<source>This value is not a valid UUID.</source>
323-
<target state="needs-review-translation">ערך זה אינו UUID תקף.</target>
323+
<target>ערך זה אינו UUID תקף.</target>
324324
</trans-unit>
325325
<trans-unit id="84">
326326
<source>This value should be a multiple of {{ compared_value }}.</source>
@@ -404,39 +404,39 @@
404404
</trans-unit>
405405
<trans-unit id="104">
406406
<source>The filename is too long. It should have {{ filename_max_length }} character or less.|The filename is too long. It should have {{ filename_max_length }} characters or less.</source>
407-
<target state="needs-review-translation">שם הקובץ ארוך מדי. עליו להכיל {{ filename_max_length }} תווים או פחות.</target>
407+
<target>שם הקובץ ארוך מדי. עליו להכיל {{ filename_max_length }} תווים או פחות.</target>
408408
</trans-unit>
409409
<trans-unit id="105">
410410
<source>The password strength is too low. Please use a stronger password.</source>
411-
<target state="needs-review-translation">חוזק הסיסמה נמוך מדי. אנא השתמש בסיסמה חזקה יותר.</target>
411+
<target>חוזק הסיסמה נמוך מדי. אנא השתמש בסיסמה חזקה יותר.</target>
412412
</trans-unit>
413413
<trans-unit id="106">
414414
<source>This value contains characters that are not allowed by the current restriction-level.</source>
415-
<target state="needs-review-translation">הערך כולל תווים שאינם מותרים על פי רמת ההגבלה הנוכחית.</target>
415+
<target>הערך כולל תווים שאינם מותרים על פי רמת ההגבלה הנוכחית.</target>
416416
</trans-unit>
417417
<trans-unit id="107">
418418
<source>Using invisible characters is not allowed.</source>
419-
<target state="needs-review-translation">אסור להשתמש בתווים בלתי נראים.</target>
419+
<target>אסור להשתמש בתווים בלתי נראים.</target>
420420
</trans-unit>
421421
<trans-unit id="108">
422422
<source>Mixing numbers from different scripts is not allowed.</source>
423-
<target state="needs-review-translation">אסור לערבב מספרים מתסריטים שונים.</target>
423+
<target>אסור לערבב מספרים מסקריפטים שונים.</target>
424424
</trans-unit>
425425
<trans-unit id="109">
426426
<source>Using hidden overlay characters is not allowed.</source>
427-
<target state="needs-review-translation">אסור להשתמש בתווים מוסתרים של חפיפה.</target>
427+
<target>אסור להשתמש בתווים חופפים נסתרים.</target>
428428
</trans-unit>
429429
<trans-unit id="110">
430430
<source>The extension of the file is invalid ({{ extension }}). Allowed extensions are {{ extensions }}.</source>
431-
<target state="needs-review-translation">סיומת הקובץ אינה תקינה ({{ extension }}). הסיומות המותרות הן {{ extensions }}.</target>
431+
<target>סיומת הקובץ אינה תקינה ({{ extension }}). הסיומות המותרות הן {{ extensions }}.</target>
432432
</trans-unit>
433433
<trans-unit id="111">
434434
<source>The detected character encoding is invalid ({{ detected }}). Allowed encodings are {{ encodings }}.</source>
435-
<target state="needs-review-translation">קידוד התווים שזוהה אינו חוקי ({{ detected }}). הקידודים המותרים הם {{ encodings }}.</target>
435+
<target>קידוד התווים שזוהה אינו חוקי ({{ detected }}). הקידודים המותרים הם {{ encodings }}.</target>
436436
</trans-unit>
437437
<trans-unit id="112">
438438
<source>This value is not a valid MAC address.</source>
439-
<target state="needs-review-translation">ערך זה אינו כתובת MAC תקפה.</target>
439+
<target>ערך זה אינו כתובת MAC תקפה.</target>
440440
</trans-unit>
441441
<trans-unit id="113">
442442
<source>This URL is missing a top-level domain.</source>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy