SecurityRoutingIntegrationTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /*
  3. * This file is part of the Symfony framework.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Symfony\Bundle\SecurityBundle\Tests\Functional;
  11. class SecurityRoutingIntegrationTest extends WebTestCase
  12. {
  13. /**
  14. * @dataProvider getConfigs
  15. */
  16. public function testRoutingErrorIsNotExposedForProtectedResourceWhenAnonymous($config)
  17. {
  18. $client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => $config));
  19. $client->insulate();
  20. $client->request('GET', '/protected_resource');
  21. $this->assertRedirect($client->getResponse(), '/login');
  22. }
  23. /**
  24. * @dataProvider getConfigs
  25. */
  26. public function testRoutingErrorIsExposedWhenNotProtected($config)
  27. {
  28. if (strpos(PHP_OS, "WIN") === 0 && version_compare(phpversion(), "5.3.9", "<")) {
  29. $this->markTestSkipped('Test hangs on Windows & PHP due to https://bugs.php.net/bug.php?id=60120 fixed in http://svn.php.net/viewvc?view=revision&revision=318366');
  30. }
  31. $client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => $config));
  32. $client->insulate();
  33. $client->request('GET', '/unprotected_resource');
  34. $this->assertEquals(404, $client->getResponse()->getStatusCode(), (string) $client->getResponse());
  35. }
  36. /**
  37. * @dataProvider getConfigs
  38. */
  39. public function testRoutingErrorIsNotExposedForProtectedResourceWhenLoggedInWithInsufficientRights($config)
  40. {
  41. if (strpos(PHP_OS, "WIN") === 0 && version_compare(phpversion(), "5.3.9", "<")) {
  42. $this->markTestSkipped('Test hangs on Windows & PHP due to https://bugs.php.net/bug.php?id=60120 fixed in http://svn.php.net/viewvc?view=revision&revision=318366');
  43. }
  44. $client = $this->createClient(array('test_case' => 'StandardFormLogin', 'root_config' => $config));
  45. $client->insulate();
  46. $form = $client->request('GET', '/login')->selectButton('login')->form();
  47. $form['_username'] = 'johannes';
  48. $form['_password'] = 'test';
  49. $client->submit($form);
  50. $client->request('GET', '/highly_protected_resource');
  51. $this->assertNotEquals(404, $client->getResponse()->getStatusCode());
  52. }
  53. public function getConfigs()
  54. {
  55. return array(array('config.yml'), array('routes_as_path.yml'));
  56. }
  57. protected function setUp()
  58. {
  59. parent::setUp();
  60. $this->deleteTmpDir('StandardFormLogin');
  61. }
  62. protected function tearDown()
  63. {
  64. parent::tearDown();
  65. $this->deleteTmpDir('StandardFormLogin');
  66. }
  67. }