Before the filters will not work

The problem is that the client told us that we can live in any OS that we wanted, so we developed CentOS as usual, and when we went to live, they said: “Oh, the new policy is only RHEL, sorry” . Our application works fine on CentOS, but not on RHEL.

Main problem:

  • routes protected by the filter 'before' => 'auth' are protected on CentOS, but not on RHEL. This means that the user is never authenticated, so Auth :: user () is always empty, so all subsequent code does not work.

Configuration Information:

  • both servers run Apache 2.2.15 and PHP 5.4.13
  • both have the same set of Apache modules and PHP extensions.
  • both have the same code from git.

I have a fix, but that doesn't make sense: in the /laravel/framework/src/Illuminate/Routing/Router.php provider

on line 1398, change this:

public function filtersEnabled() { return $this->runFilters; } 

:

 public function filtersEnabled() { return true;//$this->runFilters; } 

Do you have any idea what is going on here? I can not find the configuration parameter anywhere where runFilters = false will be set.

+4
source share
1 answer

I finally found the problem. Some time ago I was getting unit tests, and in applications / tests I saw this:

 class TestCase extends Illuminate\Foundation\Testing\TestCase { public function createApplication(){ $unitTesting = true; $testEnvironment = 'testing'; return require __DIR__.'/../../bootstrap/start.php'; } 

So I thought, “Awesome!” $ testENvironment is customizable. I hated "testing" by default because it is what we call our QA environment, so I changed it to "phpunit" and then created the app / config / phpunit / * files. He worked like a charm in development.

When I moved the code to our test environment, I started getting errors that the sessions were empty. At first I thought the laravel array session handler was broken, so I tried native, but it was broken too. But then I put some entries in the code and found that beforeFilters actually did not start, so there was no authentication, so the session was rightfully empty. So, I tracked the execution of code from the index to start automatic inclusion in dispatching, and down the routing path I found this little hard-coded jewel:

 vendor/laravel/framework/src/Illuminate/Routing/RoutingServiceProvider.php 35 if ($app['env'] == 'testing') 36 { 37: $router->disableFilters(); 38 } 

renaming our test environment to “test”, and our “phpunit” environment for “testing” fixes the problem.

Maybe I'll make a pull request to set this env name :)

+12
source

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


All Articles