|
19 | 19 | use Laudis\Neo4j\Bolt\BoltDriver; |
20 | 20 | use Laudis\Neo4j\Bolt\ConnectionPool; |
21 | 21 | use Laudis\Neo4j\ClientBuilder; |
| 22 | +use Laudis\Neo4j\Common\DriverSetupManager; |
22 | 23 | use Laudis\Neo4j\Common\Uri; |
23 | 24 | use Laudis\Neo4j\Contracts\DriverInterface; |
24 | 25 | use Laudis\Neo4j\Contracts\TransactionInterface; |
25 | 26 | use Laudis\Neo4j\Databags\DriverConfiguration; |
| 27 | +use Laudis\Neo4j\Databags\DriverSetup; |
26 | 28 | use Laudis\Neo4j\Databags\SessionConfiguration; |
27 | 29 | use Laudis\Neo4j\Databags\Statement; |
| 30 | +use Laudis\Neo4j\Databags\TransactionConfiguration; |
28 | 31 | use Laudis\Neo4j\Exception\Neo4jException; |
| 32 | +use Laudis\Neo4j\Formatter\SummarizedResultFormatter; |
29 | 33 | use Laudis\Neo4j\Tests\EnvironmentAwareIntegrationTest; |
30 | 34 | use Psr\Log\LoggerInterface; |
31 | 35 | use Psr\Log\LogLevel; |
@@ -61,6 +65,45 @@ public function testDriverAuthFailureVerifyConnectivity(): void |
61 | 65 | $driver->verifyConnectivity(); |
62 | 66 | } |
63 | 67 |
|
| 68 | + public function testClientAuthFailureVerifyConnectivity(): void |
| 69 | + { |
| 70 | + $connection = $_ENV['CONNECTION'] ?? false; |
| 71 | + if (str_starts_with($connection, 'http')) { |
| 72 | + $this->markTestSkipped('HTTP does not support auth failure connectivity passing'); |
| 73 | + } |
| 74 | + |
| 75 | + if (!is_string($connection)) { |
| 76 | + $connection = 'bolt://localhost'; |
| 77 | + } |
| 78 | + |
| 79 | + $uri = Uri::create($connection); |
| 80 | + $uri = $uri->withUserInfo('neo4j', 'absolutelyonehundredpercentawrongpassword'); |
| 81 | + |
| 82 | + /** @noinspection PhpUnhandledExceptionInspection */ |
| 83 | + $conf = DriverConfiguration::default()->withLogger(LogLevel::DEBUG, $this->createMock(LoggerInterface::class)); |
| 84 | + $logger = $conf->getLogger(); |
| 85 | + if ($logger === null) { |
| 86 | + throw new RuntimeException('Logger not set'); |
| 87 | + } |
| 88 | + |
| 89 | + $client = (new ClientBuilder( |
| 90 | + SessionConfiguration::create(), |
| 91 | + TransactionConfiguration::create(), |
| 92 | + (new DriverSetupManager( |
| 93 | + SummarizedResultFormatter::create(), |
| 94 | + $conf, |
| 95 | + ))->withSetup( |
| 96 | + new DriverSetup($uri, Authenticate::fromUrl($uri, $logger)) |
| 97 | + ) |
| 98 | + ))->build(); |
| 99 | + |
| 100 | + $driver = $client->getDriver(null); |
| 101 | + |
| 102 | + $this->expectException(Neo4jException::class); |
| 103 | + $this->expectExceptionMessage('Neo4j errors detected. First one with code "Neo.ClientError.Security.Unauthorized" and message "The client is unauthorized due to authentication failure."'); |
| 104 | + $driver->verifyConnectivity(); |
| 105 | + } |
| 106 | + |
64 | 107 | public function testDifferentAuth(): void |
65 | 108 | { |
66 | 109 | $auth = Authenticate::fromUrl($this->getUri()); |
|
0 commit comments