mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-03 18:04:26 +02:00
2 small fixes for unit tests
This commit is contained in:
@@ -31,14 +31,8 @@ class FunctionTest extends PHPUnit_Smarty
|
|||||||
public function testUnknownFunction()
|
public function testUnknownFunction()
|
||||||
{
|
{
|
||||||
$this->smarty->enableSecurity();
|
$this->smarty->enableSecurity();
|
||||||
try {
|
$this->expectException(\Smarty\CompilerException::class);
|
||||||
$this->smarty->fetch('eval:{unknown()}');
|
$this->expectExceptionMessage('Cannot compile unknown function unknown');
|
||||||
}
|
$this->smarty->fetch('eval:{unknown()}');
|
||||||
catch (Exception $e) {
|
|
||||||
$this->assertStringContainsString("PHP function 'unknown' not allowed by security setting", $e->getMessage());
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$this->fail('Exception for unknown function has not been raised.');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -62,9 +62,10 @@ class SecurityTest extends PHPUnit_Smarty
|
|||||||
*/
|
*/
|
||||||
public function testNotTrustedModifier()
|
public function testNotTrustedModifier()
|
||||||
{
|
{
|
||||||
|
$this->smarty->security_policy->disabled_modifiers[] = 'escape';
|
||||||
$this->expectException(\Smarty\Exception::class);
|
$this->expectException(\Smarty\Exception::class);
|
||||||
$this->expectExceptionMessage('modifier \'sizeof\' not allowed by security setting');
|
$this->expectExceptionMessage('modifier \'escape\' disabled by security setting');
|
||||||
@$this->smarty->fetch('string:{assign var=foo value=[1,2,3,4,5]}{$foo|@sizeof}');
|
@$this->smarty->fetch('string:{assign var=foo value=[1,2,3,4,5]}{$foo|escape}');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -215,40 +216,40 @@ class SecurityTest extends PHPUnit_Smarty
|
|||||||
$this->assertEquals('25', $this->smarty->fetch($tpl));
|
$this->assertEquals('25', $this->smarty->fetch($tpl));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test not trusted PHP function
|
* test not trusted PHP function
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function testNotTrustedStaticClass()
|
public function testNotTrustedStaticClass()
|
||||||
{
|
{
|
||||||
$this->expectException(\Smarty\Exception::class);
|
$this->expectException(\Smarty\Exception::class);
|
||||||
$this->expectExceptionMessage('access to static class \'mysecuritystaticclass\' not allowed by security setting');
|
$this->expectExceptionMessage('access to static class \'mysecuritystaticclass\' not allowed by security setting');
|
||||||
$this->smarty->security_policy->static_classes = array('null');
|
$this->smarty->security_policy->static_classes = array('null');
|
||||||
$this->smarty->fetch('string:{mysecuritystaticclass::square(5)}');
|
$this->smarty->fetch('string:{mysecuritystaticclass::square(5)}');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test not trusted PHP function
|
* test not trusted PHP function
|
||||||
*/
|
*/
|
||||||
public function testNotTrustedStaticClassEval()
|
public function testNotTrustedStaticClassEval()
|
||||||
{
|
{
|
||||||
$this->expectException(\Smarty\Exception::class);
|
$this->expectException(\Smarty\Exception::class);
|
||||||
$this->expectExceptionMessage('dynamic static class not allowed by security setting');
|
$this->expectExceptionMessage('dynamic static class not allowed by security setting');
|
||||||
$this->smarty->security_policy->static_classes = array('null');
|
$this->smarty->security_policy->static_classes = array('null');
|
||||||
$this->smarty->fetch('string:{$test = "mysecuritystaticclass"}{$test::square(5)}');
|
$this->smarty->fetch('string:{$test = "mysecuritystaticclass"}{$test::square(5)}');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test not trusted PHP function
|
* test not trusted PHP function
|
||||||
*/
|
*/
|
||||||
public function testNotTrustedStaticClassSmartyVar()
|
public function testNotTrustedStaticClassSmartyVar()
|
||||||
{
|
{
|
||||||
$this->expectException(\Smarty\Exception::class);
|
$this->expectException(\Smarty\Exception::class);
|
||||||
$this->expectExceptionMessage('dynamic static class not allowed by security setting');
|
$this->expectExceptionMessage('dynamic static class not allowed by security setting');
|
||||||
$this->smarty->security_policy->static_classes = array('null');
|
$this->smarty->security_policy->static_classes = array('null');
|
||||||
$this->smarty->fetch('string:{$smarty.template_object::square(5)}');
|
$this->smarty->fetch('string:{$smarty.template_object::square(5)}');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testChangedTrustedDirectory()
|
public function testChangedTrustedDirectory()
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user