N°2538 enforce generic method to check path validity

Now uses realpath() and StartsWith
This commit is contained in:
Pierre Goiffon
2019-10-16 10:43:01 +02:00
parent 29c30c1f89
commit 607d355c61
4 changed files with 58 additions and 12 deletions

View File

@@ -50,4 +50,39 @@ class UtilsTest extends \Combodo\iTop\Test\UnitTest\ItopTestCase
[false, 1024, 2048],
];
}
/**
* @dataProvider realPathDataProvider
*/
public function testRealPath($sPath, $sBasePath, $expected)
{
$this->assertSame($expected, utils::RealPath($sPath, $sBasePath));
}
public function realPathDataProvider()
{
parent::setUp(); // if not called, APPROOT won't be defined :(
$sItopRootPath = APPROOT;
$sSep = DIRECTORY_SEPARATOR;
return [
'licence.txt' => [$sItopRootPath.'license.txt', $sItopRootPath, $sItopRootPath.'license.txt'],
'unexisting file' => [$sItopRootPath.'license_DOES_NOT_EXIST.txt', $sItopRootPath, false],
'/license.txt' => [$sItopRootPath.$sSep.'license.txt', $sItopRootPath, $sItopRootPath.'license.txt'],
'%2flicense.txt' => [$sItopRootPath.'%2flicense.txt', $sItopRootPath, false],
'../license.txt' => [$sItopRootPath.'..'.$sSep.'license.txt', $sItopRootPath, false],
'%2e%2e%2flicense.txt' => [$sItopRootPath.'%2e%2e%2flicense.txt', $sItopRootPath, false],
'application/utils.inc.php with basepath=APPROOT' => [
$sItopRootPath.'application/utils.inc.php',
$sItopRootPath,
$sItopRootPath.'application'.$sSep.'utils.inc.php',
],
'application/utils.inc.php with basepath=APPROOT/application' => [
$sItopRootPath.'application/utils.inc.php',
$sItopRootPath.'application',
$sItopRootPath.'application'.$sSep.'utils.inc.php',
],
];
}
}