Skip to content

Commit 45fe468

Browse files
committed
Merge branch '2.8'
* 2.8: removed usage of the deprecated StringUtils::equals() method Fix: Resolve tempdir symlink, not working on OSX fixed tests migrate session after remember me authentication prevent timing attacks in digest auth listener mitigate CSRF timing attack vulnerability fix potential timing attack issue [WebProfilerBundle] Added a top left border radius to the minified to… [Routing] Changing RouteCollectionBuilder::import() behavior to add to the builder [HttpKernel] Don't reset on shutdown but in FrameworkBundle/Test/KernelTestCase [Process] PhpExecutableFinder: add regression test
2 parents 06959c0 + 2dbb75a commit 45fe468

File tree

12 files changed

+113
-20
lines changed

12 files changed

+113
-20
lines changed

src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Test;
1313

14+
use Symfony\Component\DependencyInjection\ResettableContainerInterface;
1415
use Symfony\Component\Finder\Finder;
1516
use Symfony\Component\HttpKernel\KernelInterface;
1617

@@ -171,7 +172,11 @@ protected static function createKernel(array $options = array())
171172
protected static function ensureKernelShutdown()
172173
{
173174
if (null !== static::$kernel) {
175+
$container = static::$kernel->getContainer();
174176
static::$kernel->shutdown();
177+
if ($container instanceof ResettableContainerInterface) {
178+
$container->reset();
179+
}
175180
}
176181
}
177182

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.css.twig

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.sf-minitoolbar {
22
background-color: #222;
3+
border-top-left-radius: 4px;
34
bottom: 0;
45
display: none;
56
height: 30px;
@@ -8,6 +9,7 @@
89
right: 0;
910
z-index: 99999;
1011
}
12+
1113
.sf-minitoolbar a {
1214
display: block;
1315
}
@@ -357,6 +359,8 @@
357359
/* Override the setting when the toolbar is on the top */
358360
{% if position == 'top' %}
359361
.sf-minitoolbar {
362+
border-bottom-left-radius: 4px;
363+
border-top-left-radius: 0;
360364
bottom: auto;
361365
right: 0;
362366
top: 0;

src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ public function testCreateServiceMethodCallsWithEscapedParam()
308308
{
309309
$builder = new ContainerBuilder();
310310
$builder->register('bar', 'stdClass');
311-
$builder->register('foo1', 'FooClass')->addMethodCall('setBar', array(array('%%unescape_it%%')));
311+
$builder->register('foo1', 'Bar\FooClass')->addMethodCall('setBar', array(array('%%unescape_it%%')));
312312
$builder->setParameter('value', 'bar');
313313
$this->assertEquals(array('%unescape_it%'), $builder->get('foo1')->bar, '->createService() replaces the values in the method calls arguments');
314314
}
@@ -317,7 +317,7 @@ public function testCreateServiceProperties()
317317
{
318318
$builder = new ContainerBuilder();
319319
$builder->register('bar', 'stdClass');
320-
$builder->register('foo1', 'FooClass')->setProperty('bar', array('%value%', new Reference('bar'), '%%unescape_it%%'));
320+
$builder->register('foo1', 'Bar\FooClass')->setProperty('bar', array('%value%', new Reference('bar'), '%%unescape_it%%'));
321321
$builder->setParameter('value', 'bar');
322322
$this->assertEquals(array('bar', $builder->get('bar'), '%unescape_it%'), $builder->get('foo1')->bar, '->createService() replaces the values in the properties');
323323
}

src/Symfony/Component/Filesystem/Tests/FilesystemTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1042,8 +1042,8 @@ public function testTempnamOnUnwritableFallsBackToSysTmp()
10421042
$dirname = $scheme.$this->workspace.DIRECTORY_SEPARATOR.'does_not_exist';
10431043

10441044
$filename = $this->filesystem->tempnam($dirname, 'bar');
1045-
1046-
$this->assertStringStartsWith(rtrim($scheme.sys_get_temp_dir(), DIRECTORY_SEPARATOR), $filename);
1045+
$realTempDir = realpath(sys_get_temp_dir());
1046+
$this->assertStringStartsWith(rtrim($scheme.$realTempDir, DIRECTORY_SEPARATOR), $filename);
10471047
$this->assertFileExists($filename);
10481048

10491049
// Tear down

src/Symfony/Component/HttpKernel/Kernel.php

-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
2424
use Symfony\Component\DependencyInjection\Loader\DirectoryLoader;
2525
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
26-
use Symfony\Component\DependencyInjection\ResettableContainerInterface;
2726
use Symfony\Component\HttpFoundation\Request;
2827
use Symfony\Component\HttpFoundation\Response;
2928
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
@@ -155,10 +154,6 @@ public function shutdown()
155154
$bundle->setContainer(null);
156155
}
157156

