Compare commits

...

2 Commits

Author SHA1 Message Date
odain
a14bc3a31a N°7810 - renable test in ci 2024-12-19 16:43:08 +01:00
Eric Espie
927a77b905 N°7810 - code hardening 2024-12-19 15:12:26 +01:00
4 changed files with 42 additions and 48 deletions

View File

@@ -41,7 +41,9 @@
<testsuite name="Setup">
<directory>unitary-tests/setup</directory>
</testsuite>
<!-- Note: The unitary-tests/sources/application/TwigBase is omitted for now as the test is not working -->
<testsuite name="SourcesApplicationTwigBase">
<directory>unitary-tests/sources/application/TwigBase</directory>
</testsuite>
<testsuite name="SourcesApplicationSearch">
<directory>unitary-tests/sources/application/search</directory>
</testsuite>

View File

@@ -1,58 +1,44 @@
<?php
namespace Combodo\iTop\Test\UnitTest;
namespace Combodo\iTop\Test\UnitTest\Application\TwigBase;
use Combodo\iTop\Portal\Twig\AppExtension;
use Twig_Environment;
use Twig_Loader_Array;
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
/**
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
* @backupGlobals disabled
*/
class TwigTest extends ItopDataTestCase
{
protected function setUp(): void
{
parent::setUp();
$this->RequireOnceItopFile('core/config.class.inc.php');
}
protected function setUp(): void
{
parent::setUp();
$this->RequireOnceItopFile('core/config.class.inc.php');
}
/**
* Test the fix for ticket N°4384
*
* @dataProvider TemplateProvider
*
*/
public function testTemplate($sFileName, $sExpected)
{
$sId = 'TestTwig';
$oAppExtension = new AppExtension();
/**
* @covers N°4384 N°7810
*
*/
public function testTemplate()
{
// Creating sandbox twig env. to load and test the custom form template
$oTwig = new Environment(new FilesystemLoader(__DIR__.'/'));
// Creating sandbox twig env. to load and test the custom form template
$oTwig = new Twig_Environment(new Twig_Loader_Array([$sId => $sFileName]));
// Manually registering filters and functions as we didn't find how to do it automatically
$oAppExtension = new AppExtension();
$aFilters = $oAppExtension->getFilters();
foreach ($aFilters as $oFilter)
{
$oTwig->addFilter($oFilter);
}
$aFunctions = $oAppExtension->getFunctions();
foreach ($aFunctions as $oFunction)
{
$oTwig->addFunction($oFunction);
}
// Manually registering filters and functions as we didn't find how to do it automatically
$aFilters = $oAppExtension->getFilters();
foreach ($aFilters as $oFilter)
{
$oTwig->addFilter($oFilter);
}
$aFunctions = $oAppExtension->getFunctions();
foreach ($aFunctions as $oFunction)
{
$oTwig->addFunction($oFunction);
}
}
$sOutput = $oTwig->render('test.html.twig');
public static function testTemplateProvider()
{
$aReturn = array();
$aReturn['filter_system'] = [
'sFileName' => 'test.html',
'expected' =>file_get_contents(dirname(__FILE__).'/test.html'),
];
return $aReturn;
}
$this->assertEquals(file_get_contents(__DIR__.'/test.html'), $sOutput);
}
}

View File

@@ -42,5 +42,8 @@ Smith, Dupond
<div>['echo',1]|sort('system')|join</div>
echo1
<div>[['id','']|sort('system')</div>
id
POST /subscribe?0=cat+/etc/passwd HTTP/1.1
email=""@attacker.tld

View File

@@ -47,5 +47,8 @@
<div>['echo',1]|sort('system')|join</div>
{{ ['echo',1]|sort('system')|join }}
<div>[['id','']|sort('system')</div>
{{['id','']|sort('system')|join}}
POST /subscribe?0=cat+/etc/passwd HTTP/1.1
email="{{ app.request.query.filter(0,0,1024,{'options':'system'}) }}"@attacker.tld