Skip to content

Commit

Permalink
test: Fix auth tests
Browse files Browse the repository at this point in the history
  • Loading branch information
exaby73 committed Nov 29, 2024
1 parent 2a85094 commit 8cffce8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions docker-compose-neo4j-4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/Neo4j/Neo4jConnectionPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Laudis\Neo4j\Neo4j;

use Bolt\error\ConnectException;
use function array_unique;
use function count;

Expand Down Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions tests/Integration/ClientIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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')) {
Expand All @@ -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) {
Expand All @@ -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();
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8cffce8

Please sign in to comment.