Skip to content

Commit

Permalink
Merge branch '3.2'
Browse files Browse the repository at this point in the history
* 3.2:
  Fixes a typo in the form collector styles
  [WebProfilerBundle] Fix content-security-policy compatibility
  [WebProfilerBundle] Drop dead code
  [HttpKernel] Fixed bug with purging of HTTPS URLs
  fix some risky tests
  [DI] [YamlFileLoader] change error message of a non existing file
  [WebProfilerBundle] Handle Content-Security-Policy-Report-Only header correctly
  [Security] Added option to return true in the method isRememberMeRequested
  • Loading branch information
fabpot committed Mar 21, 2017
2 parents 4c0006a + 8cd835e commit b048296
Show file tree
Hide file tree
Showing 40 changed files with 236 additions and 142 deletions.
Expand Up @@ -25,5 +25,7 @@ public function testConstruct()
{
$connection = $this->getMockBuilder('Doctrine\DBAL\Connection')->disableOriginalConstructor()->getMock();
$handler = new DbalSessionHandler($connection);

$this->assertInstanceOf('Symfony\Bridge\Doctrine\HttpFoundation\DbalSessionHandler', $handler);
}
}
Expand Up @@ -89,7 +89,10 @@ public function testThemeBlockInheritanceUsingDynamicExtend()
;

$this->renderer->setTheme($view, array('page_dynamic_extends.html.twig'));
$this->renderer->searchAndRenderBlock($view, 'row');
$this->assertMatchesXpath(
$this->renderer->searchAndRenderBlock($view, 'row'),
'/div/label[text()="child"]'
);
}

public function isSelectedChoiceProvider()
Expand Down
Expand Up @@ -30,11 +30,10 @@ public function testDevEnvironment()
public function testProdEnvironment()
{
$helper = new StopwatchHelper(null);
$helper->start('foo');

try {
$helper->start('foo');
} catch (\BadMethodCallException $e) {
$this->fail('Assumed stopwatch is not called when not provided');
}
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
// can be executed without throwing any exceptions
$this->addToAssertionCount(1);
}
}
Expand Up @@ -19,21 +19,9 @@ class TemplateTest extends TestCase
/**
* @dataProvider getTemplateToPathProvider
*/
public function testGetPathForTemplatesInABundle($template, $path)
public function testGetPathForTemplate($template, $path)
{
if ($template->get('bundle')) {
$this->assertEquals($template->getPath(), $path);
}
}

/**
* @dataProvider getTemplateToPathProvider
*/
public function testGetPathForTemplatesOutOfABundle($template, $path)
{
if (!$template->get('bundle')) {
$this->assertEquals($template->getPath(), $path);
}
$this->assertSame($template->getPath(), $path);
}

