Adding tests for securing private variable inclussion on templates.
[akelos.git] / test / unit / lib / AkActionView / AkPhpCodeSanitizer.php
blobbaec8ae98be911264c5331c60987433214ea510b
1 <?php
3 require_once(dirname(__FILE__).'/../../../fixtures/config/config.php');
4 require_once(AK_LIB_DIR.DS.'AkActionView'.DS.'AkPhpCodeSanitizer.php');
6 class AkPhpCodeSanitizer_TestCase extends AkUnitTest
9 function test_should_avoid_private_variables()
11 $this->assertInvalidCode('<?php $_private; ?>');
12 $this->assertInvalidCode('<?=$_private?>');
15 function test_should_avoid_private_array_keys()
17 $this->assertInvalidCode('<?php echo $var[\'_private\']; ?>');
18 $this->assertInvalidCode('<?php $var["_private"]?>');
19 $this->assertInvalidCode('<?php $var[public][_private]?>');
20 $this->assertInvalidCode('<?php $var[{\'_private\'}]?>');
23 function test_should_avoid_private_object_attributes()
25 $this->assertInvalidCode('<?php echo $var->_private; ?>');
26 $this->assertInvalidCode('<?php $var->_private?>');
27 $this->assertInvalidCode('<?php $var->public->_private]?>');
28 $this->assertInvalidCode('<?php $var->{\'_private\'}?>');
29 $this->assertInvalidCode('<?php $var->$variable_attr?>');
33 /**/
34 function assertValidCode($code)
36 $this->CodeSanitizer =& new AkPhpCodeSanitizer();
37 $this->CodeSanitizer->setOptions(array('code'=>$code));
38 $this->assertTrue($this->CodeSanitizer->isCodeSecure(), 'Secure code not accepted: '.$code);
41 function assertInvalidCode($code)
43 $this->CodeSanitizer =& new AkPhpCodeSanitizer();
44 $this->CodeSanitizer->setOptions(array('code'=>$code));
45 $this->assertFalse($this->CodeSanitizer->isCodeSecure(), 'Unsecure code not detected: '.$code);
46 $this->assertErrorPattern('/You can\'t use/');