From 8cffce8cae7ab7262d2d6c552805b0b0f4647103 Mon Sep 17 00:00:00 2001 From: exaby73 Date: Fri, 29 Nov 2024 11:39:18 +0530 Subject: [PATCH] test: Fix auth tests --- docker-compose-neo4j-4.yml | 1 + docker-compose.yml | 1 + src/Neo4j/Neo4jConnectionPool.php | 3 ++- tests/Integration/ClientIntegrationTest.php | 14 +++++++++----- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/docker-compose-neo4j-4.yml b/docker-compose-neo4j-4.yml index 06a391b9..95dee8cd 100644 --- a/docker-compose-neo4j-4.yml +++ b/docker-compose-neo4j-4.yml @@ -3,6 +3,7 @@ x-shared: NEO4J_AUTH: neo4j/testtest NEO4J_ACCEPT_LICENSE_AGREEMENT: "yes" NEO4J_dbms_security_allow__csv__import__from__file__urls: "true" + NEO4J_dbms_security_auth__lock__time: 0s NEO4JLABS_PLUGINS: '["apoc"]' x-shared-cluster: diff --git a/docker-compose.yml b/docker-compose.yml index 1be8fd81..91a1ed84 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,6 +2,7 @@ x-definitions: x-shared-env: &common-env NEO4J_AUTH: neo4j/testtest + NEO4J_dbms_security_auth__lock__time: 0s NEO4J_PLUGINS: '["apoc"]' x-shared-cluster-env: &common-cluster-env diff --git a/src/Neo4j/Neo4jConnectionPool.php b/src/Neo4j/Neo4jConnectionPool.php index 75de8213..caa72d09 100644 --- a/src/Neo4j/Neo4jConnectionPool.php +++ b/src/Neo4j/Neo4jConnectionPool.php @@ -13,6 +13,7 @@ namespace Laudis\Neo4j\Neo4j; +use Bolt\error\ConnectException; use function array_unique; use function count; @@ -146,7 +147,7 @@ public function acquire(SessionConfiguration $config): Generator /** @var BoltConnection $connection */ $connection = GeneratorHelper::getReturnFromGenerator($pool->acquire($config)); $table = $this->routingTable($connection, $config); - } catch (Throwable $e) { + } catch (ConnectException $e) { // todo - once client side logging is implemented it must be conveyed here. $latestError = $e; continue; // We continue if something is wrong with the current server diff --git a/tests/Integration/ClientIntegrationTest.php b/tests/Integration/ClientIntegrationTest.php index 8259a1c0..52d10f76 100644 --- a/tests/Integration/ClientIntegrationTest.php +++ b/tests/Integration/ClientIntegrationTest.php @@ -21,7 +21,6 @@ use Laudis\Neo4j\Bolt\ConnectionPool; use Laudis\Neo4j\ClientBuilder; use Laudis\Neo4j\Common\DriverSetupManager; -use Laudis\Neo4j\Common\Uri; use Laudis\Neo4j\Contracts\DriverInterface; use Laudis\Neo4j\Contracts\TransactionInterface; use Laudis\Neo4j\Databags\DriverConfiguration; @@ -39,6 +38,12 @@ final class ClientIntegrationTest extends EnvironmentAwareIntegrationTest { + public function setUp(): void + { + parent::setUp(); + $this->driver->closeConnections(); + } + public function testDriverAuthFailureVerifyConnectivity(): void { if (str_starts_with($this->uri->getScheme(), 'http')) { @@ -47,7 +52,6 @@ public function testDriverAuthFailureVerifyConnectivity(): void $uri = $this->uri->withUserInfo('neo4j', 'absolutelyonehundredpercentawrongpassword'); - /** @noinspection PhpUnhandledExceptionInspection */ $conf = DriverConfiguration::default()->withLogger(LogLevel::DEBUG, $this->createMock(LoggerInterface::class)); $logger = $conf->getLogger(); if ($logger === null) { @@ -60,6 +64,7 @@ public function testDriverAuthFailureVerifyConnectivity(): void $this->expectExceptionMessage( 'Neo4j errors detected. First one with code "Neo.ClientError.Security.Unauthorized" and message "The client is unauthorized due to authentication failure."' ); + $driver->verifyConnectivity(); } @@ -89,13 +94,12 @@ public function testClientAuthFailureVerifyConnectivity(): void ) ))->build(); - $driver = $client->getDriver(null); - $this->expectException(Neo4jException::class); $this->expectExceptionMessage( 'Neo4j errors detected. First one with code "Neo.ClientError.Security.Unauthorized" and message "The client is unauthorized due to authentication failure."' ); - $driver->verifyConnectivity(); + + $client->getDriver(null); } public function testDifferentAuth(): void