2016-12-12 05:41:11 +01:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
class ForbiddenCodeTest extends TestCase
|
2016-12-12 05:41:11 +01:00
|
|
|
{
|
2018-11-06 03:57:36 +01:00
|
|
|
use Traits\InvalidCodeAnalysisTestTrait;
|
|
|
|
use Traits\ValidCodeAnalysisTestTrait;
|
2016-12-12 05:41:11 +01:00
|
|
|
|
|
|
|
/**
|
2019-03-01 21:55:20 +01:00
|
|
|
* @return iterable<string,array{string,error_message:string,2?:string[],3?:bool,4?:string}>
|
2016-12-12 05:41:11 +01:00
|
|
|
*/
|
2020-09-12 17:24:05 +02:00
|
|
|
public function providerInvalidCodeParse(): iterable
|
2016-12-12 05:41:11 +01:00
|
|
|
{
|
2017-04-25 05:45:02 +02:00
|
|
|
return [
|
|
|
|
'varDump' => [
|
|
|
|
'<?php
|
|
|
|
var_dump("hello");',
|
2017-05-27 02:05:57 +02:00
|
|
|
'error_message' => 'ForbiddenCode',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
2019-04-13 17:20:02 +02:00
|
|
|
'varDumpCased' => [
|
|
|
|
'<?php
|
|
|
|
vAr_dUMp("hello");',
|
|
|
|
'error_message' => 'ForbiddenCode',
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
'execTicks' => [
|
|
|
|
'<?php
|
|
|
|
`rm -rf`;',
|
2017-05-27 02:05:57 +02:00
|
|
|
'error_message' => 'ForbiddenCode',
|
2017-04-25 05:45:02 +02:00
|
|
|
],
|
|
|
|
'exec' => [
|
|
|
|
'<?php
|
|
|
|
shell_exec("rm -rf");',
|
2017-05-27 02:05:57 +02:00
|
|
|
'error_message' => 'ForbiddenCode',
|
|
|
|
],
|
2019-04-13 17:20:02 +02:00
|
|
|
'execCased' => [
|
|
|
|
'<?php
|
|
|
|
sHeLl_EXeC("rm -rf");',
|
|
|
|
'error_message' => 'ForbiddenCode',
|
|
|
|
],
|
2017-04-25 05:45:02 +02:00
|
|
|
];
|
2016-12-12 05:41:11 +01:00
|
|
|
}
|
2018-03-13 04:48:10 +01:00
|
|
|
|
|
|
|
/**
|
2019-03-01 21:55:20 +01:00
|
|
|
* @return iterable<string,array{string,assertions?:array<string,string>,error_levels?:string[]}>
|
2018-03-13 04:48:10 +01:00
|
|
|
*/
|
2020-09-12 17:24:05 +02:00
|
|
|
public function providerValidCodeParse(): iterable
|
2018-03-13 04:48:10 +01:00
|
|
|
{
|
|
|
|
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-12 05:41:11 +01:00
|
|
|
}
|