2016-12-11 23:41:11 -05:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
2017-04-24 23:45:02 -04:00
|
|
|
class ForbiddenCodeTest extends TestCase
|
2016-12-11 23:41:11 -05:00
|
|
|
{
|
2017-04-24 23:45:02 -04:00
|
|
|
use Traits\FileCheckerInvalidCodeParseTestTrait;
|
2018-03-12 23:48:10 -04:00
|
|
|
use Traits\FileCheckerValidCodeParseTestTrait;
|
2016-12-11 23:41:11 -05:00
|
|
|
|
|
|
|
/**
|
2017-04-24 23:45:02 -04:00
|
|
|
* @return array
|
2016-12-11 23:41:11 -05:00
|
|
|
*/
|
2017-04-24 23:45:02 -04:00
|
|
|
public function providerFileCheckerInvalidCodeParse()
|
2016-12-11 23:41:11 -05:00
|
|
|
{
|
2017-04-24 23:45:02 -04:00
|
|
|
return [
|
|
|
|
'varDump' => [
|
|
|
|
'<?php
|
|
|
|
var_dump("hello");',
|
2017-05-26 20:05:57 -04:00
|
|
|
'error_message' => 'ForbiddenCode',
|
2017-04-24 23:45:02 -04:00
|
|
|
],
|
|
|
|
'execTicks' => [
|
|
|
|
'<?php
|
|
|
|
`rm -rf`;',
|
2017-05-26 20:05:57 -04:00
|
|
|
'error_message' => 'ForbiddenCode',
|
2017-04-24 23:45:02 -04:00
|
|
|
],
|
|
|
|
'exec' => [
|
|
|
|
'<?php
|
|
|
|
shell_exec("rm -rf");',
|
2017-05-26 20:05:57 -04:00
|
|
|
'error_message' => 'ForbiddenCode',
|
|
|
|
],
|
2017-04-24 23:45:02 -04:00
|
|
|
];
|
2016-12-11 23:41:11 -05:00
|
|
|
}
|
2018-03-12 23:48:10 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function providerFileCheckerValidCodeParse()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'execWithSuppression' => [
|
|
|
|
'<?php
|
|
|
|
@exec("pwd 2>&1", $output, $returnValue);
|
|
|
|
if ($returnValue === 0) {
|
|
|
|
echo "success";
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
'execWithoutSuppression' => [
|
|
|
|
'<?php
|
|
|
|
exec("pwd 2>&1", $output, $returnValue);
|
|
|
|
if ($returnValue === 0) {
|
|
|
|
echo "success";
|
|
|
|
}',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
2016-12-11 23:41:11 -05:00
|
|
|
}
|