Skip to content

Commit 4acae8d

Browse files
authored
Merge pull request #91 from clue-labs/connect-without-database
Fix "bad handshake" error when connecting without database name
2 parents 6cf4b91 + 8815d5c commit 4acae8d

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

src/Commands/AuthenticateCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function authenticatePacket($scramble, Buffer $buffer)
4444
. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
4545
. $this->user . "\x00"
4646
. $this->getAuthToken($scramble, $this->passwd, $buffer)
47-
. ($this->dbname ? $this->dbname . "\x00" : '');
47+
. $this->dbname . "\x00";
4848
}
4949

5050
public function getAuthToken($scramble, $password, Buffer $buffer)

tests/FactoryTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,24 @@ public function testConnectWithValidAuthWillRunUntilQuit()
160160
$loop->run();
161161
}
162162

163+
public function testConnectWithValidAuthAndWithoutDbNameWillRunUntilQuit()
164+
{
165+
$this->expectOutputString('connected.closed.');
166+
167+
$loop = \React\EventLoop\Factory::create();
168+
$factory = new Factory($loop);
169+
170+
$uri = $this->getConnectionString(array('dbname' => ''));
171+
$factory->createConnection($uri)->then(function (ConnectionInterface $connection) {
172+
echo 'connected.';
173+
$connection->quit()->then(function () {
174+
echo 'closed.';
175+
});
176+
}, 'printf')->then(null, 'printf');
177+
178+
$loop->run();
179+
}
180+
163181
public function testConnectWithValidAuthWillIgnoreNegativeTimeoutAndRunUntilQuit()
164182
{
165183
$this->expectOutputString('connected.closed.');

tests/ResultQueryTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,25 @@ public function testSimpleSelect()
359359
$loop->run();
360360
}
361361

362+
/**
363+
* @depends testSimpleSelect
364+
*/
365+
public function testSimpleSelectFromLazyConnectionWithoutDatabaseNameReturnsSameData()
366+
{
367+
$loop = \React\EventLoop\Factory::create();
368+
$factory = new Factory($loop);
369+
370+
$uri = $this->getConnectionString(array('dbname' => ''));
371+
$connection = $factory->createLazyConnection($uri);
372+
373+
$connection->query('select * from test.book')->then(function (QueryResult $command) {
374+
$this->assertCount(2, $command->resultRows);
375+
})->done();
376+
377+
$connection->quit();
378+
$loop->run();
379+
}
380+
362381
public function testInvalidSelectShouldFail()
363382
{
364383
$loop = \React\EventLoop\Factory::create();

0 commit comments

Comments
 (0)