Skip to content

Commit 7681d10

Browse files
exaby73transistive
authored andcommitted
fix: Pass original hostname to ssl configuration before IP resolution
1 parent 899e753 commit 7681d10

File tree

7 files changed

+17
-7
lines changed

7 files changed

+17
-7
lines changed

src/Bolt/ConnectionPool.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public static function create(UriInterface $uri, AuthenticateInterface $auth, Dr
5050
$semaphore,
5151
BoltFactory::create(),
5252
new ConnectionRequestData(
53+
$uri->getHost(),
5354
$uri,
5455
$auth,
5556
$conf->getUserAgent(),

src/BoltFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static function create(): self
5050

5151
public function createConnection(ConnectionRequestData $data, SessionConfiguration $sessionConfig): BoltConnection
5252
{
53-
[$sslLevel, $sslConfig] = $this->sslConfigurationFactory->create($data->getUri(), $data->getSslConfig());
53+
[$sslLevel, $sslConfig] = $this->sslConfigurationFactory->create($data->getUri()->withHost($data->getHostname()), $data->getSslConfig());
5454

5555
$uriConfig = new UriConfiguration(
5656
$data->getUri()->getHost(),

src/Databags/ConnectionRequestData.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,18 @@
2222
final class ConnectionRequestData
2323
{
2424
public function __construct(
25+
private readonly string $hostname,
2526
private readonly UriInterface $uri,
2627
private readonly AuthenticateInterface $auth,
2728
private readonly string $userAgent,
2829
private readonly SslConfiguration $config
2930
) {}
3031

32+
public function getHostname(): string
33+
{
34+
return $this->hostname;
35+
}
36+
3137
public function getUri(): UriInterface
3238
{
3339
return $this->uri;

src/Neo4j/Neo4jConnectionPool.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public static function create(UriInterface $uri, AuthenticateInterface $auth, Dr
8282
$semaphore,
8383
BoltFactory::create(),
8484
new ConnectionRequestData(
85+
$uri->getHost(),
8586
$uri,
8687
$auth,
8788
$conf->getUserAgent(),
@@ -92,9 +93,10 @@ public static function create(UriInterface $uri, AuthenticateInterface $auth, Dr
9293
);
9394
}
9495

95-
public function createOrGetPool(UriInterface $uri): ConnectionPool
96+
public function createOrGetPool(string $hostname, UriInterface $uri): ConnectionPool
9697
{
9798
$data = new ConnectionRequestData(
99+
$hostname,
98100
$uri,
99101
$this->data->getAuth(),
100102
$this->data->getUserAgent(),
@@ -130,7 +132,7 @@ public function acquire(SessionConfiguration $config): Generator
130132
foreach ($addresses as $address) {
131133
$triedAddresses[] = $address;
132134

133-
$pool = $this->createOrGetPool($this->data->getUri()->withHost($address));
135+
$pool = $this->createOrGetPool($this->data->getUri()->getHost(), $this->data->getUri()->withHost($address));
134136
try {
135137
/** @var BoltConnection $connection */
136138
$connection = GeneratorHelper::getReturnFromGenerator($pool->acquire($config));
@@ -158,7 +160,7 @@ public function acquire(SessionConfiguration $config): Generator
158160
$server = $server->withScheme($this->data->getUri()->getScheme());
159161
}
160162

161-
return $this->createOrGetPool($server)->acquire($config);
163+
return $this->createOrGetPool($this->data->getUri()->getHost(), $server)->acquire($config);
162164
}
163165

164166
/**
@@ -200,7 +202,7 @@ private function routingTable(BoltConnection $connection, SessionConfiguration $
200202

201203
public function release(ConnectionInterface $connection): void
202204
{
203-
$this->createOrGetPool($connection->getServerAddress())->release($connection);
205+
$this->createOrGetPool($connection->getServerAddress()->getHost(), $connection->getServerAddress())->release($connection);
204206
}
205207

206208
private function createKey(ConnectionRequestData $data, ?SessionConfiguration $config = null): string

tests/Integration/BoltResultIntegrationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testIterationLong(): void
4040
new SslConfigurationFactory()
4141
);
4242
$connection = $factory->createConnection(
43-
new ConnectionRequestData($this->getUri(), Authenticate::fromUrl($this->getUri()), 'a/b', new SslConfiguration(SslMode::FROM_URL(), false)),
43+
new ConnectionRequestData($this->getUri()->getHost(), $this->getUri(), Authenticate::fromUrl($this->getUri()), 'a/b', new SslConfiguration(SslMode::FROM_URL(), false)),
4444
SessionConfiguration::default()
4545
);
4646

tests/Unit/BoltConnectionPoolTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ private function setupPool(Generator $semaphoreGenerator): void
157157

158158
$this->pool = new ConnectionPool(
159159
$this->semaphore, $this->factory, new ConnectionRequestData(
160+
'',
160161
Uri::create(''),
161162
Authenticate::disabled(),
162163
'',

tests/Unit/BoltFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected function setUp(): void
6262
public function testCreateBasic(): void
6363
{
6464
$connection = $this->factory->createConnection(
65-
new ConnectionRequestData(Uri::create(''), Authenticate::disabled(), '', SslConfiguration::default()),
65+
new ConnectionRequestData('', Uri::create(''), Authenticate::disabled(), '', SslConfiguration::default()),
6666
SessionConfiguration::default()
6767
);
6868

0 commit comments

Comments
 (0)