158-
if ($this->container instanceof ResettableContainerInterface) {
159-
$this->container->reset();
160-
}
161-
162157
$this->container = null;
163158
}
164159

src/Symfony/Component/Process/Tests/PhpExecutableFinderTest.php

+19-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,25 @@
1919
class PhpExecutableFinderTest extends \PHPUnit_Framework_TestCase
2020
{
2121
/**
22-
* tests find() with the env var PHP_PATH.
22+
* tests find() with the constant PHP_BINARY.
23+
*/
24+
public function testFind()
25+
{
26+
if (defined('HHVM_VERSION')) {
27+
$this->markTestSkipped('Should not be executed in HHVM context.');
28+
}
29+
30+
$f = new PhpExecutableFinder();
31+
32+
$current = PHP_BINARY;
33+
$args = 'phpdbg' === PHP_SAPI ? ' -qrr' : '';
34+
35+
$this->assertEquals($current.$args, $f->find(), '::find() returns the executable PHP');
36+
$this->assertEquals($current, $f->find(false), '::find() returns the executable PHP');
37+
}
38+
39+
/**
40+
* tests find() with the env var / constant PHP_BINARY with HHVM.
2341
*/
2442
public function testFindWithHHVM()
2543
{

src/Symfony/Component/Routing/RouteCollectionBuilder.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,17 @@ public function __construct(LoaderInterface $loader = null)
4949
/**
5050
* Import an external routing resource and returns the RouteCollectionBuilder.
5151
*
52-
* $routes->mount('/blog', $routes->import('blog.yml'));
52+
* $routes->import('blog.yml', '/blog');
5353
*
54-
* @param mixed $resource
55-
* @param string $type
54+
* @param mixed $resource
55+
* @param string|null $prefix
56+
* @param string $type
5657
*
5758
* @return RouteCollectionBuilder
5859
*
5960
* @throws FileLoaderLoadException
6061
*/
61-
public function import($resource, $type = null)
62+
public function import($resource, $prefix = '/', $type = null)
6263
{
6364
/** @var RouteCollection $collection */
6465
$collection = $this->load($resource, $type);
@@ -73,6 +74,9 @@ public function import($resource, $type = null)
7374
$builder->addResource($resource);
7475
}
7576

77+
// mount into this builder
78+
$this->mount($prefix, $builder);
79+
7680
return $builder;
7781
}
7882

src/Symfony/Component/Routing/Tests/RouteCollectionBuilderTest.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function testImport()
4545

4646
// import the file!
4747
$routes = new RouteCollectionBuilder($loader);
48-
$importedRoutes = $routes->import('admin_routing.yml', 'yaml');
48+
$importedRoutes = $routes->import('admin_routing.yml', '/', 'yaml');
4949

5050
// we should get back a RouteCollectionBuilder
5151
$this->assertInstanceOf('Symfony\Component\Routing\RouteCollectionBuilder', $importedRoutes);
@@ -56,6 +56,9 @@ public function testImport()
5656
$this->assertSame($originalRoute, $route);
5757
// should return file_resource.yml, which is in the original collection
5858
$this->assertCount(1, $addedCollection->getResources());
59+
60+
// make sure the routes were imported into the top-level builder
61+
$this->assertCount(1, $routes->build());
5962
}
6063

