From 2722ea717df71facfa93db302809ea2a51b3f164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Tue, 21 Feb 2023 13:43:14 -0300 Subject: [PATCH] Replace escapeString with quoteString in AccountLocking class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- .../Server/Privileges/AccountLocking.php | 12 ++++---- psalm-baseline.xml | 16 ----------- .../Server/Privileges/AccountLockingTest.php | 28 +++++++------------ 3 files changed, 16 insertions(+), 40 deletions(-) diff --git a/libraries/classes/Server/Privileges/AccountLocking.php b/libraries/classes/Server/Privileges/AccountLocking.php index 68c62c2f59..ccb65c77bf 100644 --- a/libraries/classes/Server/Privileges/AccountLocking.php +++ b/libraries/classes/Server/Privileges/AccountLocking.php @@ -27,9 +27,9 @@ final class AccountLocking } $statement = sprintf( - 'ALTER USER \'%s\'@\'%s\' ACCOUNT LOCK;', - $this->dbi->escapeString($user), - $this->dbi->escapeString($host) + 'ALTER USER %s@%s ACCOUNT LOCK;', + $this->dbi->quoteString($user), + $this->dbi->quoteString($host) ); if ($this->dbi->tryQuery($statement) !== false) { return; @@ -48,9 +48,9 @@ final class AccountLocking } $statement = sprintf( - 'ALTER USER \'%s\'@\'%s\' ACCOUNT UNLOCK;', - $this->dbi->escapeString($user), - $this->dbi->escapeString($host) + 'ALTER USER %s@%s ACCOUNT UNLOCK;', + $this->dbi->quoteString($user), + $this->dbi->quoteString($host) ); if ($this->dbi->tryQuery($statement) !== false) { return; diff --git a/psalm-baseline.xml b/psalm-baseline.xml index b880f502f5..e42485809a 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -14177,14 +14177,6 @@ - - - escapeString - escapeString - escapeString - escapeString - - @@ -18096,14 +18088,6 @@ assertIsArray - - - withConsecutive - withConsecutive - withConsecutive - withConsecutive - - escapeString diff --git a/test/classes/Server/Privileges/AccountLockingTest.php b/test/classes/Server/Privileges/AccountLockingTest.php index c1bfa7cc8d..9892d28a3b 100644 --- a/test/classes/Server/Privileges/AccountLockingTest.php +++ b/test/classes/Server/Privileges/AccountLockingTest.php @@ -20,10 +20,8 @@ class AccountLockingTest extends TestCase $dbi = $this->createMock(DatabaseInterface::class); $dbi->expects($this->once())->method('isMariaDB')->willReturn(true); $dbi->expects($this->once())->method('getVersion')->willReturn(100402); - $dbi->expects($this->exactly(2)) - ->method('escapeString') - ->withConsecutive([$this->equalTo('test.user')], [$this->equalTo('test.host')]) - ->willReturnOnConsecutiveCalls('test.user', 'test.host'); + $dbi->expects($this->exactly(2))->method('quoteString') + ->will($this->returnCallback(static fn (string $string) => "'" . $string . "'")); $dbi->expects($this->once()) ->method('tryQuery') ->with($this->equalTo('ALTER USER \'test.user\'@\'test.host\' ACCOUNT LOCK;')) @@ -39,10 +37,8 @@ class AccountLockingTest extends TestCase $dbi = $this->createMock(DatabaseInterface::class); $dbi->expects($this->once())->method('isMariaDB')->willReturn(true); $dbi->expects($this->once())->method('getVersion')->willReturn(100402); - $dbi->expects($this->exactly(2)) - ->method('escapeString') - ->withConsecutive([$this->equalTo('test.user')], [$this->equalTo('test.host')]) - ->willReturnOnConsecutiveCalls('test.user', 'test.host'); + $dbi->expects($this->exactly(2))->method('quoteString') + ->will($this->returnCallback(static fn (string $string) => "'" . $string . "'")); $dbi->expects($this->once()) ->method('tryQuery') ->with($this->equalTo('ALTER USER \'test.user\'@\'test.host\' ACCOUNT LOCK;')) @@ -62,7 +58,7 @@ class AccountLockingTest extends TestCase $dbi = $this->createMock(DatabaseInterface::class); $dbi->expects($this->once())->method('isMariaDB')->willReturn(true); $dbi->expects($this->once())->method('getVersion')->willReturn(100401); - $dbi->expects($this->never())->method('escapeString'); + $dbi->expects($this->never())->method('quoteString'); $dbi->expects($this->never())->method('tryQuery'); $dbi->expects($this->never())->method('getError'); @@ -79,10 +75,8 @@ class AccountLockingTest extends TestCase $dbi = $this->createMock(DatabaseInterface::class); $dbi->expects($this->once())->method('isMariaDB')->willReturn(true); $dbi->expects($this->once())->method('getVersion')->willReturn(100402); - $dbi->expects($this->exactly(2)) - ->method('escapeString') - ->withConsecutive([$this->equalTo('test.user')], [$this->equalTo('test.host')]) - ->willReturnOnConsecutiveCalls('test.user', 'test.host'); + $dbi->expects($this->exactly(2))->method('quoteString') + ->will($this->returnCallback(static fn (string $string) => "'" . $string . "'")); $dbi->expects($this->once()) ->method('tryQuery') ->with($this->equalTo('ALTER USER \'test.user\'@\'test.host\' ACCOUNT UNLOCK;')) @@ -98,10 +92,8 @@ class AccountLockingTest extends TestCase $dbi = $this->createMock(DatabaseInterface::class); $dbi->expects($this->once())->method('isMariaDB')->willReturn(true); $dbi->expects($this->once())->method('getVersion')->willReturn(100402); - $dbi->expects($this->exactly(2)) - ->method('escapeString') - ->withConsecutive([$this->equalTo('test.user')], [$this->equalTo('test.host')]) - ->willReturnOnConsecutiveCalls('test.user', 'test.host'); + $dbi->expects($this->exactly(2))->method('quoteString') + ->will($this->returnCallback(static fn (string $string) => "'" . $string . "'")); $dbi->expects($this->once()) ->method('tryQuery') ->with($this->equalTo('ALTER USER \'test.user\'@\'test.host\' ACCOUNT UNLOCK;')) @@ -121,7 +113,7 @@ class AccountLockingTest extends TestCase $dbi = $this->createMock(DatabaseInterface::class); $dbi->expects($this->once())->method('isMariaDB')->willReturn(false); $dbi->expects($this->once())->method('getVersion')->willReturn(50705); - $dbi->expects($this->never())->method('escapeString'); + $dbi->expects($this->never())->method('quoteString'); $dbi->expects($this->never())->method('tryQuery'); $dbi->expects($this->never())->method('getError');