mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-25 11:38:44 +02:00
✅ Fix DBBackupTest
DB connection dependency was added ina222ead4(N°2336) in \DBBackup::GetMysqlCliTlsOptions but test wasn't updated accordingly :/^ The test wasn't ran on Jenkins untilb11bf308, so we saw the regression only yesterday :( This is now fixed ! 🥳
This commit is contained in:
@@ -447,6 +447,12 @@ class CMDBSource
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws \MySQLException
|
||||
*
|
||||
* @uses \CMDBSource::QueryToCol() so needs a connection opened !
|
||||
*/
|
||||
public static function GetDBVersion()
|
||||
{
|
||||
$aVersions = self::QueryToCol('SELECT Version() as version', 'version');
|
||||
@@ -464,8 +470,10 @@ class CMDBSource
|
||||
/**
|
||||
* Get the DB vendor between MySQL and its main forks
|
||||
* @return string
|
||||
*
|
||||
* @uses \CMDBSource::GetServerVariable() so needs a connection opened !
|
||||
*/
|
||||
static public function GetDBVendor()
|
||||
public static function GetDBVendor()
|
||||
{
|
||||
$sDBVendor = static::ENUM_DB_VENDOR_MYSQL;
|
||||
|
||||
|
||||
@@ -466,6 +466,9 @@ EOF;
|
||||
*
|
||||
* @return string TLS arguments for CLI programs such as mysqldump. Empty string if the config does not use TLS.
|
||||
*
|
||||
* @uses \CMDBSource::GetDBVendor() so needs a connection opened !
|
||||
* @uses \CMDBSource::GetDBVersion() so needs a connection opened !
|
||||
*
|
||||
* @since 2.5.0 N°1260
|
||||
* @link https://dev.mysql.com/doc/refman/5.6/en/connection-options.html#encrypted-connection-options "Command Options for Encrypted Connections"
|
||||
*/
|
||||
|
||||
@@ -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
|
||||
@@ -21,21 +22,35 @@ class DBBackupTest extends ItopTestCase
|
||||
require_once(APPROOT.'core/cmdbsource.class.inc.php'); // DBBackup dependency
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \CoreException
|
||||
* @throws \ConfigException
|
||||
* @throws \MySQLException
|
||||
*/
|
||||
public function testGetMysqlCliTlsOptions()
|
||||
{
|
||||
$oConfig = new Config();
|
||||
$oConfig->Set('db_tls.enabled', false);
|
||||
$oConfigToTest = utils::GetConfig();
|
||||
|
||||
$sCliArgsNoTls = DBBackup::GetMysqlCliTlsOptions($oConfig);
|
||||
// No TLS connection = no additional CLI args !
|
||||
$oConfigToTest->Set('db_tls.enabled', false);
|
||||
$sCliArgsNoTls = DBBackup::GetMysqlCliTlsOptions($oConfigToTest);
|
||||
$this->assertEmpty($sCliArgsNoTls);
|
||||
|
||||
$oConfig->Set('db_tls.enabled', true);
|
||||
$sCliArgsMinCfg = DBBackup::GetMysqlCliTlsOptions($oConfig);
|
||||
$this->assertEquals(' --ssl', $sCliArgsMinCfg);
|
||||
// We need a connection to the DB, so let's open it !
|
||||
$oConfigOnDisk = utils::GetConfig();
|
||||
CMDBSource::InitFromConfig($oConfigOnDisk);
|
||||
|
||||
// TLS connection configured = we need one CLI arg
|
||||
$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
|
||||
$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.ca', $sTestCa);
|
||||
$sCliArgsCapathCfg = DBBackup::GetMysqlCliTlsOptions($oConfigToTest);
|
||||
$this->assertStringStartsWith(' --ssl', $sCliArgsMinCfg);
|
||||
$this->assertStringEndsWith('--ssl-ca="'.$sTestCa.'"', $sCliArgsCapathCfg);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user