Skip to content

Commit

Permalink
Merge branch '2.8' into 3.4
Browse files Browse the repository at this point in the history
* 2.8:
  removed unneeded comments in tests
  Change PHPDoc in ResponseHeaderBag::getCookies() to help IDEs
  [HttpKernel] Set first trusted proxy as REMOTE_ADDR in InlineFragmentRenderer.
  [Process] Consider \"executable\" suffixes first on Windows
  Triggering RememberMe's loginFail() when token cannot be created
  • Loading branch information
fabpot committed May 30, 2018
2 parents 3114ffb + fa7bec4 commit 10580f1
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 66 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public function removeCookie($name, $path = '/', $domain = null)
*
* @param string $format
*
* @return array
* @return Cookie[]
*
* @throws \InvalidArgumentException When the $format is invalid
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ protected function createSubRequest($uri, Request $request)
// Do nothing
}

$server['REMOTE_ADDR'] = '127.0.0.1';
$trustedProxies = Request::getTrustedProxies();
$server['REMOTE_ADDR'] = $trustedProxies ? reset($trustedProxies) : '127.0.0.1';

unset($server['HTTP_IF_MODIFIED_SINCE']);
unset($server['HTTP_IF_NONE_MATCH']);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function testRenderWithObjectsAsAttributes()
$subRequest->attributes->replace(array('object' => $object, '_format' => 'html', '_controller' => 'main_controller', '_locale' => 'en'));
$subRequest->headers->set('x-forwarded-for', array('127.0.0.1'));
$subRequest->server->set('HTTP_X_FORWARDED_FOR', '127.0.0.1');
$subRequest->server->set('REMOTE_ADDR', '1.1.1.1');

$strategy = new InlineFragmentRenderer($this->getKernelExpectingRequest($subRequest));

