|
14 | 14 | use PHPUnit\Framework\TestCase;
|
15 | 15 | use Symfony\Bundle\WebProfilerBundle\Controller\ProfilerController;
|
16 | 16 | use Symfony\Bundle\WebProfilerBundle\Csp\ContentSecurityPolicyHandler;
|
| 17 | +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
17 | 18 | use Symfony\Component\HttpKernel\Profiler\Profile;
|
18 | 19 | use Symfony\Component\HttpFoundation\Request;
|
19 | 20 |
|
@@ -46,6 +47,42 @@ public function getEmptyTokenCases()
|
46 | 47 | );
|
47 | 48 | }
|
48 | 49 |
|
| 50 | + /** |
| 51 | + * @dataProvider getOpenFileCases |
| 52 | + */ |
| 53 | + public function testOpeningDisallowedPaths($path, $isAllowed) |
| 54 | + { |
| 55 | + $urlGenerator = $this->getMockBuilder('Symfony\Component\Routing\Generator\UrlGeneratorInterface')->getMock(); |
| 56 | + $twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock(); |
| 57 | + $profiler = $this |
| 58 | + ->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profiler') |
| 59 | + ->disableOriginalConstructor() |
| 60 | + ->getMock(); |
| 61 | + |
| 62 | + $controller = new ProfilerController($urlGenerator, $profiler, $twig, array(), 'bottom', null, __DIR__.'/../..'); |
| 63 | + |
| 64 | + try { |
| 65 | + $response = $controller->openAction(Request::create('/_wdt/open', Request::METHOD_GET, array('file' => $path))); |
| 66 | + $this->assertEquals(200, $response->getStatusCode()); |
| 67 | + $this->assertTrue($isAllowed); |
| 68 | + } catch (NotFoundHttpException $e) { |
| 69 | + $this->assertFalse($isAllowed); |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + public function getOpenFileCases() |
| 74 | + { |
| 75 | + return array( |
| 76 | + array('README.md', true), |
| 77 | + array('composer.json', true), |
| 78 | + array('Controller/ProfilerController.php', true), |
| 79 | + array('.gitignore', false), |
| 80 | + array('../TwigBundle/README.md', false), |
| 81 | + array('Controller/../README.md', false), |
| 82 | + array('Controller/./ProfilerController.php', false), |
| 83 | + ); |
| 84 | + } |
| 85 | + |
49 | 86 | /**
|
50 | 87 | * @dataProvider provideCspVariants
|
51 | 88 | */
|
|
0 commit comments