diff --git a/libraries/classes/Controllers/Setup/ShowConfigController.php b/libraries/classes/Controllers/Setup/ShowConfigController.php index 292da09d28..5c43dd067f 100644 --- a/libraries/classes/Controllers/Setup/ShowConfigController.php +++ b/libraries/classes/Controllers/Setup/ShowConfigController.php @@ -36,8 +36,6 @@ final class ShowConfigController $GLOBALS['ConfigFile']->resetConfigData(); // drop post data $response->generateHeader303('../setup/index.php' . Url::getCommonRaw(['route' => '/setup'])); - - return; } /** @var mixed $submitDownload */ diff --git a/libraries/classes/Plugins/Auth/AuthenticationConfig.php b/libraries/classes/Plugins/Auth/AuthenticationConfig.php index 3855062a0f..480d3a2c1f 100644 --- a/libraries/classes/Plugins/Auth/AuthenticationConfig.php +++ b/libraries/classes/Plugins/Auth/AuthenticationConfig.php @@ -28,20 +28,18 @@ class AuthenticationConfig extends AuthenticationPlugin { /** * Displays authentication form - * - * @return bool always true */ - public function showLoginForm(): bool + public function showLoginForm(): void { $response = ResponseRenderer::getInstance(); - if ($response->isAjax()) { - $response->setRequestStatus(false); - // reload_flag removes the token parameter from the URL and reloads - $response->addJSON('reload_flag', '1'); - $response->callExit(); + if (! $response->isAjax()) { + return; } - return true; + $response->setRequestStatus(false); + // reload_flag removes the token parameter from the URL and reloads + $response->addJSON('reload_flag', '1'); + $response->callExit(); } /** @@ -66,7 +64,7 @@ class AuthenticationConfig extends AuthenticationPlugin * * @param string $failure String describing why authentication has failed */ - public function showFailure(string $failure): void + public function showFailure(string $failure): never { parent::showFailure($failure); diff --git a/libraries/classes/Plugins/Auth/AuthenticationCookie.php b/libraries/classes/Plugins/Auth/AuthenticationCookie.php index 23366e32a5..f8f78bdd7f 100644 --- a/libraries/classes/Plugins/Auth/AuthenticationCookie.php +++ b/libraries/classes/Plugins/Auth/AuthenticationCookie.php @@ -63,7 +63,7 @@ class AuthenticationCookie extends AuthenticationPlugin * * @global string $conn_error the last connection error */ - public function showLoginForm(): bool + public function showLoginForm(): never { $GLOBALS['conn_error'] ??= null; @@ -379,7 +379,6 @@ class AuthenticationCookie extends AuthenticationPlugin SessionCache::remove('proc_priv'); $this->showFailure('no-activity'); - ResponseRenderer::getInstance()->callExit(); } // check password cookie @@ -552,12 +551,9 @@ class AuthenticationCookie extends AuthenticationPlugin * prepares error message and switches to showLoginForm() which display the error * and the login form * - * this function MUST exit/quit the application, - * currently done by call to showLoginForm() - * * @param string $failure String describing why authentication has failed */ - public function showFailure(string $failure): void + public function showFailure(string $failure): never { $GLOBALS['conn_error'] ??= null; diff --git a/libraries/classes/Plugins/Auth/AuthenticationHttp.php b/libraries/classes/Plugins/Auth/AuthenticationHttp.php index ca8358200c..bb2b77c88e 100644 --- a/libraries/classes/Plugins/Auth/AuthenticationHttp.php +++ b/libraries/classes/Plugins/Auth/AuthenticationHttp.php @@ -30,10 +30,8 @@ class AuthenticationHttp extends AuthenticationPlugin { /** * Displays authentication form and redirect as necessary - * - * @return bool always true (no return indeed) */ - public function showLoginForm(): bool + public function showLoginForm(): never { $response = ResponseRenderer::getInstance(); if ($response->isAjax()) { @@ -43,13 +41,13 @@ class AuthenticationHttp extends AuthenticationPlugin $response->callExit(); } - return $this->authForm(); + $this->authForm(); } /** * Displays authentication form */ - public function authForm(): bool + public function authForm(): never { if (empty($GLOBALS['cfg']['Server']['auth_http_realm'])) { if (empty($GLOBALS['cfg']['Server']['verbose'])) { @@ -179,7 +177,7 @@ class AuthenticationHttp extends AuthenticationPlugin * * @param string $failure String describing why authentication has failed */ - public function showFailure(string $failure): void + public function showFailure(string $failure): never { parent::showFailure($failure); diff --git a/libraries/classes/Plugins/Auth/AuthenticationSignon.php b/libraries/classes/Plugins/Auth/AuthenticationSignon.php index 418bb7f7a5..76f52dcc27 100644 --- a/libraries/classes/Plugins/Auth/AuthenticationSignon.php +++ b/libraries/classes/Plugins/Auth/AuthenticationSignon.php @@ -32,7 +32,7 @@ class AuthenticationSignon extends AuthenticationPlugin /** * Displays authentication form */ - public function showLoginForm(): bool + public function showLoginForm(): never { $response = ResponseRenderer::getInstance(); $response->disable(); @@ -244,7 +244,7 @@ class AuthenticationSignon extends AuthenticationPlugin * * @param string $failure String describing why authentication has failed */ - public function showFailure(string $failure): void + public function showFailure(string $failure): never { parent::showFailure($failure); diff --git a/libraries/classes/Plugins/AuthenticationPlugin.php b/libraries/classes/Plugins/AuthenticationPlugin.php index a13f05611e..2a6071bef6 100644 --- a/libraries/classes/Plugins/AuthenticationPlugin.php +++ b/libraries/classes/Plugins/AuthenticationPlugin.php @@ -61,7 +61,7 @@ abstract class AuthenticationPlugin /** * Displays authentication form */ - abstract public function showLoginForm(): bool; + abstract public function showLoginForm(): void; /** * Gets authentication credentials diff --git a/libraries/classes/ResponseRenderer.php b/libraries/classes/ResponseRenderer.php index cf05ce51d0..537fc7105a 100644 --- a/libraries/classes/ResponseRenderer.php +++ b/libraries/classes/ResponseRenderer.php @@ -439,7 +439,7 @@ class ResponseRenderer * * @param string $location will set location to redirect. */ - public function generateHeader303(string $location): void + public function generateHeader303(string $location): never { $this->setHttpResponseCode(303); $this->header('Location: ' . $location); diff --git a/libraries/classes/Setup/FormProcessing.php b/libraries/classes/Setup/FormProcessing.php index 0efa6d786c..d3ee17c081 100644 --- a/libraries/classes/Setup/FormProcessing.php +++ b/libraries/classes/Setup/FormProcessing.php @@ -48,8 +48,6 @@ class FormProcessing $response = ResponseRenderer::getInstance(); $response->disable(); $response->generateHeader303('../setup/index.php' . Url::getCommonRaw(['route' => '/setup'])); - - return; } // form has errors, show warning diff --git a/psalm-baseline.xml b/psalm-baseline.xml index dc9dc053ee..9754ea64db 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -8177,9 +8177,6 @@ - - bool - @@ -8243,7 +8240,6 @@ bool - bool @@ -8271,9 +8267,6 @@ $oldUser - - bool - @@ -8297,9 +8290,6 @@ password]]> user]]> - - bool - @@ -8326,9 +8316,6 @@ issetCookie - - bool - diff --git a/test/classes/Plugins/Auth/AuthenticationConfigTest.php b/test/classes/Plugins/Auth/AuthenticationConfigTest.php index dab16f20a3..ae0abac14d 100644 --- a/test/classes/Plugins/Auth/AuthenticationConfigTest.php +++ b/test/classes/Plugins/Auth/AuthenticationConfigTest.php @@ -94,7 +94,7 @@ class AuthenticationConfigTest extends AbstractTestCase $html = ob_get_clean(); - $this->assertInstanceOf(ExitException::class, $throwable ?? null); + $this->assertInstanceOf(ExitException::class, $throwable); $this->assertIsString($html); diff --git a/test/classes/Plugins/Auth/AuthenticationCookieTest.php b/test/classes/Plugins/Auth/AuthenticationCookieTest.php index 885859e04b..48b5047902 100644 --- a/test/classes/Plugins/Auth/AuthenticationCookieTest.php +++ b/test/classes/Plugins/Auth/AuthenticationCookieTest.php @@ -73,7 +73,7 @@ class AuthenticationCookieTest extends AbstractNetworkTestCase } #[Group('medium')] - public function testAuthErrorAJAX(): void + public function testAuthErrorAJAX(): never { $mockResponse = $this->mockResponse(); @@ -191,7 +191,7 @@ class AuthenticationCookieTest extends AbstractNetworkTestCase $result = ob_get_clean(); - $this->assertInstanceOf(ExitException::class, $throwable ?? null); + $this->assertInstanceOf(ExitException::class, $throwable); $this->assertIsString($result); @@ -276,7 +276,7 @@ class AuthenticationCookieTest extends AbstractNetworkTestCase $result = ob_get_clean(); - $this->assertInstanceOf(ExitException::class, $throwable ?? null); + $this->assertInstanceOf(ExitException::class, $throwable); $this->assertIsString($result); @@ -355,7 +355,7 @@ class AuthenticationCookieTest extends AbstractNetworkTestCase $result = ob_get_clean(); - $this->assertInstanceOf(ExitException::class, $throwable ?? null); + $this->assertInstanceOf(ExitException::class, $throwable); $this->assertIsString($result); @@ -643,7 +643,8 @@ class AuthenticationCookieTest extends AbstractNetworkTestCase ->will($this->returnValue('testBF')); $this->object->expects($this->once()) - ->method('showFailure'); + ->method('showFailure') + ->willThrowException(new ExitException()); $this->expectException(ExitException::class); $this->object->readCredentials(); @@ -711,6 +712,10 @@ class AuthenticationCookieTest extends AbstractNetworkTestCase ->onlyMethods(['showLoginForm']) ->getMock(); + $this->object->expects($this->exactly(1)) + ->method('showLoginForm') + ->willThrowException(new ExitException()); + $GLOBALS['server'] = 2; $_COOKIE['pmaAuth-2'] = 'pass'; @@ -718,7 +723,10 @@ class AuthenticationCookieTest extends AbstractNetworkTestCase ['Cache-Control: no-store, no-cache, must-revalidate'], ['Pragma: no-cache'], ); - $this->object->showFailure('empty-denied'); + try { + $this->object->showFailure('empty-denied'); + } catch (ExitException) { + } $this->assertEquals( $GLOBALS['conn_error'], @@ -773,6 +781,10 @@ class AuthenticationCookieTest extends AbstractNetworkTestCase ->onlyMethods(['showLoginForm']) ->getMock(); + $this->object->expects($this->exactly(1)) + ->method('showLoginForm') + ->willThrowException(new ExitException()); + $GLOBALS['server'] = 2; $_COOKIE['pmaAuth-2'] = 'pass'; @@ -780,7 +792,10 @@ class AuthenticationCookieTest extends AbstractNetworkTestCase ['Cache-Control: no-store, no-cache, must-revalidate'], ['Pragma: no-cache'], ); - $this->object->showFailure('allow-denied'); + try { + $this->object->showFailure('allow-denied'); + } catch (ExitException) { + } $this->assertEquals($GLOBALS['conn_error'], 'Access denied!'); } @@ -792,6 +807,10 @@ class AuthenticationCookieTest extends AbstractNetworkTestCase ->onlyMethods(['showLoginForm']) ->getMock(); + $this->object->expects($this->exactly(1)) + ->method('showLoginForm') + ->willThrowException(new ExitException()); + $GLOBALS['server'] = 2; $_COOKIE['pmaAuth-2'] = 'pass'; @@ -802,7 +821,10 @@ class AuthenticationCookieTest extends AbstractNetworkTestCase ['Cache-Control: no-store, no-cache, must-revalidate'], ['Pragma: no-cache'], ); - $this->object->showFailure('no-activity'); + try { + $this->object->showFailure('no-activity'); + } catch (ExitException) { + } $this->assertEquals( $GLOBALS['conn_error'], @@ -818,6 +840,10 @@ class AuthenticationCookieTest extends AbstractNetworkTestCase ->onlyMethods(['showLoginForm']) ->getMock(); + $this->object->expects($this->exactly(1)) + ->method('showLoginForm') + ->willThrowException(new ExitException()); + $GLOBALS['server'] = 2; $_COOKIE['pmaAuth-2'] = 'pass'; @@ -836,7 +862,10 @@ class AuthenticationCookieTest extends AbstractNetworkTestCase ['Cache-Control: no-store, no-cache, must-revalidate'], ['Pragma: no-cache'], ); - $this->object->showFailure(''); + try { + $this->object->showFailure(''); + } catch (ExitException) { + } $this->assertEquals($GLOBALS['conn_error'], '#42 Cannot log in to the MySQL server'); } @@ -848,6 +877,10 @@ class AuthenticationCookieTest extends AbstractNetworkTestCase ->onlyMethods(['showLoginForm']) ->getMock(); + $this->object->expects($this->exactly(1)) + ->method('showLoginForm') + ->willThrowException(new ExitException()); + $dbi = $this->getMockBuilder(DatabaseInterface::class) ->disableOriginalConstructor() ->getMock(); @@ -866,7 +899,10 @@ class AuthenticationCookieTest extends AbstractNetworkTestCase ['Cache-Control: no-store, no-cache, must-revalidate'], ['Pragma: no-cache'], ); - $this->object->showFailure(''); + try { + $this->object->showFailure(''); + } catch (ExitException) { + } $this->assertEquals($GLOBALS['conn_error'], 'Cannot log in to the MySQL server'); } diff --git a/test/classes/Plugins/Auth/AuthenticationHttpTest.php b/test/classes/Plugins/Auth/AuthenticationHttpTest.php index e1693cd872..d805e825d8 100644 --- a/test/classes/Plugins/Auth/AuthenticationHttpTest.php +++ b/test/classes/Plugins/Auth/AuthenticationHttpTest.php @@ -314,7 +314,7 @@ class AuthenticationHttpTest extends AbstractNetworkTestCase $result = ob_get_clean(); - $this->assertInstanceOf(ExitException::class, $throwable ?? null); + $this->assertInstanceOf(ExitException::class, $throwable); $this->assertIsString($result); @@ -326,15 +326,20 @@ class AuthenticationHttpTest extends AbstractNetworkTestCase ->getMock(); $this->object->expects($this->exactly(2)) - ->method('authForm'); + ->method('authForm') + ->willThrowException(new ExitException()); // case 2 $GLOBALS['cfg']['Server']['host'] = 'host'; $GLOBALS['errno'] = 1045; - $this->object->showFailure(''); + try { + $this->object->showFailure(''); + } catch (ExitException) { + } // case 3 $GLOBALS['errno'] = 1043; + $this->expectException(ExitException::class); $this->object->showFailure(''); } } diff --git a/test/classes/Plugins/Auth/AuthenticationSignonTest.php b/test/classes/Plugins/Auth/AuthenticationSignonTest.php index 28e4a9678e..e81eb2ba78 100644 --- a/test/classes/Plugins/Auth/AuthenticationSignonTest.php +++ b/test/classes/Plugins/Auth/AuthenticationSignonTest.php @@ -67,7 +67,7 @@ class AuthenticationSignonTest extends AbstractNetworkTestCase $result = ob_get_clean(); - $this->assertInstanceOf(ExitException::class, $throwable ?? null); + $this->assertInstanceOf(ExitException::class, $throwable); $this->assertIsString($result); @@ -229,9 +229,13 @@ class AuthenticationSignonTest extends AbstractNetworkTestCase ->getMock(); $this->object->expects($this->exactly(1)) - ->method('showLoginForm'); + ->method('showLoginForm') + ->willThrowException(new ExitException()); - $this->object->showFailure('empty-denied'); + try { + $this->object->showFailure('empty-denied'); + } catch (ExitException) { + } $this->assertEquals( 'Login without a password is forbidden by configuration (see AllowNoPassword)', @@ -250,9 +254,13 @@ class AuthenticationSignonTest extends AbstractNetworkTestCase ->getMock(); $this->object->expects($this->exactly(1)) - ->method('showLoginForm'); + ->method('showLoginForm') + ->willThrowException(new ExitException()); - $this->object->showFailure('allow-denied'); + try { + $this->object->showFailure('allow-denied'); + } catch (ExitException) { + } $this->assertEquals('Access denied!', $_SESSION['PMA_single_signon_error_message']); } @@ -268,11 +276,15 @@ class AuthenticationSignonTest extends AbstractNetworkTestCase ->getMock(); $this->object->expects($this->exactly(1)) - ->method('showLoginForm'); + ->method('showLoginForm') + ->willThrowException(new ExitException()); $GLOBALS['cfg']['LoginCookieValidity'] = '1440'; - $this->object->showFailure('no-activity'); + try { + $this->object->showFailure('no-activity'); + } catch (ExitException) { + } $this->assertEquals( 'You have been automatically logged out due to inactivity of' @@ -293,7 +305,8 @@ class AuthenticationSignonTest extends AbstractNetworkTestCase ->getMock(); $this->object->expects($this->exactly(1)) - ->method('showLoginForm'); + ->method('showLoginForm') + ->willThrowException(new ExitException()); $dbi = $this->getMockBuilder(DatabaseInterface::class) ->disableOriginalConstructor() @@ -305,7 +318,10 @@ class AuthenticationSignonTest extends AbstractNetworkTestCase $GLOBALS['dbi'] = $dbi; - $this->object->showFailure(''); + try { + $this->object->showFailure(''); + } catch (ExitException) { + } $this->assertEquals('error<123>', $_SESSION['PMA_single_signon_error_message']); } @@ -322,7 +338,8 @@ class AuthenticationSignonTest extends AbstractNetworkTestCase ->getMock(); $this->object->expects($this->exactly(1)) - ->method('showLoginForm'); + ->method('showLoginForm') + ->willThrowException(new ExitException()); $dbi = $this->getMockBuilder(DatabaseInterface::class) ->disableOriginalConstructor() @@ -334,7 +351,10 @@ class AuthenticationSignonTest extends AbstractNetworkTestCase $GLOBALS['dbi'] = $dbi; - $this->object->showFailure(''); + try { + $this->object->showFailure(''); + } catch (ExitException) { + } $this->assertEquals('Cannot log in to the MySQL server', $_SESSION['PMA_single_signon_error_message']); }