Skip to content

Commit 2aed762

Browse files
author
Eugene Leonovich
committed
Flush spaces after successful authentication
Ref: tarantool/tarantool-php#71
1 parent 4ffeee4 commit 2aed762

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

src/Client.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,19 @@ public function isDisconnected()
6060

6161
public function authenticate($username, $password)
6262
{
63-
$this->username = $username;
64-
$this->password = $password;
65-
6663
if ($this->isDisconnected()) {
6764
$this->salt = $this->connection->open();
6865
}
6966

7067
$request = new AuthenticateRequest($this->salt, $username, $password);
68+
$response = $this->sendRequest($request);
7169

72-
return $this->sendRequest($request);
70+
$this->username = $username;
71+
$this->password = $password;
72+
73+
$this->flushSpaces();
74+
75+
return $response;
7376
}
7477

7578
public function ping()

tests/Integration/ClientTest.php

+39
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Tarantool\Tests\Integration;
44

5+
use Tarantool\Exception\Exception;
56
use Tarantool\Tests\Assert;
67

78
class ClientTest extends \PHPUnit_Framework_TestCase
@@ -77,4 +78,42 @@ public function testFlushSpaces()
7778

7879
$this->assertSame(4, Utils::getTotalSelectCalls() - $total);
7980
}
81+
82+
public function testSpacesAreFlushedAfterSuccessfulAuthentication()
83+
{
84+
$client = Utils::createClient();
85+
86+
$client->getSpace('space_conn')->select();
87+
$client->authenticate('user_foo', 'foo');
88+
89+
try {
90+
$client->getSpace('space_conn')->select();
91+
} catch (Exception $e) {
92+
// this error means that the client tried to select 'space_conn'
93+
// from '_vspace' to get the space id instead of getting it directly
94+
// from the cache (otherwise it will be 'Read access denied' error)
95+
$this->assertSame("Space 'space_conn' does not exist", $e->getMessage());
96+
97+
return;
98+
}
99+
100+
$this->fail();
101+
}
102+
103+
public function testSpacesAreNotFlushedAfterFailedAuthentication()
104+
{
105+
$client = Utils::createClient();
106+
107+
$client->getSpace('space_conn')->select();
108+
$total = Utils::getTotalSelectCalls();
109+
110+
try {
111+
$client->authenticate('user_foo', 'incorrect_password');
112+
} catch (Exception $e) {
113+
$this->assertSame("Incorrect password supplied for user 'user_foo'", $e->getMessage());
114+
}
115+
116+
$client->getSpace('space_conn')->select();
117+
$this->assertSame(1, Utils::getTotalSelectCalls() - $total);
118+
}
80119
}

0 commit comments

Comments
 (0)