google2fa-laravel icon indicating copy to clipboard operation
google2fa-laravel copied to clipboard

Middleware does not work in tests

Open ValtteriL opened this issue 5 years ago • 2 comments

The included middleware '2fa' does not seem to work in tests.

I have added the middleware to app/Http/Kernel.php and am using it in my API. All my test users have google2fa secret generated in factory.

Still nothing happens - the middleware does not request for 2FA token nor does it stop the routes from being taken, it seems that the middleware does not to anything at all.

I have tried both stateful and stateless middleware.

Tracking down, the middleware function noUserIsAuthenticated() returns true, thus the middleware does not detect my authentication.

If I change the code as follows to see which check fails:

protected function canPassWithoutCheckingOTP()
    {
        if(!$this->isEnabled()) { echo "2FA not enabled...\n";}
        if($this->noUserIsAuthenticated()) {echo "user is not authenticated...\n";}
        if(!$this->isActivated()) {echo "user is not authenticated...\n";}
        if($this->twoFactorAuthStillValid()) {echo "two factor auth is still valid...\n";}

        return
            !$this->isEnabled() ||
            $this->noUserIsAuthenticated() ||
            !$this->isActivated() ||
            $this->twoFactorAuthStillValid();
    }

I get the output user is not authenticated... and the following error: ErrorException: Trying to get property 'google2fa_secret' of non-object

The error does not happen without those changes above.

Any clue what might be wrong?

ValtteriL avatar Mar 12 '20 18:03 ValtteriL

Same here, were you able to fix it @ValtteriL ?

Tiththa avatar May 18 '20 08:05 Tiththa

No, unfortunately not. @Tiththa

ValtteriL avatar May 19 '20 15:05 ValtteriL