-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use local methods to "override" native PHP functions
- Loading branch information
Showing
12 changed files
with
535 additions
and
321 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
phpunit/functional/Glpi/System/Requirement/MysqliMysqlndTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
/** | ||
* --------------------------------------------------------------------- | ||
* | ||
* GLPI - Gestionnaire Libre de Parc Informatique | ||
* | ||
* http://glpi-project.org | ||
* | ||
* @copyright 2015-2025 Teclib' and contributors. | ||
* @copyright 2003-2014 by the INDEPNET Development Team. | ||
* @licence https://www.gnu.org/licenses/gpl-3.0.html | ||
* | ||
* --------------------------------------------------------------------- | ||
* | ||
* LICENSE | ||
* | ||
* This file is part of GLPI. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
* --------------------------------------------------------------------- | ||
*/ | ||
|
||
namespace tests\units\Glpi\System\Requirement; | ||
|
||
use Glpi\System\Requirement\MysqliMysqlnd; | ||
|
||
class MysqliMysqlndTest extends \GLPITestCase | ||
{ | ||
public function testCheckUsingMysqlnd() | ||
{ | ||
$instance = $this->getMockBuilder(MysqliMysqlnd::class) | ||
->onlyMethods(['isExtensionLoaded', 'isMysqlND']) | ||
->getMock(); | ||
$instance->method('isExtensionLoaded')->willReturn(true); | ||
$instance->method('isMysqlND')->willReturn(true); | ||
$this->assertTrue($instance->isValidated()); | ||
$this->assertEquals( | ||
['mysqli extension is installed.'], | ||
$instance->getValidationMessages() | ||
); | ||
} | ||
|
||
public function testCheckUsingAlternativeDriver() | ||
{ | ||
$instance = $this->getMockBuilder(MysqliMysqlnd::class) | ||
->onlyMethods(['isExtensionLoaded', 'isMysqlND']) | ||
->getMock(); | ||
$instance->method('isExtensionLoaded')->willReturn(true); | ||
$instance->method('isMysqlND')->willReturn(false); | ||
$this->assertFalse($instance->isValidated()); | ||
$this->assertEquals( | ||
['mysqli extension is installed but is not using mysqlnd driver.'], | ||
$instance->getValidationMessages() | ||
); | ||
} | ||
|
||
public function testCheckOnMissingExtension() | ||
{ | ||
$instance = $this->getMockBuilder(MysqliMysqlnd::class) | ||
->onlyMethods(['isExtensionLoaded']) | ||
->getMock(); | ||
$instance->method('isExtensionLoaded')->willReturn(false); | ||
$this->assertFalse($instance->isValidated()); | ||
$this->assertEquals( | ||
['mysqli extension is missing.'], | ||
$instance->getValidationMessages() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
272 changes: 272 additions & 0 deletions
272
phpunit/functional/Glpi/System/Requirement/SeLinuxTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,272 @@ | ||
<?php | ||
|
||
/** | ||
* --------------------------------------------------------------------- | ||
* | ||
* GLPI - Gestionnaire Libre de Parc Informatique | ||
* | ||
* http://glpi-project.org | ||
* | ||
* @copyright 2015-2025 Teclib' and contributors. | ||
* @copyright 2003-2014 by the INDEPNET Development Team. | ||
* @licence https://www.gnu.org/licenses/gpl-3.0.html | ||
* | ||
* --------------------------------------------------------------------- | ||
* | ||
* LICENSE | ||
* | ||
* This file is part of GLPI. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
* --------------------------------------------------------------------- | ||
*/ | ||
|
||
namespace tests\units\Glpi\System\Requirement; | ||
|
||
use Glpi\System\Requirement\SeLinux; | ||
|
||
class SeLinuxTest extends \GLPITestCase | ||
{ | ||
public function testCheckOutOfContext() | ||
{ | ||
$instance = $this->getMockBuilder(SeLinux::class) | ||
->onlyMethods([ | ||
'doesSelinuxBinariesExists', | ||
'doesSelinuxIsEnabledFunctionExists', | ||
'doesSelinuxGetenforceFunctionExists', | ||
'doesSelinuxBooleanFunctionExists', | ||
]) | ||
->getMock(); | ||
$instance->method('doesSelinuxBinariesExists')->willReturn(false); | ||
$instance->method('doesSelinuxIsEnabledFunctionExists')->willReturn(false); | ||
$instance->method('doesSelinuxGetenforceFunctionExists')->willReturn(false); | ||
$instance->method('doesSelinuxBooleanFunctionExists')->willReturn(false); | ||
|
||
$this->assertFalse($instance->isValidated()); | ||
$this->assertTrue($instance->isOutOfContext()); | ||
} | ||
|
||
public function testCheckWithEnforcesAndActiveBooleans() | ||
{ | ||
$instance = $this->getMockBuilder(SeLinux::class) | ||
->onlyMethods([ | ||
'doesSelinuxBinariesExists', | ||
'doesSelinuxIsEnabledFunctionExists', | ||
'isSelinuxEnabled', | ||
'doesSelinuxGetenforceFunctionExists', | ||
'getSelinxEnforceStatus', | ||
'doesSelinuxBooleanFunctionExists', | ||
'isSelinuxBooleanActive' | ||
]) | ||
->getMock(); | ||
$instance->method('doesSelinuxBinariesExists')->willReturn(true); | ||
$instance->method('doesSelinuxIsEnabledFunctionExists')->willReturn(true); | ||
$instance->method('isSelinuxEnabled')->willReturn(true); | ||
$instance->method('doesSelinuxGetenforceFunctionExists')->willReturn(true); | ||
$instance->method('getSelinxEnforceStatus')->willReturn(1); | ||
$instance->method('doesSelinuxBooleanFunctionExists')->willReturn(true); | ||
$instance->method('isSelinuxBooleanActive')->willReturn(true); | ||
|
||
$this->assertTrue($instance->isValidated()); | ||
$this->assertEquals( | ||
$instance->getValidationMessages(), | ||
['SELinux configuration is OK.'] | ||
); | ||
} | ||
|
||
public function testCheckWithEnforcesAndInactiveNetworkConnect() | ||
{ | ||
$instance = $this->getMockBuilder(SeLinux::class) | ||
->onlyMethods([ | ||
'doesSelinuxBinariesExists', | ||
'doesSelinuxIsEnabledFunctionExists', | ||
'isSelinuxEnabled', | ||
'doesSelinuxGetenforceFunctionExists', | ||
'getSelinxEnforceStatus', | ||
'doesSelinuxBooleanFunctionExists', | ||
'isSelinuxBooleanActive' | ||
]) | ||
->getMock(); | ||
$instance->method('doesSelinuxBinariesExists')->willReturn(true); | ||
$instance->method('doesSelinuxIsEnabledFunctionExists')->willReturn(true); | ||
$instance->method('isSelinuxEnabled')->willReturn(true); | ||
$instance->method('doesSelinuxGetenforceFunctionExists')->willReturn(true); | ||
$instance->method('getSelinxEnforceStatus')->willReturn(1); | ||
$instance->method('doesSelinuxBooleanFunctionExists')->willReturn(true); | ||
$instance->method('isSelinuxBooleanActive')->willReturnCallback( | ||
function ($bool) { | ||
return $bool != 'httpd_can_network_connect'; | ||
} | ||
); | ||
|
||
$this->assertFalse($instance->isValidated()); | ||
$this->assertEquals( | ||
['SELinux boolean httpd_can_network_connect is off, some features may require this to be on.'], | ||
$instance->getValidationMessages() | ||
); | ||
} | ||
|
||
public function testCheckWithEnforcesAndInactiveNetworkConnectDB() | ||
{ | ||
$instance = $this->getMockBuilder(SeLinux::class) | ||
->onlyMethods([ | ||
'doesSelinuxBinariesExists', | ||
'doesSelinuxIsEnabledFunctionExists', | ||
'isSelinuxEnabled', | ||
'doesSelinuxGetenforceFunctionExists', | ||
'getSelinxEnforceStatus', | ||
'doesSelinuxBooleanFunctionExists', | ||
'isSelinuxBooleanActive' | ||
]) | ||
->getMock(); | ||
$instance->method('doesSelinuxBinariesExists')->willReturn(true); | ||
$instance->method('doesSelinuxIsEnabledFunctionExists')->willReturn(true); | ||
$instance->method('isSelinuxEnabled')->willReturn(true); | ||
$instance->method('doesSelinuxGetenforceFunctionExists')->willReturn(true); | ||
$instance->method('getSelinxEnforceStatus')->willReturn(1); | ||
$instance->method('doesSelinuxBooleanFunctionExists')->willReturn(true); | ||
$instance->method('isSelinuxBooleanActive')->willReturnCallback( | ||
function ($bool) { | ||
return $bool != 'httpd_can_network_connect_db'; | ||
} | ||
); | ||
|
||
$this->assertFalse($instance->isValidated()); | ||
$this->assertEquals( | ||
['SELinux boolean httpd_can_network_connect_db is off, some features may require this to be on.'], | ||
$instance->getValidationMessages() | ||
); | ||
} | ||
|
||
public function testCheckWithEnforcesAndInactiveSendmail() | ||
{ | ||
$instance = $this->getMockBuilder(SeLinux::class) | ||
->onlyMethods([ | ||
'doesSelinuxBinariesExists', | ||
'doesSelinuxIsEnabledFunctionExists', | ||
'isSelinuxEnabled', | ||
'doesSelinuxGetenforceFunctionExists', | ||
'getSelinxEnforceStatus', | ||
'doesSelinuxBooleanFunctionExists', | ||
'isSelinuxBooleanActive' | ||
]) | ||
->getMock(); | ||
$instance->method('doesSelinuxBinariesExists')->willReturn(true); | ||
$instance->method('doesSelinuxIsEnabledFunctionExists')->willReturn(true); | ||
$instance->method('isSelinuxEnabled')->willReturn(true); | ||
$instance->method('doesSelinuxGetenforceFunctionExists')->willReturn(true); | ||
$instance->method('getSelinxEnforceStatus')->willReturn(1); | ||
$instance->method('doesSelinuxBooleanFunctionExists')->willReturn(true); | ||
$instance->method('isSelinuxBooleanActive')->willReturnCallback( | ||
function ($bool) { | ||
return $bool != 'httpd_can_sendmail'; | ||
} | ||
); | ||
|
||
$this->assertFalse($instance->isValidated()); | ||
$this->assertEquals( | ||
['SELinux boolean httpd_can_sendmail is off, some features may require this to be on.'], | ||
$instance->getValidationMessages() | ||
); | ||
} | ||
|
||
public function testCheckWithEnforcesAndInactiveBooleans() | ||
{ | ||
$instance = $this->getMockBuilder(SeLinux::class) | ||
->onlyMethods([ | ||
'doesSelinuxBinariesExists', | ||
'doesSelinuxIsEnabledFunctionExists', | ||
'isSelinuxEnabled', | ||
'doesSelinuxGetenforceFunctionExists', | ||
'getSelinxEnforceStatus', | ||
'doesSelinuxBooleanFunctionExists', | ||
'isSelinuxBooleanActive' | ||
]) | ||
->getMock(); | ||
$instance->method('doesSelinuxBinariesExists')->willReturn(true); | ||
$instance->method('doesSelinuxIsEnabledFunctionExists')->willReturn(true); | ||
$instance->method('isSelinuxEnabled')->willReturn(true); | ||
$instance->method('doesSelinuxGetenforceFunctionExists')->willReturn(true); | ||
$instance->method('getSelinxEnforceStatus')->willReturn(1); | ||
$instance->method('doesSelinuxBooleanFunctionExists')->willReturn(true); | ||
$instance->method('isSelinuxBooleanActive')->willReturn(false); | ||
|
||
$this->assertFalse($instance->isValidated()); | ||
$this->assertEquals( | ||
[ | ||
'SELinux boolean httpd_can_network_connect is off, some features may require this to be on.', | ||
'SELinux boolean httpd_can_network_connect_db is off, some features may require this to be on.', | ||
'SELinux boolean httpd_can_sendmail is off, some features may require this to be on.', | ||
], | ||
$instance->getValidationMessages() | ||
); | ||
} | ||
|
||
public function testCheckWithPermissiveSeLinux() | ||
{ | ||
$instance = $this->getMockBuilder(SeLinux::class) | ||
->onlyMethods([ | ||
'doesSelinuxBinariesExists', | ||
'doesSelinuxIsEnabledFunctionExists', | ||
'isSelinuxEnabled', | ||
'doesSelinuxGetenforceFunctionExists', | ||
'getSelinxEnforceStatus', | ||
'doesSelinuxBooleanFunctionExists', | ||
'isSelinuxBooleanActive' | ||
]) | ||
->getMock(); | ||
$instance->method('doesSelinuxBinariesExists')->willReturn(true); | ||
$instance->method('doesSelinuxIsEnabledFunctionExists')->willReturn(true); | ||
$instance->method('isSelinuxEnabled')->willReturn(true); | ||
$instance->method('doesSelinuxGetenforceFunctionExists')->willReturn(true); | ||
$instance->method('getSelinxEnforceStatus')->willReturn(0); | ||
$instance->method('doesSelinuxBooleanFunctionExists')->willReturn(true); | ||
$instance->method('isSelinuxBooleanActive')->willReturn(true); | ||
|
||
$this->assertFalse($instance->isValidated()); | ||
$this->assertEquals( | ||
['For security reasons, SELinux mode should be Enforcing.'], | ||
$instance->getValidationMessages() | ||
); | ||
} | ||
|
||
public function testCheckWithDisabledSeLinux() | ||
{ | ||
$instance = $this->getMockBuilder(SeLinux::class) | ||
->onlyMethods([ | ||
'doesSelinuxBinariesExists', | ||
'doesSelinuxIsEnabledFunctionExists', | ||
'isSelinuxEnabled', | ||
'doesSelinuxGetenforceFunctionExists', | ||
'getSelinxEnforceStatus', | ||
'doesSelinuxBooleanFunctionExists', | ||
'isSelinuxBooleanActive' | ||
]) | ||
->getMock(); | ||
$instance->method('doesSelinuxBinariesExists')->willReturn(true); | ||
$instance->method('doesSelinuxIsEnabledFunctionExists')->willReturn(true); | ||
$instance->method('isSelinuxEnabled')->willReturn(false); | ||
$instance->method('doesSelinuxGetenforceFunctionExists')->willReturn(true); | ||
$instance->method('getSelinxEnforceStatus')->willReturn(1); | ||
$instance->method('doesSelinuxBooleanFunctionExists')->willReturn(true); | ||
$instance->method('isSelinuxBooleanActive')->willReturn(true); | ||
|
||
$this->assertFalse($instance->isValidated()); | ||
$this->assertEquals( | ||
['For security reasons, SELinux mode should be Enforcing.'], | ||
$instance->getValidationMessages() | ||
); | ||
} | ||
} |
Oops, something went wrong.