Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix authentication to Tarantool >= 2.11 #175

Merged
merged 3 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/third_party/tp.h
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,9 @@ enum tp_request_type {

static const uint32_t SCRAMBLE_SIZE = 20;

static const char* CHAP_SHA1_AUTH_METHOD = "chap-sha1";
static const uint32_t CHAP_SHA1_AUTH_METHOD_SIZE = 9;

/**
* Receive greetings from the server.
* Note, the input buffer is not copied,
Expand Down Expand Up @@ -1289,7 +1292,7 @@ tp_auth(struct tp *p, const char *salt_base64, const char *user, int ulen, const
mp_sizeof_uint(TP_TUPLE);
if (!nopass)
sz += mp_sizeof_array(2) +
mp_sizeof_str(0) +
mp_sizeof_str(CHAP_SHA1_AUTH_METHOD_SIZE) +
mp_sizeof_str(SCRAMBLE_SIZE);
else
sz += mp_sizeof_array(0);
Expand All @@ -1310,7 +1313,7 @@ tp_auth(struct tp *p, const char *salt_base64, const char *user, int ulen, const
h = mp_encode_uint(h, TP_TUPLE);
if (!nopass) {
h = mp_encode_array(h, 2);
h = mp_encode_str(h, 0, 0);
h = mp_encode_str(h, CHAP_SHA1_AUTH_METHOD, CHAP_SHA1_AUTH_METHOD_SIZE);

// char salt[64];
zend_string *salt = NULL;
Expand Down
8 changes: 4 additions & 4 deletions test/CreateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ public function test_06_bad_credentials() {
$this->assertTrue($c->ping());

$this->expectException(TarantoolClientError::class);
$this->expectExceptionMessage(
'Incorrect password supplied for user');
$this->expectExceptionMessageMatches(
'/(Incorrect password supplied for user)|(User not found or supplied credentials are invalid)/');
$c->authenticate('test', 'bad_password');
}

Expand All @@ -118,8 +118,8 @@ public function test_07_bad_guest_credentials() {
$this->assertTrue($c->ping());

$this->expectException(TarantoolClientError::class);
$this->expectExceptionMessage(
'Incorrect password supplied for user');
$this->expectExceptionMessageMatches(
'/(Incorrect password supplied for user)|(User not found or supplied credentials are invalid)/');
$c->authenticate('guest', 'guest');
}

Expand Down
4 changes: 2 additions & 2 deletions test/DMLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public function test_16_hash_select() {
self::$tarantool->select("test_hash", null, null, null, null, TARANTOOL::ITERATOR_EQ);
$this->assertFalse(True);
} catch (TarantoolClientError $e) {
$this->assertRegExp('(Invalid key part|via a partial key)', $e->getMessage());
$this->assertMatchesRegularExpression('(Invalid key part|via a partial key)', $e->getMessage());
}
}

Expand All @@ -373,7 +373,7 @@ public function test_17_01_it_clienterror($spc, $itype, $xcmsg) {
self::$tarantool->select($spc, null, null, null, null, $itype);
$this->assertFalse(True);
} catch (TarantoolClientError $e) {
$this->assertRegExp($xcmsg, $e->getMessage());
$this->assertMatchesRegularExpression($xcmsg, $e->getMessage());
}
}

Expand Down
23 changes: 23 additions & 0 deletions test/PhpUnitCompat.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,28 @@ public function expectExceptionMessageMatches($regularExpression) {
}
}

/*
* AssertMatchesRegularExpressionTrait (private).
*
* phpunit-8 provides the new name for the
* assertRegExp() method:
* assertMatchesRegularExpression(). phpunit-10 removes the old name.
*
* This trait adds assertMatchesRegularExpression() method for
* phpunit-6, phpunit-7, phpunit-8 and phpunit-9.
*/
if ($testCaseRef->hasMethod('assertMatchesRegularExpression')) {
trait AssertMatchesRegularExpressionTrait {
/* Nothing to define. */
}
} else {
trait AssertMatchesRegularExpressionTrait {
public function assertMatchesRegularExpression($pattern, $string, $message = '') {
self::assertRegExp($pattern, $string, $message);
}
}
}

/*
* TestCaseCompat (public).
*
Expand All @@ -240,4 +262,5 @@ trait TestCaseCompat
use SetUpTearDownTrait;
use AssertStringContainsStringTrait;
use ExpectExceptionMessageMatchesTrait;
use AssertMatchesRegularExpressionTrait;
}
1 change: 0 additions & 1 deletion test/shared/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<file>test/DMLTest.php</file>
<file>test/MockTest.php</file>
<file>test/MsgPackTest.php</file>
<file>test/AssertTest.php</file>
oleg-jukovec marked this conversation as resolved.
Show resolved Hide resolved
<file>test/RandomTest.php</file>
</testsuite>
</testsuites>
Expand Down