-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes
$request->user()
or Auth::user()
run query each time if tok…
…en doesn't exists fixes #49201 Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
- Loading branch information
Showing
4 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Auth; | ||
|
||
use Illuminate\Auth\RequestGuard; | ||
use Illuminate\Contracts\Auth\UserProvider; | ||
use Illuminate\Http\Request; | ||
use Mockery as m; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class AuthRequestGuardTest extends TestCase | ||
{ | ||
protected function tearDown(): void | ||
{ | ||
m::close(); | ||
} | ||
|
||
public function testUserDoesntCallRetrieveByCredentialMoreThanOnceWhenGivenAuthentication() | ||
{ | ||
$provider = m::mock(UserProvider::class); | ||
$provider->shouldReceive('retrieveByCredentials')->once()->with(['api_token' => 'foo'])->andReturnNull(); | ||
$request = Request::create('/', 'GET', ['api_token' => 'foo']); | ||
|
||
$guard = new RequestGuard(function ($request, $provider) { | ||
return $provider->retrieveByCredentials($request->query()); | ||
}, $request, $provider); | ||
|
||
$this->assertNull($guard->user()); | ||
|
||
// Ensure mocked provider.retrieveByCredential expectation only called once. | ||
$this->assertNull($guard->user()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters