Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable security firewall in test environment on Symfony2

Tags:

php

symfony

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?

like image 959
vinnylinux Avatar asked Jul 26 '12 18:07

vinnylinux


People also ask

What is the Symfony Dev firewall?

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).

How to enable logging out in Symfony firewall?

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.

Do I need to create firewall matchers in Symfony?

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.

What are Symfony's configuration environments?

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 ).


1 Answers

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.

like image 191
sentenza Avatar answered Sep 28 '22 02:09

sentenza