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?
The dev firewall is really a fake firewall: it makes sure that you don't accidentally block Symfony's dev tools - which live under URLs like /_profiler and /_wdt. All real URLs are handled by the main firewall (no pattern key means it matches all URLs).
To enable logging out, activate the logout config parameter under your firewall: That's it! By sending a user to the app_logout route (i.e. to /logout ) Symfony will un-authenticate the current user and redirect them. The LogoutEvent was introduced in Symfony 5.1.
Most of the time you don't need to create matchers yourself as Symfony can do it for you based on the firewall configuration. You can use any of the following restrictions individually or mix them together to get your desired firewall configuration.
That's the idea of Symfony's configuration environments. A typical Symfony application begins with three environments: dev (for local development), prod (for production servers) and test (for automated tests ).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With