Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Before filters not running

The problem is the client told us we could go live with any OS we wanted, so we developed on CentOS as usual, and when we went to go live, they said "oh, new policy is RHEL only, sorry". Our application works perfectly on CentOS, but not on RHEL.

Main Problem:

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

Configuration Info:

  • both servers are running 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 it makes NO sense: in vendor/laravel/framework/src/Illuminate/Routing/Router.php

at line 1398, change this:

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

to this:

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

Do you have any idea what's going on here? I can't find a config option anywhere that would be setting runFilters = false.

like image 411
lo_fye Avatar asked Dec 15 '22 11:12

lo_fye


1 Answers

I finally found the issue. A while ago I was getting unit tests running, and in app/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! The $testENvironment is configurable. I hated the 'testing' default because that's what we call our QA environment, so I changed it to "phpunit", and then created app/config/phpunit/* files. It ran like a charm in development.

When I pushed the code to our testing environment, I started getting errors about sessions being empty. At first i thought laravel's array session handler was broken, so i tried native, but it was broken too. But then I put some logging throughout the code, and discovered that in fact beforeFilters were not getting run, so authentication wasn't happening, so the session was rightfully empty. So then I traced the code execution from index to start to autoinclude to dispatching, and way down in the routing i found this little hard-coded gem:

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

renaming our testing environment to 'test' and our 'phpunit' environment to 'testing' fixed the issue.

maybe i'll do a pull request to make that env name configurable :)

like image 61
lo_fye Avatar answered Dec 25 '22 19:12

lo_fye