Skip to content

Commit 1084918

Browse files
authored
don't assume a server agent necesarily exists (#286)
1 parent 5e94937 commit 1084918

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/BoltFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function createConnection(ConnectionRequestData $data, SessionConfigurati
7878

7979
$response = $data->getAuth()->authenticateBolt($connection, $data->getUserAgent());
8080

81-
$config->setServerAgent($response['server']);
81+
$config->setServerAgent($response['server'] ?? '');
8282

8383
return $connection;
8484
}

tests/Unit/BoltFactoryTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,34 @@ public function testBoltFactoryWithSocketTypeOverride(): void
107107
$factory = BoltFactory::create(null, SocketType::STREAM());
108108
self::assertInstanceOf(BoltFactory::class, $factory);
109109
}
110+
111+
public function testCreateConnectionWithNullServerAgent(): void
112+
{
113+
// This test reproduces issue #285 where authenticateBolt returns null for server
114+
$auth = $this->createMock(AuthenticateInterface::class);
115+
$auth->method('authenticateBolt')
116+
->willReturn(['server' => null, 'connection_id' => 'i', 'hints' => []]);
117+
118+
$connection = $this->factory->createConnection(
119+
new ConnectionRequestData('', Uri::create(''), $auth, '', SslConfiguration::default()),
120+
SessionConfiguration::default()
121+
);
122+
123+
self::assertInstanceOf(BoltConnection::class, $connection);
124+
}
125+
126+
public function testCreateConnectionWithMissingServerKey(): void
127+
{
128+
// This test reproduces issue #285 where authenticateBolt returns response without server key
129+
$auth = $this->createMock(AuthenticateInterface::class);
130+
$auth->method('authenticateBolt')
131+
->willReturn(['connection_id' => 'i', 'hints' => []]);
132+
133+
$connection = $this->factory->createConnection(
134+
new ConnectionRequestData('', Uri::create(''), $auth, '', SslConfiguration::default()),
135+
SessionConfiguration::default()
136+
);
137+
138+
self::assertInstanceOf(BoltConnection::class, $connection);
139+
}
110140
}

0 commit comments

Comments
 (0)