Merge remote-tracking branch 'origin/support/2.7' into support/3.0

# Conflicts:
#	core/cmdbsource.class.inc.php
#	core/log.class.inc.php
#	test/setup/iTopDesignFormat/iTopDesignFormatTest.php
This commit is contained in:
Pierre Goiffon
2022-01-12 09:56:16 +01:00
6 changed files with 87 additions and 19 deletions

View File

@@ -2,9 +2,10 @@
namespace Combodo\iTop\Test\UnitTest\Core;
use CMDBSource;
use Combodo\iTop\Test\UnitTest\ItopTestCase;
use Config;
use DBBackup;
use utils;
/**
* @runTestsInSeparateProcesses
@@ -13,29 +14,76 @@ use DBBackup;
*/
class DBBackupTest extends ItopTestCase
{
/**
* @throws \CoreException
* @throws \MySQLException
* @throws \ConfigException
*/
protected function setUp()
{
parent::setUp();
require_once(APPROOT.'core/config.class.inc.php');
require_once(APPROOT.'setup/backup.class.inc.php');
require_once(APPROOT.'core/cmdbsource.class.inc.php'); // DBBackup dependency
// We need a connection to the DB, so let's open it !
// We are using the default config file... as the server might not be configured for all the combination we are testing
// For example dev env and ci env won't accept TLS connection
$oConfigOnDisk = utils::GetConfig();
CMDBSource::InitFromConfig($oConfigOnDisk);
}
public function testGetMysqlCliTlsOptions()
/**
* No TLS connection = no additional CLI args !
*
* @throws \CoreException
* @throws \ConfigException
* @throws \MySQLException
*/
public function testGetMysqlCliTlsOptionsNoTls()
{
$oConfig = new Config();
$oConfig->Set('db_tls.enabled', false);
$oConfigToTest = utils::GetConfig();
$oConfigToTest->Set('db_tls.enabled', false);
$sCliArgsNoTls = DBBackup::GetMysqlCliTlsOptions($oConfigToTest);
$sCliArgsNoTls = DBBackup::GetMysqlCliTlsOptions($oConfig);
$this->assertEmpty($sCliArgsNoTls);
}
$oConfig->Set('db_tls.enabled', true);
$sCliArgsMinCfg = DBBackup::GetMysqlCliTlsOptions($oConfig);
$this->assertEquals(' --ssl', $sCliArgsMinCfg);
/**
* TLS connection configured = we need one CLI arg
*
* @return void
* @throws \ConfigException
* @throws \CoreException
*/
public function testGetMysqlCliTlsOptionsWithTlsNoCa()
{
$oConfigToTest = utils::GetConfig();
$oConfigToTest->Set('db_tls.enabled', true);
$sCliArgsMinCfg = DBBackup::GetMysqlCliTlsOptions($oConfigToTest);
// depending on the MySQL version, we would have `--ssl` or `--ssl-mode=VERIFY_CA`
$this->assertStringStartsWith(' --ssl', $sCliArgsMinCfg);
}
/**
* TLS connection configured + CA option = we need multiple CLI args
*
* @return void
* @throws \ConfigException
* @throws \CoreException
*/
public function testGetMysqlCliTlsOptionsWithTlsAndCa()
{
$oConfigToTest = utils::GetConfig();
$sTestCa = 'my_test_ca';
$oConfig->Set('db_tls.ca', $sTestCa);
$sCliArgsCapathCfg = DBBackup::GetMysqlCliTlsOptions($oConfig);
$this->assertEquals(' --ssl --ssl-ca="'.$sTestCa.'"', $sCliArgsCapathCfg);
$oConfigToTest->Set('db_tls.enabled', true);
$oConfigToTest->Set('db_tls.ca', $sTestCa);
$sCliArgsCapathCfg = DBBackup::GetMysqlCliTlsOptions($oConfigToTest);
$this->assertStringStartsWith(' --ssl', $sCliArgsCapathCfg);
$this->assertStringEndsWith('--ssl-ca='.DBBackup::EscapeShellArg($sTestCa), $sCliArgsCapathCfg);
}
}