FilesystemTest.php 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /*
  3. * This file is part of Twig.
  4. *
  5. * (c) Fabien Potencier
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. class Twig_Tests_Loader_FilesystemTest extends PHPUnit_Framework_TestCase
  11. {
  12. /**
  13. * @dataProvider getSecurityTests
  14. */
  15. public function testSecurity($template)
  16. {
  17. $loader = new Twig_Loader_Filesystem(array(dirname(__FILE__).'/../Fixtures'));
  18. try {
  19. $loader->getCacheKey($template);
  20. $this->fail();
  21. } catch (Twig_Error_Loader $e) {
  22. $this->assertNotContains('Unable to find template', $e->getMessage());
  23. }
  24. }
  25. public function getSecurityTests()
  26. {
  27. return array(
  28. array("AutoloaderTest\0.php"),
  29. array('..\\AutoloaderTest.php'),
  30. array('..\\\\\\AutoloaderTest.php'),
  31. array('../AutoloaderTest.php'),
  32. array('..////AutoloaderTest.php'),
  33. array('./../AutoloaderTest.php'),
  34. array('.\\..\\AutoloaderTest.php'),
  35. array('././././././../AutoloaderTest.php'),
  36. array('.\\./.\\./.\\./../AutoloaderTest.php'),
  37. array('foo/../../AutoloaderTest.php'),
  38. array('foo\\..\\..\\AutoloaderTest.php'),
  39. array('foo/../bar/../../AutoloaderTest.php'),
  40. array('foo/bar/../../../AutoloaderTest.php'),
  41. array('filters/../../AutoloaderTest.php'),
  42. array('filters//..//..//AutoloaderTest.php'),
  43. array('filters\\..\\..\\AutoloaderTest.php'),
  44. array('filters\\\\..\\\\..\\\\AutoloaderTest.php'),
  45. array('filters\\//../\\/\\..\\AutoloaderTest.php'),
  46. );
  47. }
  48. }