Expand Down Expand Up @@ -99,7 +100,7 @@ public function testRenderWithTrustedHeaderDisabled()
{
Request::setTrustedProxies(array(), 0);

$strategy = new InlineFragmentRenderer($this->getKernelExpectingRequest(Request::create('/')));
$strategy = new InlineFragmentRenderer($this->getKernelExpectingRequest(Request::create('/', 'GET', array(), array(), array(), array('REMOTE_ADDR' => '1.1.1.1'))));
$this->assertSame('foo', $strategy->render('/', Request::create('/'))->getContent());

Request::setTrustedProxies(array(), -1);
Expand Down Expand Up @@ -187,6 +188,7 @@ public function testESIHeaderIsKeptInSubrequest()
{
$expectedSubRequest = Request::create('/');
$expectedSubRequest->headers->set('Surrogate-Capability', 'abc="ESI/1.0"');
$expectedSubRequest->server->set('REMOTE_ADDR', '1.1.1.1');

if (Request::HEADER_X_FORWARDED_FOR & Request::getTrustedHeaderSet()) {
$expectedSubRequest->headers->set('x-forwarded-for', array('127.0.0.1'));
Expand All @@ -211,7 +213,7 @@ public function testESIHeaderIsKeptInSubrequestWithTrustedHeaderDisabled()

public function testHeadersPossiblyResultingIn304AreNotAssignedToSubrequest()
{
$expectedSubRequest = Request::create('/');
$expectedSubRequest = Request::create('/', 'GET', array(), array(), array(), array('REMOTE_ADDR' => '1.1.1.1'));
if (Request::HEADER_X_FORWARDED_FOR & Request::getTrustedHeaderSet()) {
$expectedSubRequest->headers->set('x-forwarded-for', array('127.0.0.1'));
$expectedSubRequest->server->set('HTTP_X_FORWARDED_FOR', '127.0.0.1');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ protected function setUp()
$this->resolver = new OptionsResolver();
}

////////////////////////////////////////////////////////////////////////////
// resolve()
////////////////////////////////////////////////////////////////////////////

/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException
* @expectedExceptionMessage The option "foo" does not exist. Defined options are: "a", "z".
Expand Down Expand Up @@ -69,10 +65,6 @@ public function testResolveFailsFromLazyOption()
$this->resolver->resolve();
}

////////////////////////////////////////////////////////////////////////////
// setDefault()/hasDefault()
////////////////////////////////////////////////////////////////////////////

public function testSetDefaultReturnsThis()
{
$this->assertSame($this->resolver, $this->resolver->setDefault('foo', 'bar'));
Expand Down Expand Up @@ -115,10 +107,6 @@ public function testHasDefaultWithNullValue()
$this->assertTrue($this->resolver->hasDefault('foo'));
}

////////////////////////////////////////////////////////////////////////////
// lazy setDefault()
////////////////////////////////////////////////////////////////////////////

public function testSetLazyReturnsThis()
{
$this->assertSame($this->resolver, $this->resolver->setDefault('foo', function (Options $options) {}));
Expand Down Expand Up @@ -232,10 +220,6 @@ public function testInvokeEachLazyOptionOnlyOnce()
$this->assertSame(2, $calls);
}

////////////////////////////////////////////////////////////////////////////
// setRequired()/isRequired()/getRequiredOptions()
////////////////////////////////////////////////////////////////////////////

public function testSetRequiredReturnsThis()
{
$this->assertSame($this->resolver, $this->resolver->setRequired('foo'));
Expand Down Expand Up @@ -330,10 +314,6 @@ public function testGetRequiredOptions()
$this->assertSame(array('foo', 'bar'), $this->resolver->getRequiredOptions());
}

////////////////////////////////////////////////////////////////////////////
// isMissing()/getMissingOptions()
////////////////////////////////////////////////////////////////////////////

public function testIsMissingIfNotSet()
{
$this->assertFalse($this->resolver->isMissing('foo'));
Expand Down Expand Up @@ -373,10 +353,6 @@ public function testGetMissingOptions()
$this->assertSame(array('bar'), $this->resolver->getMissingOptions());
}

////////////////////////////////////////////////////////////////////////////
// setDefined()/isDefined()/getDefinedOptions()
////////////////////////////////////////////////////////////////////////////

/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException
*/
Expand Down Expand Up @@ -474,10 +450,6 @@ public function testClearedOptionsAreNotDefined()
$this->assertFalse($this->resolver->isDefined('foo'));
}

////////////////////////////////////////////////////////////////////////////
// setAllowedTypes()
////////////////////////////////////////////////////////////////////////////

/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException
*/
Expand Down Expand Up @@ -748,10 +720,6 @@ public function testAddAllowedTypesDoesNotOverwrite2()
$this->assertNotEmpty($this->resolver->resolve());
}

////////////////////////////////////////////////////////////////////////////
// setAllowedValues()
////////////////////////////////////////////////////////////////////////////

/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException
*/
Expand Down Expand Up @@ -903,10 +871,6 @@ function () { return false; },
$this->assertEquals(array('foo' => 'bar'), $this->resolver->resolve());
}

////////////////////////////////////////////////////////////////////////////
// addAllowedValues()
////////////////////////////////////////////////////////////////////////////

/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException
*/
Expand Down Expand Up @@ -1023,10 +987,6 @@ public function testResolveSucceedsIfAnyAddedClosureReturnsTrue2()
$this->assertEquals(array('foo' => 'bar'), $this->resolver->resolve());
}

////////////////////////////////////////////////////////////////////////////
// setNormalizer()
////////////////////////////////////////////////////////////////////////////

public function testSetNormalizerReturnsThis()
{
$this->resolver->setDefault('foo', 'bar');
Expand Down Expand Up @@ -1278,10 +1238,6 @@ public function testNormalizerNotCalledForUnsetOptions()
$this->assertEmpty($this->resolver->resolve());
}

////////////////////////////////////////////////////////////////////////////
// setDefaults()
////////////////////////////////////////////////////////////////////////////

public function testSetDefaultsReturnsThis()
{
$this->assertSame($this->resolver, $this->resolver->setDefaults(array('foo', 'bar')));
Expand Down Expand Up @@ -1316,10 +1272,6 @@ public function testFailIfSetDefaultsFromLazyOption()
$this->resolver->resolve();
}

////////////////////////////////////////////////////////////////////////////
// remove()
////////////////////////////////////////////////////////////////////////////

public function testRemoveReturnsThis()
{
$this->resolver->setDefault('foo', 'bar');
Expand Down Expand Up @@ -1408,10 +1360,6 @@ public function testRemoveUnknownOptionIgnored()
$this->assertNotNull($this->resolver->remove('foo'));
}

