From 6cf3d41bb3aecd7d0e8fc4406868619f826cfde2 Mon Sep 17 00:00:00 2001 From: Deleu Date: Mon, 16 Jul 2018 08:32:33 -0400 Subject: [PATCH 1/3] Let Exception Handler do the reporting Co-authored-by: Abdala Cerqueira --- .../Database/Connectors/ConnectionFactory.php | 4 +- .../ApiAuthenticationWithEloquentTest.php | 52 +++++++++++++++++++ .../Database/EloquentRelationshipsTest.php | 2 - 3 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 tests/Integration/Auth/ApiAuthenticationWithEloquentTest.php diff --git a/src/Illuminate/Database/Connectors/ConnectionFactory.php b/src/Illuminate/Database/Connectors/ConnectionFactory.php index 564a9018033d..163bc2bcf1d8 100755 --- a/src/Illuminate/Database/Connectors/ConnectionFactory.php +++ b/src/Illuminate/Database/Connectors/ConnectionFactory.php @@ -182,9 +182,7 @@ protected function createPdoResolverWithHosts(array $config) try { return $this->createConnector($config)->connect($config); } catch (PDOException $e) { - if (count($hosts) - 1 === $key && $this->container->bound(ExceptionHandler::class)) { - $this->container->make(ExceptionHandler::class)->report($e); - } + continue; } } diff --git a/tests/Integration/Auth/ApiAuthenticationWithEloquentTest.php b/tests/Integration/Auth/ApiAuthenticationWithEloquentTest.php new file mode 100644 index 000000000000..771b80d8b843 --- /dev/null +++ b/tests/Integration/Auth/ApiAuthenticationWithEloquentTest.php @@ -0,0 +1,52 @@ +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] [2002] Connection refused (SQL: select * from `users` where `api_token` = whatever limit 1)'); + + $this->withoutExceptionHandling()->get('/auth', ['Authorization' => 'Bearer whatever']); + } +} + +class User extends \Illuminate\Foundation\Auth\User +{ + +} \ No newline at end of file diff --git a/tests/Integration/Database/EloquentRelationshipsTest.php b/tests/Integration/Database/EloquentRelationshipsTest.php index e841995c3422..b73e35390b00 100644 --- a/tests/Integration/Database/EloquentRelationshipsTest.php +++ b/tests/Integration/Database/EloquentRelationshipsTest.php @@ -22,7 +22,6 @@ class EloquentRelationshipsTest extends TestCase { /** * @test - * @group f */ public function standard_relationships() { @@ -41,7 +40,6 @@ public function standard_relationships() /** * @test - * @group f */ public function overridden_relationships() { From e49ea7294e8440d5e2a22ae0fbc5f081f665f3a2 Mon Sep 17 00:00:00 2001 From: Deleu Date: Mon, 16 Jul 2018 08:44:47 -0400 Subject: [PATCH 2/3] StyleCI --- src/Illuminate/Database/Connectors/ConnectionFactory.php | 1 - .../Integration/Auth/ApiAuthenticationWithEloquentTest.php | 7 +++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Database/Connectors/ConnectionFactory.php b/src/Illuminate/Database/Connectors/ConnectionFactory.php index 163bc2bcf1d8..d998a41845fe 100755 --- a/src/Illuminate/Database/Connectors/ConnectionFactory.php +++ b/src/Illuminate/Database/Connectors/ConnectionFactory.php @@ -11,7 +11,6 @@ use Illuminate\Database\PostgresConnection; use Illuminate\Database\SqlServerConnection; use Illuminate\Contracts\Container\Container; -use Illuminate\Contracts\Debug\ExceptionHandler; class ConnectionFactory { diff --git a/tests/Integration/Auth/ApiAuthenticationWithEloquentTest.php b/tests/Integration/Auth/ApiAuthenticationWithEloquentTest.php index 771b80d8b843..0590b14a6e04 100644 --- a/tests/Integration/Auth/ApiAuthenticationWithEloquentTest.php +++ b/tests/Integration/Auth/ApiAuthenticationWithEloquentTest.php @@ -2,9 +2,9 @@ namespace Illuminate\Tests\Integration\Auth\ApiAuthenticationWithEloquentTest; -use Illuminate\Database\QueryException; -use Illuminate\Support\Facades\Route; use Orchestra\Testbench\TestCase; +use Illuminate\Support\Facades\Route; +use Illuminate\Database\QueryException; class ApiAuthenticationWithEloquentTest extends TestCase { @@ -48,5 +48,4 @@ public function authentication_via_api_with_eloquent_using_wrong_database_creden class User extends \Illuminate\Foundation\Auth\User { - -} \ No newline at end of file +} From 80559479fee7e526724f62c2123b1f041161a6f8 Mon Sep 17 00:00:00 2001 From: Deleu Date: Mon, 16 Jul 2018 08:46:55 -0400 Subject: [PATCH 3/3] Fix error message Co-authored-by: Abdala Cerqueira --- tests/Integration/Auth/ApiAuthenticationWithEloquentTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Integration/Auth/ApiAuthenticationWithEloquentTest.php b/tests/Integration/Auth/ApiAuthenticationWithEloquentTest.php index 0590b14a6e04..4553b275be43 100644 --- a/tests/Integration/Auth/ApiAuthenticationWithEloquentTest.php +++ b/tests/Integration/Auth/ApiAuthenticationWithEloquentTest.php @@ -40,7 +40,7 @@ public function authentication_via_api_with_eloquent_using_wrong_database_creden $this->expectException(QueryException::class); - $this->expectExceptionMessage('SQLSTATE[HY000] [2002] Connection refused (SQL: select * from `users` where `api_token` = whatever limit 1)'); + $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']); }