9

I'm trying to disable a security firewall for a test environment in Symfony2, but i'm not having luck. Here's what i have in config_test.yml:

security:
    firewalls:
        web:
            pattern: .*
            security: false
            anonymous: ~

However, this is not disabling security. Any ideas how i can completely disable security for a certain firewall when in test env?

vinnylinux
  • 7,050
  • 13
  • 61
  • 127
  • You might also need to have an authenticated user in the system (I did). Check my comment here: http://stackoverflow.com/questions/11451969/authentication-in-functional-tests-in-symfony-2-1 Also check this one out: http://symfony.com/doc/current/cookbook/testing/simulating_authentication.html – timhc22 Sep 17 '14 at 17:00

3 Answers3

8

Do not change security.yml, instead make an ad hoc rule for testing purposes.

You have to disable all the security firewalls configuration on your config_test.yml:

  imports:
      - { resource: config_dev.yml }

  framework:
      test: ~
      session:
          storage_id: session.storage.mock_file
      profiler:
          collect: false

  web_profiler:
      toolbar: false
      intercept_redirects: false

  swiftmailer:
      disable_delivery: true

  security:
      firewalls:
          dev:
              pattern:  ^/
              security: false

Note

Mind that config_test.yml imports config_dev.yml, which imports config.yml. So you must override all the basic configuration on test config file to make it works.

sentenza
  • 1,608
  • 3
  • 29
  • 51
7

As mentioned in similar topic turn off firewall when developing put following rule in Your security.yml:

firewalls:
    dev:
        pattern:  ^/
        security: false
Community
  • 1
  • 1
Valentas
  • 2,135
  • 1
  • 17
  • 21
5

Possible solution

You could extract from config.yml this part of code:

imports:
    - { resource: security.yml }

And put it separately to config_dev.yml and config_prod.yml. In this case config_test.yml will not import security configuration and, as result, you'll have no security in test environment.

Vitalii Zurian
  • 17,858
  • 4
  • 64
  • 81
  • 1
    Problem is: i'm using JMSSecurityExtraBundle with annotated security roles. I'm getting "The security context was not populated with a Token." all the time. – vinnylinux Jul 27 '12 at 19:43
  • The solution from Valentas disables the firewall for prod too. – Marinus Nov 08 '16 at 00:32