public function getTemplateToPathProvider()
Expand Down
Expand Up @@ -47,7 +47,7 @@ class ProfilerController
* @param string $toolbarPosition The toolbar position (top, bottom, normal, or null -- use the configuration)
* @param string $baseDir The project root directory
*/
public function __construct(UrlGeneratorInterface $generator, Profiler $profiler = null, \Twig_Environment $twig, array $templates, $toolbarPosition = 'normal', ContentSecurityPolicyHandler $cspHandler = null, $baseDir = null)
public function __construct(UrlGeneratorInterface $generator, Profiler $profiler = null, \Twig_Environment $twig, array $templates, $toolbarPosition = 'bottom', ContentSecurityPolicyHandler $cspHandler = null, $baseDir = null)
{
$this->generator = $generator;
$this->profiler = $profiler;
Expand Down
Expand Up @@ -108,6 +108,7 @@ private function removeCspHeaders(Response $response)
{
$response->headers->remove('X-Content-Security-Policy');
$response->headers->remove('Content-Security-Policy');
$response->headers->remove('Content-Security-Policy-Report-Only');
}

/**
Expand Down Expand Up @@ -257,6 +258,10 @@ private function getCspHeaders(Response $response)
$headers['Content-Security-Policy'] = $this->parseDirectives($response->headers->get('Content-Security-Policy'));
}

if ($response->headers->has('Content-Security-Policy-Report-Only')) {
$headers['Content-Security-Policy-Report-Only'] = $this->parseDirectives($response->headers->get('Content-Security-Policy-Report-Only'));
}

if ($response->headers->has('X-Content-Security-Policy')) {
$headers['X-Content-Security-Policy'] = $this->parseDirectives($response->headers->get('X-Content-Security-Policy'));
}
Expand Down
@@ -1,15 +1,10 @@
<!-- START of Symfony Web Debug Toolbar -->
{% if 'normal' != position %}
<div id="sfMiniToolbar-{{ token }}" class="sf-minitoolbar" data-no-turbolink>
<a href="#" title="Show Symfony toolbar" tabindex="-1" id="sfToolbarMiniToggler-{{ token }}" accesskey="D">
{{ include('@WebProfiler/Icon/symfony.svg') }}
</a>
</div>
<style{% if csp_style_nonce %} nonce="{{ csp_style_nonce }}"{% endif %}>
{{ include('@WebProfiler/Profiler/toolbar.css.twig', { 'position': position, 'floatable': true }) }}
</style>
<div id="sfToolbarClearer-{{ token }}" class="sf-toolbar-clearer"></div>
{% endif %}
<div id="sfMiniToolbar-{{ token }}" class="sf-minitoolbar" data-no-turbolink>
<a href="#" title="Show Symfony toolbar" tabindex="-1" id="sfToolbarMiniToggler-{{ token }}" accesskey="D">
{{ include('@WebProfiler/Icon/symfony.svg') }}
</a>
</div>
<div id="sfToolbarClearer-{{ token }}" class="sf-toolbar-clearer"></div>

<div id="sfToolbarMainContent-{{ token }}" class="sf-toolbarreset clear-fix" data-no-turbolink>
{% for name, template in templates %}
Expand All @@ -28,10 +23,8 @@
{% endif %}
{% endfor %}

{% if 'normal' != position %}
<a class="hide-button" id="sfToolbarHideButton-{{ token }}" title="Close Toolbar" tabindex="-1" accesskey="D">
{{ include('@WebProfiler/Icon/close.svg') }}
</a>
{% endif %}
<a class="hide-button" id="sfToolbarHideButton-{{ token }}" title="Close Toolbar" tabindex="-1" accesskey="D">
{{ include('@WebProfiler/Icon/close.svg') }}
</a>
</div>
<!-- END of Symfony Web Debug Toolbar -->
@@ -1,5 +1,8 @@
<div id="sfwdt{{ token }}" class="sf-toolbar sf-display-none"></div>
{{ include('@WebProfiler/Profiler/base_js.html.twig') }}
<style{% if csp_style_nonce %} nonce="{{ csp_style_nonce }}"{% endif %}>
{{ include('@WebProfiler/Profiler/toolbar.css.twig', { 'position': position, 'floatable': true }) }}
</style>
<script{% if csp_script_nonce %} nonce={{ csp_script_nonce }}{% endif %}>/*<![CDATA[*/
(function () {
{% if 'top' == position %}
Expand Down
Expand Up @@ -157,9 +157,9 @@ private function createController($profiler, $twig, $withCSP)
if ($withCSP) {
$nonceGenerator = $this->getMockBuilder('Symfony\Bundle\WebProfilerBundle\Csp\NonceGenerator')->getMock();

return new ProfilerController($urlGenerator, $profiler, $twig, array(), 'normal', new ContentSecurityPolicyHandler($nonceGenerator));
return new ProfilerController($urlGenerator, $profiler, $twig, array(), 'bottom', new ContentSecurityPolicyHandler($nonceGenerator));
}

return new ProfilerController($urlGenerator, $profiler, $twig, array(), 'normal');
return new ProfilerController($urlGenerator, $profiler, $twig, array());
}
}
Expand Up @@ -97,41 +97,41 @@ public function provideRequestAndResponsesForOnKernelResponse()
array('csp_script_nonce' => $nonce, 'csp_style_nonce' => $nonce),
$this->createRequest(),
$this->createResponse(),
array('Content-Security-Policy' => null, 'X-Content-Security-Policy' => null),
array('Content-Security-Policy' => null, 'Content-Security-Policy-Report-Only' => null, 'X-Content-Security-Policy' => null),
),
array(
$nonce, array('csp_script_nonce' => $requestScriptNonce, 'csp_style_nonce' => $requestStyleNonce),
$this->createRequest($requestNonceHeaders),
$this->createResponse($responseNonceHeaders),
array('Content-Security-Policy' => null, 'X-Content-Security-Policy' => null),
array('Content-Security-Policy' => null, 'Content-Security-Policy-Report-Only' => null, 'X-Content-Security-Policy' => null),
),
array(
$nonce,
array('csp_script_nonce' => $requestScriptNonce, 'csp_style_nonce' => $requestStyleNonce),
$this->createRequest($requestNonceHeaders),
$this->createResponse(),
array('Content-Security-Policy' => null, 'X-Content-Security-Policy' => null),
array('Content-Security-Policy' => null, 'Content-Security-Policy-Report-Only' => null, 'X-Content-Security-Policy' => null),
),
array(
$nonce,
array('csp_script_nonce' => $responseScriptNonce, 'csp_style_nonce' => $responseStyleNonce),
$this->createRequest(),
$this->createResponse($responseNonceHeaders),
array('Content-Security-Policy' => null, 'X-Content-Security-Policy' => null),
array('Content-Security-Policy' => null, 'Content-Security-Policy-Report-Only' => null, 'X-Content-Security-Policy' => null),
),
array(
$nonce,
array('csp_script_nonce' => $nonce, 'csp_style_nonce' => $nonce),
$this->createRequest(),
$this->createResponse(array('Content-Security-Policy' => 'frame-ancestors https: ; form-action: https:')),
array('Content-Security-Policy' => 'frame-ancestors https: ; form-action: https:', 'X-Content-Security-Policy' => null),
$this->createResponse(array('Content-Security-Policy' => 'frame-ancestors https: ; form-action: https:', 'Content-Security-Policy-Report-Only' => 'frame-ancestors http: ; form-action: http:')),
array('Content-Security-Policy' => 'frame-ancestors https: ; form-action: https:', 'Content-Security-Policy-Report-Only' => 'frame-ancestors http: ; form-action: http:', 'X-Content-Security-Policy' => null),
),
array(
$nonce,
array('csp_script_nonce' => $nonce, 'csp_style_nonce' => $nonce),
$this->createRequest(),
$this->createResponse(array('Content-Security-Policy' => 'default-src \'self\' domain.com; script-src \'self\' \'unsafe-inline\'')),
array('Content-Security-Policy' => 'default-src \'self\' domain.com; script-src \'self\' \'unsafe-inline\'; style-src \'self\' domain.com \'unsafe-inline\' \'nonce-'.$nonce.'\'', 'X-Content-Security-Policy' => null),
$this->createResponse(array('Content-Security-Policy' => 'default-src \'self\' domain.com; script-src \'self\' \'unsafe-inline\'', 'Content-Security-Policy-Report-Only' => 'default-src \'self\' domain-report-only.com; script-src \'self\' \'unsafe-inline\'')),
array('Content-Security-Policy' => 'default-src \'self\' domain.com; script-src \'self\' \'unsafe-inline\'; style-src \'self\' domain.com \'unsafe-inline\' \'nonce-'.$nonce.'\'', 'Content-Security-Policy-Report-Only' => 'default-src \'self\' domain-report-only.com; script-src \'self\' \'unsafe-inline\'; style-src \'self\' domain-report-only.com \'unsafe-inline\' \'nonce-'.$nonce.'\'', 'X-Content-Security-Policy' => null),
),
array(
$nonce,
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Console/Tests/ApplicationTest.php
Expand Up @@ -718,8 +718,12 @@ public function testVerboseValueNotBreakArguments()
$input = new ArgvInput(array('cli.php', '-v', 'foo:bar'));
$application->run($input, $output);

$this->addToAssertionCount(1);

$input = new ArgvInput(array('cli.php', '--verbose', 'foo:bar'));
$application->run($input, $output);

$this->addToAssertionCount(1);
}