////////////////////////////////////////////////////////////////////////////
// clear()
////////////////////////////////////////////////////////////////////////////

public function testClearReturnsThis()
{
$this->assertSame($this->resolver, $this->resolver->clear());
Expand Down Expand Up @@ -1498,10 +1446,6 @@ public function testClearOptionAndNormalizer()
$this->assertEmpty($this->resolver->resolve());
}

////////////////////////////////////////////////////////////////////////////
// ArrayAccess
////////////////////////////////////////////////////////////////////////////

public function testArrayAccess()
{
$this->resolver->setDefault('default1', 0);
Expand Down Expand Up @@ -1616,10 +1560,6 @@ public function testFailIfCyclicDependency()
$this->resolver->resolve();
}

////////////////////////////////////////////////////////////////////////////
// Countable
////////////////////////////////////////////////////////////////////////////

public function testCount()
{
$this->resolver->setDefault('default', 0);
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Process/ExecutableFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function find($name, $default = null, array $extraDirs = array())
$suffixes = array('');
if ('\\' === DIRECTORY_SEPARATOR) {
$pathExt = getenv('PATHEXT');
$suffixes = array_merge($suffixes, $pathExt ? explode(PATH_SEPARATOR, $pathExt) : $this->suffixes);
$suffixes = array_merge($pathExt ? explode(PATH_SEPARATOR, $pathExt) : $this->suffixes, $suffixes);
}
foreach ($suffixes as $suffix) {
foreach ($dirs as $dir) {
Expand Down
30 changes: 30 additions & 0 deletions src/Symfony/Component/Process/Tests/ExecutableFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,36 @@ public function testFindProcessInOpenBasedir()
$this->assertSamePath(PHP_BINARY, $result);
}

/**
* @requires PHP 5.4
*/
public function testFindBatchExecutableOnWindows()
{
if (ini_get('open_basedir')) {
$this->markTestSkipped('Cannot test when open_basedir is set');
}
if ('\\' !== DIRECTORY_SEPARATOR) {
$this->markTestSkipped('Can be only tested on windows');
}

$target = tempnam(sys_get_temp_dir(), 'example-windows-executable');

touch($target);
touch($target.'.BAT');

$this->assertFalse(is_executable($target));

$this->setPath(sys_get_temp_dir());

$finder = new ExecutableFinder();
$result = $finder->find(basename($target), false);

unlink($target);
unlink($target.'.BAT');

$this->assertSamePath($target.'.BAT', $result);
}

private function assertSamePath($expected, $tested)
{
if ('\\' === DIRECTORY_SEPARATOR) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,25 @@ public function handle(GetResponseEvent $event)
}

$request = $event->getRequest();
if (null === $token = $this->rememberMeServices->autoLogin($request)) {
try {
if (null === $token = $this->rememberMeServices->autoLogin($request)) {
return;
}
} catch (AuthenticationException $e) {
if (null !== $this->logger) {
$this->logger->warning(
'The token storage was not populated with remember-me token as the'
.' RememberMeServices was not able to create a token from the remember'
.' me information.', array('exception' => $e)
);
}

$this->rememberMeServices->loginFail($request);

if (!$this->catchExceptions) {
throw $e;
}

return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,43 @@ public function testOnCoreSecurityIgnoresAuthenticationOptionallyRethrowsExcepti
$listener->handle($event);
}

public function testOnCoreSecurityAuthenticationExceptionDuringAutoLoginTriggersLoginFail()
{
list($listener, $tokenStorage, $service, $manager) = $this->getListener();

$tokenStorage
->expects($this->once())
->method('getToken')
->will($this->returnValue(null))
;

$exception = new AuthenticationException('Authentication failed.');
$service
->expects($this->once())
->method('autoLogin')
->will($this->throwException($exception))
;

$service
->expects($this->once())
->method('loginFail')
;

$manager
->expects($this->never())
->method('authenticate')
;

$event = $this->getGetResponseEvent();
$event
->expects($this->once())
->method('getRequest')
->will($this->returnValue(new Request()))
;

$listener->handle($event);
}

public function testOnCoreSecurity()
{
list($listener, $tokenStorage, $service, $manager) = $this->getListener();
Expand Down

0 comments on commit 10580f1

Please sign in to comment.