8000 Merge branch '5.1' · symfony/symfony@27bb282 · GitHub
[go: up one dir, main page]

Skip to content

Commit 27bb282

Browse files
committed
Merge branch '5.1'
* 5.1: Backport: Improve link script with rollback when using symlink fix more numeric cases changing in PHP 8 Fixed autoLogin() returning null [Notifier] add doc for free mobile dsn
2 parents 160b598 + 216f2fa commit 27bb282

File tree

4 files changed

+30
-30
lines changed

4 files changed

+30
-30
lines changed

src/Symfony/Component/Security/Http/Authenticator/RememberMeAuthenticator.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use Symfony\Component\Security\Core\Exception\AuthenticationException;
2020
use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface;
2121
use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport;
22-
use Symfony\Component\Security\Http\RememberMe\AbstractRememberMeServices;
2322
use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface;
2423

2524
/**
@@ -57,21 +56,23 @@ public function supports(Request $request): ?bool
5756
return false;
5857
}
5958

60-
if (($cookie = $request->attributes->get(AbstractRememberMeServices::COOKIE_ATTR_NAME)) && null === $cookie->getValue()) {
59+
$token = $this->rememberMeServices->autoLogin($request);
60+
if (null === $token) {
6161
return false;
6262
}
6363

64-
if (isset($this->options['name']) && !$request->cookies->has($this->options['name'])) {
65-
return false;
66-
}
64+
$request->attributes->set('_remember_me_token', $token);
6765

6866
// the `null` return value indicates that this authenticator supports lazy firewalls
6967
return null;
7068
}
7169

7270
public function authenticate(Request $request): PassportInterface
7371
{
74-
$token = $this->rememberMeServices->autoLogin($request);
72+
$token = $request->attributes->get('_remember_me_token');
73+
if (null === $token) {
74+
throw new \LogicException('No remember me token is set.');
75+
}
7576

7677
return new SelfValidatingPassport($token->getUser());
7778
}

src/Symfony/Component/Security/Http/Tests/Authenticator/RememberMeAuthenticatorTest.php

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@
1212
namespace Symfony\Component\Security\Http\Tests\Authenticator;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Component\HttpFoundation\Cookie;
1615
use Symfony\Component\HttpFoundation\Request;
1716
use Symfony\Component\Security\Core\Authentication\Token\RememberMeToken;
1817
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
1918
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
2019
use Symfony\Component\Security\Core\User\User;
2120
use Symfony\Component\Security\Http\Authenticator\RememberMeAuthenticator;
22-
use Symfony\Component\Security\Http\RememberMe\AbstractRememberMeServices;
2321
use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface;
2422

2523
class RememberMeAuthenticatorTest extends TestCase
@@ -37,8 +35,6 @@ protected function setUp(): void
3735
'name' => '_remember_me_cookie',
3836
]);
3937
$this->request = new Request();
40-
$this->request->cookies->set('_remember_me_cookie', $val = $this->generateCookieValue());
41-
$this->request->attributes->set(AbstractRememberMeServices::COOKIE_ATTR_NAME, new Cookie('_remember_me_cookie', $val));
4238
}
4339

4440
public function testSupportsTokenStorageWithToken()
@@ -48,39 +44,34 @@ public function testSupportsTokenStorageWithToken()
4844
$this->assertFalse($this->authenticator->supports($this->request));
4945
}
5046

51-
public function testSupportsRequestWithoutAttribute()
47+
/**
48+
* @dataProvider provideSupportsData
49+
*/
50+
public function testSupports($autoLoginResult, $support)
5251
{
53-
$this->request->attributes->remove(AbstractRememberMeServices::COOKIE_ATTR_NAME);
52+
$this->rememberMeServices->expects($this->once())->method('autoLogin')->with($this->request)->willReturn($autoLoginResult);
5453

55-
$this->assertNull($this->authenticator->supports($this->request));
54+
$this->assertSame($support, $this->authenticator->supports($this->request));
5655
}
5756

58-
public function testSupportsRequestWithoutCookie()
57+
public function provideSupportsData()
5958
{
60-
$this->request->cookies->remove('_remember_me_cookie');
61-
62-
$this->assertFalse($this->authenticator->supports($this->request));
63-
}
64-
65-
public function testSupports()
66-
{
67-
$this->assertNull($this->authenticator->supports($this->request));
59+
yield [null, false];
60+
yield [$this->createMock(TokenInterface::class), null];
6861
}
6962

7063
public function testAuthenticate()
7164
{
72-
$this->rememberMeServices->expects($this->once())
73-
->method('autoLogin')
74-
->with($this->request)
75-
->willReturn(new RememberMeToken($user = new User('wouter', 'test'), 'main', 'secret'));
76-
65+
$this->request->attributes->set('_remember_me_token', new RememberMeToken($user = new User('wouter', 'test'), 'main', 'secret'));
7766
$passport = $this->authenticator->authenticate($this->request);
7867

7968
$this->assertSame($user, $passport->getUser());
8069
}
8170

82-
private function generateCookieValue()
71+
public function testAuthenticateWithoutToken()
8372
{
84-
return base64_encode(implode(AbstractRememberMeServices::COOKIE_DELIMITER, ['part1', 'part2']));
73+
$this->expectException(\LogicException::class);
74+
75+
$this->authenticator->authenticate($this->request);
8576
}
8677
}

src/Symfony/Component/Yaml/Inline.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public static function dump($value, int $flags = 0): string
161161
return 'false';
162162
case< D5F9 /span> ctype_digit($value):
163163
return \is_string($value) ? "'$value'" : (int) $value;
164-
case is_numeric($value) && false === strpos($value, "\n"):
164+
case is_numeric($value) && false === strpos($value, "\f") && false === strpos($value, "\n") && false === strpos($value, "\r") && false === strpos($value, "\t") && false === strpos($value, "\v"):
165165
$locale = setlocale(LC_NUMERIC, 0);
166166
if (false !== $locale) {
167167
setlocale(LC_NUMERIC, 'C');

src/Symfony/Component/Yaml/Tests/InlineTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,14 @@ public function getTestsForDump()
506506
['[foo, \'@foo.baz\', { \'%foo%\': \'foo is %foo%\', bar: \'%foo%\' }, true, \'@service_container\']', ['foo', '@foo.baz', ['%foo%' => 'foo is %foo%', 'bar' => '%foo%'], true, '@service_container']],
507507

508508
['{ foo: { bar: { 1: 2, baz: 3 } } }', ['foo' => ['bar' => [1 => 2, 'baz' => 3]]]],
509+
510+
// numeric strings with trailing whitespaces
511+
["'0123 '", '0123 '],
512+
['"0123\f"', "0123\f"],
513+
['"0123\n"', "0123\n"],
514+
['"0123\r"', "0123\r"],
515+
['"0123\t"', "0123\t"],
516+
['"0123\v"', "0123\v"],
509517
];
510518
}
511519

0 commit comments

Comments
 (0)
0