public function testRunReturnsIntegerExitCode()
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Component/Console/Tests/Helper/TableTest.php
Expand Up @@ -34,7 +34,7 @@ protected function tearDown()
}

/**
* @dataProvider testRenderProvider
* @dataProvider renderProvider
*/
public function testRender($headers, $rows, $style, $expected, $decorated = false)
{
Expand All @@ -50,7 +50,7 @@ public function testRender($headers, $rows, $style, $expected, $decorated = fals
}

/**
* @dataProvider testRenderProvider
* @dataProvider renderProvider
*/
public function testRenderAddRows($headers, $rows, $style, $expected, $decorated = false)
{
Expand All @@ -66,7 +66,7 @@ public function testRenderAddRows($headers, $rows, $style, $expected, $decorated
}

/**
* @dataProvider testRenderProvider
* @dataProvider renderProvider
*/
public function testRenderAddRowsOneByOne($headers, $rows, $style, $expected, $decorated = false)
{
Expand All @@ -83,7 +83,7 @@ public function testRenderAddRowsOneByOne($headers, $rows, $style, $expected, $d
$this->assertEquals($expected, $this->getOutputContent($output));
}

public function testRenderProvider()
public function renderProvider()
{
$books = array(
array('99921-58-10-7', 'Divine Comedy', 'Dante Alighieri'),
Expand Down
Expand Up @@ -594,7 +594,7 @@ protected function loadFile($file)
}

if (!file_exists($file)) {
throw new InvalidArgumentException(sprintf('The service file "%s" is not valid.', $file));
throw new InvalidArgumentException(sprintf('The file "%s" does not exist.', $file));
}

if (null === $this->yamlParser) {
Expand Down
Expand Up @@ -115,6 +115,8 @@ public function testProcessIgnoresMethodCalls()
$container->register('b')->addMethodCall('setA', array(new Reference('a')));

$this->process($container);

$this->addToAssertionCount(1);
}

public function testProcessIgnoresLazyServices()
Expand Down
Expand Up @@ -48,6 +48,8 @@ public function testProcess()
$container->register('d', 'class')->setSynthetic(true);

$this->process($container);

$this->addToAssertionCount(1);
}

public function testValidTags()
Expand All @@ -59,6 +61,8 @@ public function testValidTags()
$container->register('d', 'class')->addTag('foo', array('bar' => 1.1));

$this->process($container);

$this->addToAssertionCount(1);
}

/**
Expand Down
Expand Up @@ -28,6 +28,10 @@ public function testProcess()
->addArgument(new Reference('b'))
;
$container->register('b', '\stdClass');

$this->process($container);

$this->addToAssertionCount(1);
}

/**
Expand Down
Expand Up @@ -38,6 +38,8 @@ public function testProcess()
$container->register('b');

$this->process($container);

$this->addToAssertionCount(1);
}

protected function process(ContainerBuilder $container)
Expand Down
Expand Up @@ -487,6 +487,8 @@ public function testCircularReferenceAllowanceForLazyServices()

$dumper = new PhpDumper($container);
$dumper->dump();

$this->addToAssertionCount(1);
}

public function testCircularReferenceAllowanceForInlinedDefinitionsForLazyServices()
Expand Down Expand Up @@ -524,6 +526,8 @@ public function testCircularReferenceAllowanceForInlinedDefinitionsForLazyServic

$dumper->setProxyDumper(new DummyProxyDumper());
$dumper->dump();

$this->addToAssertionCount(1);
}

public function testLazyArgumentProvideGenerator()
Expand Down
Expand Up @@ -157,6 +157,8 @@ public function testCompiledContainerCanBeDumped($containerFile)
$container->compile();
$dumper = new XmlDumper($container);
$dumper->dump();

$this->addToAssertionCount(1);
}

public function provideCompiledContainerData()
Expand Down
Expand Up @@ -40,40 +40,33 @@ public static function setUpBeforeClass()
require_once self::$fixturesPath.'/includes/ProjectExtension.php';
}

public function testLoadFile()
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
* @expectedExceptionMessageRegExp /The file ".+" does not exist./
*/
public function testLoadUnExistFile()
{
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/ini'));
$r = new \ReflectionObject($loader);
$m = $r->getMethod('loadFile');
$m->setAccessible(true);

try {
$m->invoke($loader, 'foo.yml');
$this->fail('->load() throws an InvalidArgumentException if the loaded file does not exist');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file does not exist');
$this->assertEquals('The service file "foo.yml" is not valid.', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file does not exist');
}

try {
$m->invoke($loader, 'parameters.ini');
$this->fail('->load() throws an InvalidArgumentException if the loaded file is not a valid YAML file');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file is not a valid YAML file');
$this->assertEquals('The service file "parameters.ini" is not valid.', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file is not a valid YAML file');
}
$m->invoke($loader, 'foo.yml');
}

$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
* @expectedExceptionMessageRegExp /The file ".+" does not contain valid YAML./
*/
public function testLoadInvalidYamlFile()
{
$path = self::$fixturesPath.'/ini';
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator($path));
$r = new \ReflectionObject($loader);
$m = $r->getMethod('loadFile');
$m->setAccessible(true);

foreach (array('nonvalid1', 'nonvalid2') as $fixture) {
try {
$m->invoke($loader, $fixture.'.yml');
$this->fail('->load() throws an InvalidArgumentException if the loaded file does not validate');
} catch (\Exception $e) {
$this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file does not validate');
$this->assertStringMatchesFormat('The service file "nonvalid%d.yml" is not valid.', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file does not validate');
}
}
$m->invoke($loader, $path.'/parameters.ini');
}

/**
Expand All @@ -97,6 +90,8 @@ public function provideInvalidFiles()
array('bad_service'),
array('bad_calls'),
array('bad_format'),
array('nonvalid1'),
array('nonvalid2'),
);
}

Expand Down

0 comments on commit b048296

Please sign in to comment.