4

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.

lo_fye
  • 6,790
  • 4
  • 33
  • 49

1 Answers1

12

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

lo_fye
  • 6,790
  • 4
  • 33
  • 49
  • 1
    Great discovery, any idea why do they do this? – asdacap Jan 23 '14 at 13:57
  • I just submitted the pull request last night :) Not sure why they do it. Probably because it was just easier to hard-code it at the time. Other higher priorities than making that configurable. – lo_fye Jan 23 '14 at 14:54
  • I love you man. Spent a whole night and morning finding out the problem – Timothy Sep 18 '16 at 08:54