-
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.
[5.6] Let Exception Handler do the reporting (#24864)
* Let Exception Handler do the reporting Co-authored-by: Abdala Cerqueira <abdala.cerqueira@gmail.com> * StyleCI * Fix error message Co-authored-by: Abdala Cerqueira <abdala.cerqueira@gmail.com>
- Loading branch information
1 parent
89fc860
commit 23f6279
Showing
3 changed files
with
52 additions
and
6 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
51 changes: 51 additions & 0 deletions
51
tests/Integration/Auth/ApiAuthenticationWithEloquentTest.php
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,51 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Auth\ApiAuthenticationWithEloquentTest; | ||
|
||
use Orchestra\Testbench\TestCase; | ||
use Illuminate\Support\Facades\Route; | ||
use Illuminate\Database\QueryException; | ||
|
||
class ApiAuthenticationWithEloquentTest extends TestCase | ||
{ | ||
protected function getEnvironmentSetUp($app) | ||
{ | ||
$app['config']->set('app.debug', 'true'); | ||
|
||
// Auth configuration | ||
$app['config']->set('auth.defaults.guard', 'api'); | ||
$app['config']->set('auth.providers.users.model', User::class); | ||
|
||
// Database configuration | ||
$app['config']->set('database.default', 'testbench'); | ||
|
||
$app['config']->set('database.connections.testbench', [ | ||
'driver' => 'mysql', | ||
'host' => env('DB_HOST', '127.0.0.1'), | ||
'username' => 'root', | ||
'password' => 'invalid-credentials', | ||
'database' => 'forge', | ||
'prefix' => '', | ||
]); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function authentication_via_api_with_eloquent_using_wrong_database_credentials_should_not_cause_infinite_loop() | ||
{ | ||
Route::get('/auth', function () { | ||
return 'success'; | ||
})->middleware('auth:api'); | ||
|
||
$this->expectException(QueryException::class); | ||
|
||
$this->expectExceptionMessage("SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) (SQL: select * from `users` where `api_token` = whatever limit 1)"); | ||
|
||
$this->withoutExceptionHandling()->get('/auth', ['Authorization' => 'Bearer whatever']); | ||
} | ||
} | ||
|
||
class User extends \Illuminate\Foundation\Auth\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