mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 02:58:43 +02:00
N°6889 backup mysqldump call : restore possibility to connect using socket protocol (#591)
With previous fix (N°6123) we forced to use the tcp protocol each time. This was blocking for users wanting to connect using the socket protocol on localhost. Now for localhost we will : - send both port and protocol arguments if the `db_host` config parameter does contain a port - don't send any of the port or protocol arguments if `db_host` doesn't contain a port
This commit is contained in:
@@ -135,4 +135,37 @@ class CMDBSourceTest extends ItopTestCase
|
||||
$bIsTlsCnx = $this->InvokeNonPublicStaticMethod(CMDBSource::class, 'IsOpenedDbConnectionUsingTls',[$oMysqli]);
|
||||
$this->assertFalse($bIsTlsCnx);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider InitServerAndPortProvider
|
||||
* @since 2.7.10 3.0.4 3.1.2 3.2.0 N°6889 method creation to keep track of the behavior change (port will return null)
|
||||
*/
|
||||
public function testInitServerAndPort(string $sDbHost, string $sExpectedServer, ?int $iExpectedPort)
|
||||
{
|
||||
$sActualServer = null;
|
||||
$iActualPort = null;
|
||||
CMDBSource::InitServerAndPort($sDbHost, $sActualServer, $iActualPort);
|
||||
|
||||
$this->assertNotNull($sActualServer);
|
||||
$this->assertEquals($sExpectedServer, $sActualServer);
|
||||
$this->assertEquals($iExpectedPort, $iActualPort);
|
||||
}
|
||||
|
||||
public function InitServerAndPortProvider()
|
||||
{
|
||||
return [
|
||||
'localhost no port' => ['localhost', 'localhost', null],
|
||||
'localhost with port' => ['localhost:333306', 'localhost', 333306],
|
||||
'persistent localhost no port' => ['p:localhost', 'p:localhost', null],
|
||||
'persistent localhost with port' => ['p:localhost:333306', 'p:localhost', 333306],
|
||||
'ip no port' => ['192.168.1.10', '192.168.1.10', null],
|
||||
'ip with port' => ['192.168.1.10:333306', '192.168.1.10', 333306],
|
||||
'persistent ip no port' => ['p:192.168.1.10', 'p:192.168.1.10', null],
|
||||
'persistent ip with port' => ['p:192.168.1.10:333306', 'p:192.168.1.10', 333306],
|
||||
'domain no port' => ['dbserver.mycompany.com', 'dbserver.mycompany.com', null],
|
||||
'domain with port' => ['dbserver.mycompany.com:333306', 'dbserver.mycompany.com', 333306],
|
||||
'persistent domain no port' => ['p:dbserver.mycompany.com', 'p:dbserver.mycompany.com', null],
|
||||
'persistent domain with port' => ['p:dbserver.mycompany.com:333306', 'p:dbserver.mycompany.com', 333306],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,29 +86,44 @@ class DBBackupTest extends ItopTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Host is localhost, we should be forced into tcp
|
||||
*
|
||||
* @return void
|
||||
* @dataProvider GetMysqlCliPortAndTransportOptionsProvider
|
||||
* @since 2.7.10 3.0.4 3.1.2 3.2.0 test for N°6123 and N°6889
|
||||
*/
|
||||
public function testGetMysqlCliTransportOptionWithLocalhost()
|
||||
public function testGetMysqlCliPortAndTransportOptions(string $sDbHost, ?int $iPort, ?int $iExpectedPortValue, string $sExpectedProtocolCliOption)
|
||||
{
|
||||
$sHost= 'localhost';
|
||||
$sTransport = DBBackup::GetMysqlCliTransportOption($sHost);
|
||||
if (is_null($iExpectedPortValue)) {
|
||||
$sExpectedPortCliOption = '';
|
||||
} else {
|
||||
$sEscapedPortValue = \DBBackup::EscapeShellArg($iExpectedPortValue);
|
||||
$sExpectedPortCliOption = ' --port=' . $sEscapedPortValue;
|
||||
}
|
||||
|
||||
$this->assertStringStartsWith('--protocol=tcp', $sTransport);
|
||||
$this->assertStringEndsWith('--protocol=tcp', $sTransport);
|
||||
$sActualCliOptions = $this->InvokeNonPublicStaticMethod(DBBackup::class, 'GetMysqlCliPortAndTransportOptions', [$sDbHost, $iPort]);
|
||||
$this->assertEquals($sExpectedPortCliOption . $sExpectedProtocolCliOption, $sActualCliOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Host is not localhost, we shouldn't be forced into tcp
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetMysqlCliTransportOptionWithoutLocalhost()
|
||||
public function GetMysqlCliPortAndTransportOptionsProvider()
|
||||
{
|
||||
$sHost= '127.0.0.1';
|
||||
$sTransport = DBBackup::GetMysqlCliTransportOption($sHost);
|
||||
$iTestPort = 333306;
|
||||
$iDefaultPort = 3306; // cannot access \CMDBSource::MYSQL_DEFAULT_PORT in dataprovider :(
|
||||
|
||||
$this->assertEmpty($sTransport);
|
||||
return [
|
||||
'Localhost no port' => ['localhost', null, null, ''],
|
||||
'Localhost with port' => ['localhost', $iTestPort, $iTestPort, ' --protocol=tcp'],
|
||||
|
||||
// we want both port and protocol for 127.0.0.1, because it is an ip address so using tcp/ip stack !
|
||||
'127.0.0.1 no port' => ['127.0.0.1', null, $iDefaultPort, ''],
|
||||
'127.0.0.1 with port' => ['127.0.0.1', $iTestPort, $iTestPort, ''],
|
||||
|
||||
'IP no port' => ['192.168.1.15', null, $iDefaultPort, ''],
|
||||
'IP with port' => ['192.168.1.15', $iTestPort, $iTestPort, ''],
|
||||
|
||||
'DNS no port' => ['dbserver.mycompany.com', null, $iDefaultPort, ''],
|
||||
'DNS with port' => ['dbserver.mycompany.com', $iTestPort, $iTestPort, ''],
|
||||
|
||||
'Windows name no port' => ['dbserver', null, $iDefaultPort, ''],
|
||||
'Windows name with port' => ['dbserver', $iTestPort, $iTestPort, ''],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user