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
This commit is contained in:
commit
77a74df487
@ -153,7 +153,7 @@ class AcceptHeader
|
||||
private function sort()
|
||||
{
|
||||
if (!$this->sorted) {
|
||||
uasort($this->items, function ($a, $b) {
|
||||
uasort($this->items, function (AcceptHeaderItem $a, AcceptHeaderItem $b) {
|
||||
$qA = $a->getQuality();
|
||||
$qB = $b->getQuality();
|
||||
|
||||
|
@ -130,7 +130,7 @@ class Request
|
||||
public $headers;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @var string|resource
|
||||
*/
|
||||
protected $content;
|
||||
|
||||
|
@ -83,12 +83,12 @@ class StreamedResponse extends Response
|
||||
public function sendHeaders()
|
||||
{
|
||||
if ($this->headersSent) {
|
||||
return;
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->headersSent = true;
|
||||
|
||||
parent::sendHeaders();
|
||||
return parent::sendHeaders();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -99,7 +99,7 @@ class StreamedResponse extends Response
|
||||
public function sendContent()
|
||||
{
|
||||
if ($this->streamed) {
|
||||
return;
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->streamed = true;
|
||||
@ -109,6 +109,8 @@ class StreamedResponse extends Response
|
||||
}
|
||||
|
||||
call_user_func($this->callback);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -121,4 +121,15 @@ class StreamedResponseTest extends TestCase
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response);
|
||||
$this->assertEquals(204, $response->getStatusCode());
|
||||
}
|
||||
|
||||
public function testReturnThis()
|
||||
{
|
||||
$response = new StreamedResponse(function () {});
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendContent());
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendContent());
|
||||
|
||||
$response = new StreamedResponse(function () {});
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendHeaders());
|
||||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendHeaders());
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace Symfony\Component\Security\Core\Authentication\Provider;
|
||||
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
||||
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
|
||||
|
||||
@ -44,7 +45,7 @@ class AnonymousAuthenticationProvider implements AuthenticationProviderInterface
|
||||
public function authenticate(TokenInterface $token)
|
||||
{
|
||||
if (!$this->supports($token)) {
|
||||
return;
|
||||
throw new AuthenticationException('The token is not supported by this authentication provider.');
|
||||
}
|
||||
|
||||
if ($this->secret !== $token->getSecret()) {
|
||||
|
@ -13,6 +13,7 @@ namespace Symfony\Component\Security\Core\Authentication\Provider;
|
||||
|
||||
use Symfony\Component\Security\Core\User\UserProviderInterface;
|
||||
use Symfony\Component\Security\Core\User\UserCheckerInterface;
|
||||
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
||||
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
@ -51,7 +52,7 @@ class PreAuthenticatedAuthenticationProvider implements AuthenticationProviderIn
|
||||
public function authenticate(TokenInterface $token)
|
||||
{
|
||||
if (!$this->supports($token)) {
|
||||
return;
|
||||
throw new AuthenticationException('The token is not supported by this authentication provider.');
|
||||
}
|
||||
|
||||
if (!$user = $token->getUser()) {
|
||||
|
@ -14,6 +14,7 @@ namespace Symfony\Component\Security\Core\Authentication\Provider;
|
||||
use Symfony\Component\Security\Core\User\UserCheckerInterface;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\RememberMeToken;
|
||||
use Symfony\Component\Security\Core\Exception\AuthenticationException;
|
||||
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
|
||||
|
||||
class RememberMeAuthenticationProvider implements AuthenticationProviderInterface
|
||||
@ -40,7 +41,7 @@ class RememberMeAuthenticationProvider implements AuthenticationProviderInterfac
|
||||
public function authenticate(TokenInterface $token)
|
||||
{
|
||||
if (!$this->supports($token)) {
|
||||
return;
|
||||
throw new AuthenticationException('The token is not supported by this authentication provider.');
|
||||
}
|
||||
|
||||
if ($this->secret !== $token->getSecret()) {
|
||||
|
@ -56,7 +56,7 @@ abstract class UserAuthenticationProvider implements AuthenticationProviderInter
|
||||
public function authenticate(TokenInterface $token)
|
||||
{
|
||||
if (!$this->supports($token)) {
|
||||
return;
|
||||
throw new AuthenticationException('The token is not supported by this authentication provider.');
|
||||
}
|
||||
|
||||
$username = $token->getUsername();
|
||||
|
@ -24,11 +24,15 @@ class AnonymousAuthenticationProviderTest extends TestCase
|
||||
$this->assertFalse($provider->supports($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationException
|
||||
* @expectedExceptionMessage The token is not supported by this authentication provider.
|
||||
*/
|
||||
public function testAuthenticateWhenTokenIsNotSupported()
|
||||
{
|
||||
$provider = $this->getProvider('foo');
|
||||
|
||||
$this->assertNull($provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
|
||||
$provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,11 +36,15 @@ class PreAuthenticatedAuthenticationProviderTest extends TestCase
|
||||
$this->assertFalse($provider->supports($token));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationException
|
||||
* @expectedExceptionMessage The token is not supported by this authentication provider.
|
||||
*/
|
||||
public function testAuthenticateWhenTokenIsNotSupported()
|
||||
{
|
||||
$provider = $this->getProvider();
|
||||
|
||||
$this->assertNull($provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
|
||||
$provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,12 +26,16 @@ class RememberMeAuthenticationProviderTest extends TestCase
|
||||
$this->assertFalse($provider->supports($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationException
|
||||
* @expectedExceptionMessage The token is not supported by this authentication provider.
|
||||
*/
|
||||
public function testAuthenticateWhenTokenIsNotSupported()
|
||||
{
|
||||
$provider = $this->getProvider();
|
||||
|
||||
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
|
||||
$this->assertNull($provider->authenticate($token));
|
||||
$provider->authenticate($token);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,11 +29,15 @@ class UserAuthenticationProviderTest extends TestCase
|
||||
$this->assertFalse($provider->supports($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationException
|
||||
* @expectedExceptionMessage The token is not supported by this authentication provider.
|
||||
*/
|
||||
public function testAuthenticateWhenTokenIsNotSupported()
|
||||
{
|
||||
$provider = $this->getProvider();
|
||||
|
||||
$this->assertNull($provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
|
||||
$provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user