Disable Symfony2 Test Firewall Security

I am trying to disable the security firewall for a test environment in Symfony2, but I'm out of luck. Here is what I have in config_test.yml:

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

However, this does not disable security. Any ideas how I can completely disable protection for a specific firewall when in a test env?

+6
source share
3 answers

As mentioned in a similar topic, disable the firewall during development, put the following rule in your security.yml:

 firewalls: dev: pattern: ^/ security: false 
+1
source

Possible Solution

You can extract this piece of code from config.yml :

 imports: - { resource: security.yml } 

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

+2
source

Do not change security.yml , instead create a special rule for testing.

You need to disable the entire security firewall configuration at 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

Remember that config_test.yml imports config_dev.yml , which imports config.yml . Therefore, you must redefine the entire base configuration in the test configuration file for it to work.

+1
source

Source: https://habr.com/ru/post/921423/


All Articles