6164
/**
@@ -285,7 +288,7 @@ public function testFlushSetsPrefixedWithMultipleLevels()
285288
->method('load')
286289
->will($this->returnValue($importedCollection));
287290
// import this from the /admin route builder
288-
$adminRoutes->mount('/imported', $adminRoutes->import('admin.yml'));
291+
$adminRoutes->import('admin.yml', '/imported');
289292

290293
$collection = $routes->build();
291294
$this->assertEquals('/admin/dashboard', $collection->get('admin_dashboard')->getPath(), 'Routes before mounting have the prefix');

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function handle(GetResponseEvent $event)
9999
return;
100100
}
101101

102-
if ($serverDigestMd5 !== $digestAuth->getResponse()) {
102+
if (!hash_equals($serverDigestMd5, $digestAuth->getResponse())) {
103103
if (null !== $this->logger) {
104104
$this->logger->debug('Unexpected response from the DigestAuth received; is the header returning a clear text passwords?', array('expected' => $serverDigestMd5, 'received' => $digestAuth->getResponse()));
105105
}

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Symfony\Component\Security\Http\SecurityEvents;
2222
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
2323
use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface;
24+
use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategy;
2425

2526
/**
2627
* RememberMeListener implements authentication capabilities via a cookie.
@@ -56,7 +57,7 @@ public function __construct(TokenStorageInterface $tokenStorage, RememberMeServi
5657
$this->logger = $logger;
5758
$this->dispatcher = $dispatcher;
5859
$this->catchExceptions = $catchExceptions;
59-
$this->sessionStrategy = $sessionStrategy;
60+
$this->sessionStrategy = null === $sessionStrategy ? new SessionAuthenticationStrategy(SessionAuthenticationStrategy::MIGRATE) : $sessionStrategy;
6061
}
6162

6263
/**
@@ -77,7 +78,7 @@ public function handle(GetResponseEvent $event)
7778

7879
try {
7980
$token = $this->authenticationManager->authenticate($token);
80-
if (null !== $this->sessionStrategy && $request->hasSession() && $request->getSession()->isStarted()) {
81+
if ($request->hasSession() && $request->getSession()->isStarted()) {
8182
$this->sessionStrategy->onAuthentication($request, $token);
8283
}
8384
$this->tokenStorage->setToken($token);

src/Symfony/Component/Security/Http/RememberMe/PersistentTokenBasedRememberMeServices.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected function processAutoLoginCookie(array $cookieParts, Request $request)
7171
list($series, $tokenValue) = $cookieParts;
7272
$persistentToken = $this->tokenProvider->loadTokenBySeries($series);
7373

74-
if ($persistentToken->getTokenValue() !== $tokenValue) {
74+
if (!hash_equals($persistentToken->getTokenValue(), $tokenValue)) {
7575
throw new CookieTheftException('This token was already used. The account is possibly compromised.');
7676
}
7777

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

+63
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,69 @@ public function testSessionStrategy()
246246
$listener->handle($event);
247247
}
248248

249+
public function testSessionIsMigratedByDefault()
250+
{
251+
list($listener, $tokenStorage, $service, $manager, , $dispatcher, $sessionStrategy) = $this->getListener(false, true, false);
252+
253+
$tokenStorage
254+
->expects($this->once())
255+
->method('getToken')
256+
->will($this->returnValue(null))
257+
;
258+
259+
$token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
260+
$service
261+
->expects($this->once())
262+
->method('autoLogin')
263+
->will($this->returnValue($token))
264+
;
265+
266+
$tokenStorage
267+
->expects($this->once())
268+
->method('setToken')
269+
->with($this->equalTo($token))
270+
;
271+
272+
$manager
273+
->expects($this->once())
274+
->method('authenticate')
275+
->will($this->returnValue($token))
276+
;
277+
278+
$session = $this->getMock('\Symfony\Component\HttpFoundation\Session\SessionInterface');
279+
$session
280+
->expects($this->once())
281+
->method('isStarted')
282+
->will($this->returnValue(true))
283+
;
284+
$session
285+
->expects($this->once())
286+
->method('migrate')
287+
;
288+
289+
$request = $this->getMock('\Symfony\Component\HttpFoundation\Request');
290+
$request
291+
->expects($this->any())
292+
->method('hasSession')
293+
->will($this->returnValue(true))
294+
;
295+
296+
$request
297+
->expects($this->any())
298+
->method('getSession')
299+
->will($this->returnValue($session))
300+
;
301+
302+
$event = $this->getGetResponseEvent();
303+
$event
304+
->expects($this->once())
305+
->method('getRequest')
306+
->will($this->returnValue($request))
307+
;
308+
309+
$listener->handle($event);
310+
}
311+
249312
public function testOnCoreSecurityInteractiveLoginEventIsDispatchedIfDispatcherIsPresent()
250313
{
251314
list($listener, $tokenStorage, $service, $manager, , $dispatcher) = $this->getListener(true);

0 commit comments

Comments
 (0)