From 7681d10d5aade2b05f96d5f329611c0b3d39dc1d Mon Sep 17 00:00:00 2001 From: exaby73 Date: Sun, 28 Jul 2024 23:49:44 +0530 Subject: [PATCH] fix: Pass original hostname to ssl configuration before IP resolution --- src/Bolt/ConnectionPool.php | 1 + src/BoltFactory.php | 2 +- src/Databags/ConnectionRequestData.php | 6 ++++++ src/Neo4j/Neo4jConnectionPool.php | 10 ++++++---- tests/Integration/BoltResultIntegrationTest.php | 2 +- tests/Unit/BoltConnectionPoolTest.php | 1 + tests/Unit/BoltFactoryTest.php | 2 +- 7 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/Bolt/ConnectionPool.php b/src/Bolt/ConnectionPool.php index 82aadb4e..d3d6556f 100644 --- a/src/Bolt/ConnectionPool.php +++ b/src/Bolt/ConnectionPool.php @@ -50,6 +50,7 @@ public static function create(UriInterface $uri, AuthenticateInterface $auth, Dr $semaphore, BoltFactory::create(), new ConnectionRequestData( + $uri->getHost(), $uri, $auth, $conf->getUserAgent(), diff --git a/src/BoltFactory.php b/src/BoltFactory.php index 20eeb2ac..f0b4611f 100644 --- a/src/BoltFactory.php +++ b/src/BoltFactory.php @@ -50,7 +50,7 @@ public static function create(): self public function createConnection(ConnectionRequestData $data, SessionConfiguration $sessionConfig): BoltConnection { - [$sslLevel, $sslConfig] = $this->sslConfigurationFactory->create($data->getUri(), $data->getSslConfig()); + [$sslLevel, $sslConfig] = $this->sslConfigurationFactory->create($data->getUri()->withHost($data->getHostname()), $data->getSslConfig()); $uriConfig = new UriConfiguration( $data->getUri()->getHost(), diff --git a/src/Databags/ConnectionRequestData.php b/src/Databags/ConnectionRequestData.php index 98a39466..b5772b1a 100644 --- a/src/Databags/ConnectionRequestData.php +++ b/src/Databags/ConnectionRequestData.php @@ -22,12 +22,18 @@ final class ConnectionRequestData { public function __construct( + private readonly string $hostname, private readonly UriInterface $uri, private readonly AuthenticateInterface $auth, private readonly string $userAgent, private readonly SslConfiguration $config ) {} + public function getHostname(): string + { + return $this->hostname; + } + public function getUri(): UriInterface { return $this->uri; diff --git a/src/Neo4j/Neo4jConnectionPool.php b/src/Neo4j/Neo4jConnectionPool.php index 4f71441e..db1f3930 100644 --- a/src/Neo4j/Neo4jConnectionPool.php +++ b/src/Neo4j/Neo4jConnectionPool.php @@ -82,6 +82,7 @@ public static function create(UriInterface $uri, AuthenticateInterface $auth, Dr $semaphore, BoltFactory::create(), new ConnectionRequestData( + $uri->getHost(), $uri, $auth, $conf->getUserAgent(), @@ -92,9 +93,10 @@ public static function create(UriInterface $uri, AuthenticateInterface $auth, Dr ); } - public function createOrGetPool(UriInterface $uri): ConnectionPool + public function createOrGetPool(string $hostname, UriInterface $uri): ConnectionPool { $data = new ConnectionRequestData( + $hostname, $uri, $this->data->getAuth(), $this->data->getUserAgent(), @@ -130,7 +132,7 @@ public function acquire(SessionConfiguration $config): Generator foreach ($addresses as $address) { $triedAddresses[] = $address; - $pool = $this->createOrGetPool($this->data->getUri()->withHost($address)); + $pool = $this->createOrGetPool($this->data->getUri()->getHost(), $this->data->getUri()->withHost($address)); try { /** @var BoltConnection $connection */ $connection = GeneratorHelper::getReturnFromGenerator($pool->acquire($config)); @@ -158,7 +160,7 @@ public function acquire(SessionConfiguration $config): Generator $server = $server->withScheme($this->data->getUri()->getScheme()); } - return $this->createOrGetPool($server)->acquire($config); + return $this->createOrGetPool($this->data->getUri()->getHost(), $server)->acquire($config); } /** @@ -200,7 +202,7 @@ private function routingTable(BoltConnection $connection, SessionConfiguration $ public function release(ConnectionInterface $connection): void { - $this->createOrGetPool($connection->getServerAddress())->release($connection); + $this->createOrGetPool($connection->getServerAddress()->getHost(), $connection->getServerAddress())->release($connection); } private function createKey(ConnectionRequestData $data, ?SessionConfiguration $config = null): string diff --git a/tests/Integration/BoltResultIntegrationTest.php b/tests/Integration/BoltResultIntegrationTest.php index c4477137..9db763a7 100644 --- a/tests/Integration/BoltResultIntegrationTest.php +++ b/tests/Integration/BoltResultIntegrationTest.php @@ -40,7 +40,7 @@ public function testIterationLong(): void new SslConfigurationFactory() ); $connection = $factory->createConnection( - new ConnectionRequestData($this->getUri(), Authenticate::fromUrl($this->getUri()), 'a/b', new SslConfiguration(SslMode::FROM_URL(), false)), + new ConnectionRequestData($this->getUri()->getHost(), $this->getUri(), Authenticate::fromUrl($this->getUri()), 'a/b', new SslConfiguration(SslMode::FROM_URL(), false)), SessionConfiguration::default() ); diff --git a/tests/Unit/BoltConnectionPoolTest.php b/tests/Unit/BoltConnectionPoolTest.php index 3f3e089d..bf717c61 100644 --- a/tests/Unit/BoltConnectionPoolTest.php +++ b/tests/Unit/BoltConnectionPoolTest.php @@ -157,6 +157,7 @@ private function setupPool(Generator $semaphoreGenerator): void $this->pool = new ConnectionPool( $this->semaphore, $this->factory, new ConnectionRequestData( + '', Uri::create(''), Authenticate::disabled(), '', diff --git a/tests/Unit/BoltFactoryTest.php b/tests/Unit/BoltFactoryTest.php index 20557bbf..4794e3e0 100644 --- a/tests/Unit/BoltFactoryTest.php +++ b/tests/Unit/BoltFactoryTest.php @@ -62,7 +62,7 @@ protected function setUp(): void public function testCreateBasic(): void { $connection = $this->factory->createConnection( - new ConnectionRequestData(Uri::create(''), Authenticate::disabled(), '', SslConfiguration::default()), + new ConnectionRequestData('', Uri::create(''), Authenticate::disabled(), '', SslConfiguration::default()), SessionConfiguration::default() );