简体   繁体   中英

Disable security firewall in test environment on Symfony2

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?

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.

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.

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

firewalls:
    dev:
        pattern:  ^/
        security: false

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM