Skip to content

Commit 5676a7a

Browse files
committed
initial kickoff
1 parent 5bf29c7 commit 5676a7a

File tree

6 files changed

+51
-7
lines changed

6 files changed

+51
-7
lines changed

docker-compose-neo4j-4.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ services:
3131
context: .
3232
dockerfile: Dockerfile
3333
args:
34-
PHP_VERSION: ${PHP_VERSION}
34+
PHP_VERSION: "${PHP_VERSION-8.1}"
3535
networks:
3636
- neo4j
3737
volumes:
@@ -46,7 +46,7 @@ services:
4646
context: .
4747
dockerfile: Dockerfile
4848
args:
49-
PHP_VERSION: ${PHP_VERSION}
49+
PHP_VERSION: "${PHP_VERSION-8.1}"
5050
WITH_XDEBUG: true
5151
working_dir: /opt/project
5252
volumes:

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ x-definitions:
2525
context: .
2626
dockerfile: Dockerfile
2727
args:
28-
PHP_VERSION: ${PHP_VERSION}
28+
PHP_VERSION: "${PHP_VERSION-8.1}"
2929
volumes:
3030
- .:/opt/project
3131
x-common-cluster:

src/Bolt/BoltDriver.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use Exception;
1717

18+
use Psr\Log\LogLevel;
1819
use function is_string;
1920

2021
use Laudis\Neo4j\Authentication\Authenticate;
@@ -103,7 +104,8 @@ public function verifyConnectivity(?SessionConfiguration $config = null): bool
103104
$config ??= SessionConfiguration::default();
104105
try {
105106
GeneratorHelper::getReturnFromGenerator($this->pool->acquire($config));
106-
} catch (Throwable) {
107+
} catch (ConnectException $e) {
108+
$this->pool->getLogger()->log(LogLevel::WARNING, 'Could not connect to server on URI ' . $this->parsedUrl->__toString(), ['error' => $e]);
107109
return false;
108110
}
109111

src/Common/DriverSetupManager.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
namespace Laudis\Neo4j\Common;
1515

16+
use Bolt\error\ConnectException;
17+
use Psr\Log\LogLevel;
1618
use function array_key_exists;
1719
use function array_key_first;
1820
use function array_reduce;
@@ -144,7 +146,12 @@ public function verifyConnectivity(SessionConfiguration $config, ?string $alias
144146
{
145147
try {
146148
$this->getDriver($config, $alias);
147-
} catch (RuntimeException) {
149+
} catch (ConnectException $e) {
150+
$this->getLogger()->log(
151+
LogLevel::WARNING,
152+
sprintf('Could not connect to server using alias (%s)', $alias ?? '<default>'),
153+
['exception' => $e]
154+
);
148155
return false;
149156
}
150157

src/Neo4j/Neo4jDriver.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313

1414
namespace Laudis\Neo4j\Neo4j;
1515

16+
use Bolt\error\ConnectException;
1617
use Exception;
1718

19+
use Psr\Log\LogLevel;
1820
use function is_string;
1921

2022
use Laudis\Neo4j\Authentication\Authenticate;
@@ -31,7 +33,6 @@
3133
use Laudis\Neo4j\Databags\SessionConfiguration;
3234
use Laudis\Neo4j\Formatter\OGMFormatter;
3335
use Psr\Http\Message\UriInterface;
34-
use Throwable;
3536

3637
/**
3738
* Driver for auto client-side routing.
@@ -105,7 +106,9 @@ public function verifyConnectivity(?SessionConfiguration $config = null): bool
105106
$config ??= SessionConfiguration::default();
106107
try {
107108
GeneratorHelper::getReturnFromGenerator($this->pool->acquire($config));
108-
} catch (Throwable) {
109+
} catch (ConnectException $e) {
110+
$this->pool->getLogger()->log(LogLevel::WARNING, 'Could not connect to server on URI ' . $this->parsedUrl->__toString(), ['error' => $e]);
111+
109112
return false;
110113
}
111114

tests/Integration/ClientIntegrationTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,48 @@
1919
use Laudis\Neo4j\Bolt\BoltDriver;
2020
use Laudis\Neo4j\Bolt\ConnectionPool;
2121
use Laudis\Neo4j\ClientBuilder;
22+
use Laudis\Neo4j\Common\Uri;
2223
use Laudis\Neo4j\Contracts\DriverInterface;
2324
use Laudis\Neo4j\Contracts\TransactionInterface;
25+
use Laudis\Neo4j\Databags\DriverConfiguration;
2426
use Laudis\Neo4j\Databags\SessionConfiguration;
2527
use Laudis\Neo4j\Databags\Statement;
2628
use Laudis\Neo4j\Exception\Neo4jException;
2729
use Laudis\Neo4j\Tests\EnvironmentAwareIntegrationTest;
30+
use Psr\Log\LoggerInterface;
31+
use Psr\Log\LogLevel;
2832
use ReflectionClass;
2933

3034
final class ClientIntegrationTest extends EnvironmentAwareIntegrationTest
3135
{
36+
public function testDriverAuthFailureVerifyConnectivity(): void
37+
{
38+
$connection = $_ENV['CONNECTION'] ?? false;
39+
if (str_starts_with($connection, 'http')) {
40+
$this->markTestSkipped('HTTP does not support auth failure connectivity passing');
41+
}
42+
43+
if (!is_string($connection)) {
44+
$connection = 'bolt://localhost';
45+
}
46+
47+
$uri = Uri::create($connection);
48+
$uri = $uri->withUserInfo('neo4j', 'absolutelyonehundredpercentawrongpassword');
49+
50+
/** @noinspection PhpUnhandledExceptionInspection */
51+
$conf = DriverConfiguration::default()->withLogger(LogLevel::DEBUG, $this->createMock(LoggerInterface::class));
52+
$logger = $conf->getLogger();
53+
if ($logger === null) {
54+
throw new RuntimeException('Logger not set');
55+
}
56+
57+
$driver = Driver::create($uri, $conf);
58+
59+
$this->expectException(Neo4jException::class);
60+
$this->expectExceptionMessage('Neo4j errors detected. First one with code "Neo.ClientError.Security.Unauthorized" and message "The client is unauthorized due to authentication failure."');
61+
$driver->verifyConnectivity();
62+
}
63+
3264
public function testDifferentAuth(): void
3365
{
3466
$auth = Authenticate::fromUrl($this->getUri());

0 commit comments

Comments
 (0)