Skip to content

Commit

Permalink
Merge pull request #91 from clue-labs/connect-without-database
Browse files Browse the repository at this point in the history
Fix "bad handshake" error when connecting without database name
  • Loading branch information
jsor authored Jan 11, 2019
2 parents 6cf4b91 + 8815d5c commit 4acae8d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Commands/AuthenticateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function authenticatePacket($scramble, Buffer $buffer)
. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
. $this->user . "\x00"
. $this->getAuthToken($scramble, $this->passwd, $buffer)
. ($this->dbname ? $this->dbname . "\x00" : '');
. $this->dbname . "\x00";
}

public function getAuthToken($scramble, $password, Buffer $buffer)
Expand Down
18 changes: 18 additions & 0 deletions tests/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,24 @@ public function testConnectWithValidAuthWillRunUntilQuit()
$loop->run();
}

public function testConnectWithValidAuthAndWithoutDbNameWillRunUntilQuit()
{
$this->expectOutputString('connected.closed.');

$loop = \React\EventLoop\Factory::create();
$factory = new Factory($loop);

$uri = $this->getConnectionString(array('dbname' => ''));
$factory->createConnection($uri)->then(function (ConnectionInterface $connection) {
echo 'connected.';
$connection->quit()->then(function () {
echo 'closed.';
});
}, 'printf')->then(null, 'printf');

$loop->run();
}

public function testConnectWithValidAuthWillIgnoreNegativeTimeoutAndRunUntilQuit()
{
$this->expectOutputString('connected.closed.');
Expand Down
19 changes: 19 additions & 0 deletions tests/ResultQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,25 @@ public function testSimpleSelect()
$loop->run();
}

/**
* @depends testSimpleSelect
*/
public function testSimpleSelectFromLazyConnectionWithoutDatabaseNameReturnsSameData()
{
$loop = \React\EventLoop\Factory::create();
$factory = new Factory($loop);

$uri = $this->getConnectionString(array('dbname' => ''));
$connection = $factory->createLazyConnection($uri);

$connection->query('select * from test.book')->then(function (QueryResult $command) {
$this->assertCount(2, $command->resultRows);
})->done();

$connection->quit();
$loop->run();
}

public function testInvalidSelectShouldFail()
{
$loop = \React\EventLoop\Factory::create();
Expand Down

0 comments on commit 4acae8d

Please sign in to comment.