Skip to content

Commit

Permalink
fix: Pass original hostname to ssl configuration before IP resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
exaby73 authored and transistive committed Jul 31, 2024
1 parent 899e753 commit 7681d10
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/Bolt/ConnectionPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public static function create(UriInterface $uri, AuthenticateInterface $auth, Dr
$semaphore,
BoltFactory::create(),
new ConnectionRequestData(
$uri->getHost(),
$uri,
$auth,
$conf->getUserAgent(),
Expand Down
2 changes: 1 addition & 1 deletion src/BoltFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
6 changes: 6 additions & 0 deletions src/Databags/ConnectionRequestData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 6 additions & 4 deletions src/Neo4j/Neo4jConnectionPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public static function create(UriInterface $uri, AuthenticateInterface $auth, Dr
$semaphore,
BoltFactory::create(),
new ConnectionRequestData(
$uri->getHost(),
$uri,
$auth,
$conf->getUserAgent(),
Expand All @@ -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(),
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/BoltResultIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);

Expand Down
1 change: 1 addition & 0 deletions tests/Unit/BoltConnectionPoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ private function setupPool(Generator $semaphoreGenerator): void

$this->pool = new ConnectionPool(
$this->semaphore, $this->factory, new ConnectionRequestData(
'',
Uri::create(''),
Authenticate::disabled(),
'',
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/BoltFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);

Expand Down

0 comments on commit 7681d10

Please sign in to comment.