Skip to content

Commit 77a74df

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: [Security] Fixed auth provider authenticate() cannot return void declare argument type streamed response should return $this content can be a resource
2 parents 9d66c90 + 2661da4 commit 77a74df

12 files changed

+45
-13
lines changed

src/Symfony/Component/HttpFoundation/AcceptHeader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public function first()
153153
private function sort()
154154
{
155155
if (!$this->sorted) {
156-
uasort($this->items, function ($a, $b) {
156+
uasort($this->items, function (AcceptHeaderItem $a, AcceptHeaderItem $b) {
157157
$qA = $a->getQuality();
158158
$qB = $b->getQuality();
159159

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class Request
130130
public $headers;
131131

132132
/**
133-
* @var string
133+
* @var string|resource
134134
*/
135135
protected $content;
136136

src/Symfony/Component/HttpFoundation/StreamedResponse.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ public function setCallback($callback)
8383
public function sendHeaders()
8484
{
8585
if ($this->headersSent) {
86-
return;
86+
return $this;
8787
}
8888

8989
$this->headersSent = true;
9090

91-
parent::sendHeaders();
91+
return parent::sendHeaders();
9292
}
9393

9494
/**
@@ -99,7 +99,7 @@ public function sendHeaders()
9999
public function sendContent()
100100
{
101101
if ($this->streamed) {
102-
return;
102+
return $this;
103103
}
104104

105105
$this->streamed = true;
@@ -109,6 +109,8 @@ public function sendContent()
109109
}
110110

111111
call_user_func($this->callback);
112+
113+
return $this;
112114
}
113115

114116
/**

src/Symfony/Component/HttpFoundation/Tests/StreamedResponseTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,15 @@ public function testCreate()
121121
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response);
122122
$this->assertEquals(204, $response->getStatusCode());
123123
}
124+
125+
public function testReturnThis()
126+
{
127+
$response = new StreamedResponse(function () {});
128+
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendContent());
129+
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendContent());
130+
131+
$response = new StreamedResponse(function () {});
132+
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendHeaders());
133+
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendHeaders());
134+
}
124135
}

src/Symfony/Component/Security/Core/Authentication/Provider/AnonymousAuthenticationProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Security\Core\Authentication\Provider;
1313

1414
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
15+
use Symfony\Component\Security\Core\Exception\AuthenticationException;
1516
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
1617
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
1718

@@ -44,7 +45,7 @@ public function __construct($secret)
4445
public function authenticate(TokenInterface $token)
4546
{
4647
if (!$this->supports($token)) {
47-
return;
48+
throw new AuthenticationException('The token is not supported by this authentication provider.');
4849
}
4950

5051
if ($this->secret !== $token->getSecret()) {

src/Symfony/Component/Security/Core/Authentication/Provider/PreAuthenticatedAuthenticationProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Security\Core\User\UserProviderInterface;
1515
use Symfony\Component\Security\Core\User\UserCheckerInterface;
16+
use Symfony\Component\Security\Core\Exception\AuthenticationException;
1617
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
1718
use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken;
1819
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
@@ -51,7 +52,7 @@ public function __construct(UserProviderInterface $userProvider, UserCheckerInte
5152
public function authenticate(TokenInterface $token)
5253
{
5354
if (!$this->supports($token)) {
54-
return;
55+
throw new AuthenticationException('The token is not supported by this authentication provider.');
5556
}
5657

5758
if (!$user = $token->getUser()) {

src/Symfony/Component/Security/Core/Authentication/Provider/RememberMeAuthenticationProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Security\Core\User\UserCheckerInterface;
1515
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1616
use Symfony\Component\Security\Core\Authentication\Token\RememberMeToken;
17+
use Symfony\Component\Security\Core\Exception\AuthenticationException;
1718
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
1819

1920
class RememberMeAuthenticationProvider implements AuthenticationProviderInterface
@@ -40,7 +41,7 @@ public function __construct(UserCheckerInterface $userChecker, $secret, $provide
4041
public function authenticate(TokenInterface $token)
4142
{
4243
if (!$this->supports($token)) {
43-
return;
44+
throw new AuthenticationException('The token is not supported by this authentication provider.');
4445
}
4546

4647
if ($this->secret !== $token->getSecret()) {

src/Symfony/Component/Security/Core/Authentication/Provider/UserAuthenticationProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function __construct(UserCheckerInterface $userChecker, $providerKey, $hi
5656
public function authenticate(TokenInterface $token)
5757
{
5858
if (!$this->supports($token)) {
59-
return;
59+
throw new AuthenticationException('The token is not supported by this authentication provider.');
6060
}
6161

6262
$username = $token->getUsername();

src/Symfony/Component/Security/Core/Tests/Authentication/Provider/AnonymousAuthenticationProviderTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ public function testSupports()
2424
$this->assertFalse($provider->supports($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
2525
}
2626

27+
/**
28+
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationException
29+
* @expectedExceptionMessage The token is not supported by this authentication provider.
30+
*/
2731
public function testAuthenticateWhenTokenIsNotSupported()
2832
{
2933
$provider = $this->getProvider('foo');
3034

31-
$this->assertNull($provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
35+
$provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock());
3236
}
3337

3438
/**

src/Symfony/Component/Security/Core/Tests/Authentication/Provider/PreAuthenticatedAuthenticationProviderTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,15 @@ public function testSupports()
3636
$this->assertFalse($provider->supports($token));
3737
}
3838

39+
/**
40+
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationException
41+
* @expectedExceptionMessage The token is not supported by this authentication provider.
42+
*/
3943
public function testAuthenticateWhenTokenIsNotSupported()
4044
{
4145
$provider = $this->getProvider();
4246

43-
$this->assertNull($provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
47+
$provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock());
4448
}
4549

4650
/**

0 commit comments

Comments
 (0)