From 52d3e1f337257f97bc61e7915f10a799983a1e2d Mon Sep 17 00:00:00 2001 From: Oleg Jukovec Date: Mon, 24 Jun 2024 14:21:36 +0300 Subject: [PATCH 1/3] Fix authentication to Tarantool >= 2.10 The authentication method is checked on the server-side since Tarantool 2.11 [1]. In fact, this has been required before [2]. So we need to add the authorization method value into the AUTH_REQUEST. 1. https://github.com/tarantool/tarantool/commit/b5754d3fb404641ac35c2601be4777e1db0890bb 2. https://www.tarantool.io/en/doc/1.10/dev_guide/internals_index/#authentication Co-authored-by: Ivan Keberlein --- src/third_party/tp.h | 7 +++++-- test/CreateTest.php | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/third_party/tp.h b/src/third_party/tp.h index 2f6a76f..cc417d0 100644 --- a/src/third_party/tp.h +++ b/src/third_party/tp.h @@ -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, @@ -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); @@ -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; diff --git a/test/CreateTest.php b/test/CreateTest.php index 7ece97e..a9ceb2b 100644 --- a/test/CreateTest.php +++ b/test/CreateTest.php @@ -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'); } @@ -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'); } From 7aa6465b7465d5e977b1d5a7e234971942b2a470 Mon Sep 17 00:00:00 2001 From: Oleg Jukovec Date: Mon, 24 Jun 2024 15:00:31 +0300 Subject: [PATCH 2/3] Fix test run with PHPUnit 11.2.4 The patch replaces `assertRegExp` with `assertMatchesRegularExpression` because the first one is outdated. Closes #157 --- test/DMLTest.php | 4 ++-- test/PhpUnitCompat.php | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/test/DMLTest.php b/test/DMLTest.php index c2d1e5b..558551d 100644 --- a/test/DMLTest.php +++ b/test/DMLTest.php @@ -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()); } } @@ -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()); } } diff --git a/test/PhpUnitCompat.php b/test/PhpUnitCompat.php index fbc44f6..d5eca90 100644 --- a/test/PhpUnitCompat.php +++ b/test/PhpUnitCompat.php @@ -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). * @@ -240,4 +262,5 @@ trait TestCaseCompat use SetUpTearDownTrait; use AssertStringContainsStringTrait; use ExpectExceptionMessageMatchesTrait; + use AssertMatchesRegularExpressionTrait; } From 196eae7888c48dc1c8f22588bd91a6fd5262f079 Mon Sep 17 00:00:00 2001 From: Oleg Jukovec Date: Mon, 24 Jun 2024 15:02:32 +0300 Subject: [PATCH 3/3] Fix test run fail due to AssertTest.php duplicate The patch removes `test/AssertTest.php` duplicate line from the `test/shared/phpunit.xml`. --- test/shared/phpunit.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/test/shared/phpunit.xml b/test/shared/phpunit.xml index 06d277b..f62f649 100644 --- a/test/shared/phpunit.xml +++ b/test/shared/phpunit.xml @@ -11,7 +11,6 @@ test/DMLTest.php test/MockTest.php test/MsgPackTest.php - test/AssertTest.php test/RandomTest.php