IcingaCommand: fix windows absolute path detection
Also add a couple of new related tests fixes #11550
This commit is contained in:
parent
3b1145284b
commit
4222261434
|
@ -87,7 +87,7 @@ class IcingaCommand extends IcingaObject
|
||||||
if (preg_match('~^([A-Z][A-Za-z0-9_]+\s\+\s)(.+?)$~', $command, $m)) {
|
if (preg_match('~^([A-Z][A-Za-z0-9_]+\s\+\s)(.+?)$~', $command, $m)) {
|
||||||
$prefix = $m[1];
|
$prefix = $m[1];
|
||||||
$command = $m[2];
|
$command = $m[2];
|
||||||
} elseif ($command[0] !== '/') {
|
} elseif (! $this->isAbsolutePath($command)) {
|
||||||
$prefix = 'PluginDir + ';
|
$prefix = 'PluginDir + ';
|
||||||
$command = '/' . $command;
|
$command = '/' . $command;
|
||||||
}
|
}
|
||||||
|
@ -97,6 +97,13 @@ class IcingaCommand extends IcingaObject
|
||||||
return c::renderKeyValue('command', c::renderArray($parts));
|
return c::renderKeyValue('command', c::renderArray($parts));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function isAbsolutePath($path)
|
||||||
|
{
|
||||||
|
return $path[0] === '/'
|
||||||
|
|| $path[0] === '\\'
|
||||||
|
|| preg_match('/^[A-Z]:\\\/', substr($path, 0, 3));
|
||||||
|
}
|
||||||
|
|
||||||
public static function setPluginDir($pluginDir)
|
public static function setPluginDir($pluginDir)
|
||||||
{
|
{
|
||||||
self::$pluginDir = $pluginDir;
|
self::$pluginDir = $pluginDir;
|
||||||
|
|
|
@ -58,6 +58,52 @@ class IcingaCommandTest extends BaseTestCase
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAbsolutePathsAreDetected()
|
||||||
|
{
|
||||||
|
$command = $this->command();
|
||||||
|
$command->command = 'C:\\test.exe';
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
$this->loadRendered('command1'),
|
||||||
|
(string) $command
|
||||||
|
);
|
||||||
|
|
||||||
|
$command->command = '/tmp/bla';
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
$this->loadRendered('command2'),
|
||||||
|
(string) $command
|
||||||
|
);
|
||||||
|
|
||||||
|
$command->command = 'tmp/bla';
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
$this->loadRendered('command3'),
|
||||||
|
(string) $command
|
||||||
|
);
|
||||||
|
|
||||||
|
$command->command = '\\\\network\\share\\bla.exe';
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
$this->loadRendered('command4'),
|
||||||
|
(string) $command
|
||||||
|
);
|
||||||
|
|
||||||
|
$command->command = 'BlahDir + \\network\\share\\bla.exe';
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
$this->loadRendered('command5'),
|
||||||
|
(string) $command
|
||||||
|
);
|
||||||
|
|
||||||
|
$command->command = 'network\\share\\bla.exe';
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
$this->loadRendered('command6'),
|
||||||
|
(string) $command
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
protected function command()
|
protected function command()
|
||||||
{
|
{
|
||||||
return IcingaCommand::create(
|
return IcingaCommand::create(
|
||||||
|
@ -68,6 +114,11 @@ class IcingaCommandTest extends BaseTestCase
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function loadRendered($name)
|
||||||
|
{
|
||||||
|
return file_get_contents(__DIR__ . '/rendered/' . $name . '.out');
|
||||||
|
}
|
||||||
|
|
||||||
public function tearDown()
|
public function tearDown()
|
||||||
{
|
{
|
||||||
$db = $this->getDb();
|
$db = $this->getDb();
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
object CheckCommand "___TEST___command" {
|
||||||
|
command = [ "C:\\test.exe" ]
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
object CheckCommand "___TEST___command" {
|
||||||
|
command = [ "/tmp/bla" ]
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
object CheckCommand "___TEST___command" {
|
||||||
|
command = [ PluginDir + "/tmp/bla" ]
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
object CheckCommand "___TEST___command" {
|
||||||
|
command = [ "\\\\network\\share\\bla.exe" ]
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
object CheckCommand "___TEST___command" {
|
||||||
|
command = [ BlahDir + "\\network\\share\\bla.exe" ]
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
object CheckCommand "___TEST___command" {
|
||||||
|
command = [ PluginDir + "/network\\share\\bla.exe" ]
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue