mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
feature(presets): Add security preset
Looks for functions often seen as insecure
This commit is contained in:
29
src/ArchPresets/Security.php
Normal file
29
src/ArchPresets/Security.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Pest\ArchPresets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class Security extends AbstractPreset
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Executes the arch preset.
|
||||||
|
*/
|
||||||
|
public function execute(): void
|
||||||
|
{
|
||||||
|
$this->expectations[] = expect([
|
||||||
|
'md5',
|
||||||
|
'sha1',
|
||||||
|
'uniqid',
|
||||||
|
'rand',
|
||||||
|
'mt_rand',
|
||||||
|
'tempnam',
|
||||||
|
'str_shuffle',
|
||||||
|
'shuffle',
|
||||||
|
'array_rand'
|
||||||
|
])->not->toBeUsed();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -8,6 +8,7 @@ use Pest\Arch\Support\Composer;
|
|||||||
use Pest\ArchPresets\AbstractPreset;
|
use Pest\ArchPresets\AbstractPreset;
|
||||||
use Pest\ArchPresets\Base;
|
use Pest\ArchPresets\Base;
|
||||||
use Pest\ArchPresets\Strict;
|
use Pest\ArchPresets\Strict;
|
||||||
|
use Pest\ArchPresets\Security;
|
||||||
use Pest\PendingCalls\TestCall;
|
use Pest\PendingCalls\TestCall;
|
||||||
use stdClass;
|
use stdClass;
|
||||||
|
|
||||||
@ -47,6 +48,14 @@ final class Preset
|
|||||||
return $this->executePreset(new Strict($this->baseNamespaces()));
|
return $this->executePreset(new Strict($this->baseNamespaces()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses the Pest security preset and returns the test call instance.
|
||||||
|
*/
|
||||||
|
public function security(): AbstractPreset
|
||||||
|
{
|
||||||
|
return $this->executePreset(new Security($this->baseNamespaces()));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the given preset.
|
* Executes the given preset.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -9,6 +9,8 @@ arch()->preset()->base()->ignoring([
|
|||||||
|
|
||||||
arch()->preset()->strict();
|
arch()->preset()->strict();
|
||||||
|
|
||||||
|
arch()->preset()->security();
|
||||||
|
|
||||||
arch('globals')
|
arch('globals')
|
||||||
->expect(['dd', 'dump', 'ray', 'die', 'var_dump', 'sleep'])
|
->expect(['dd', 'dump', 'ray', 'die', 'var_dump', 'sleep'])
|
||||||
->not->toBeUsed()
|
->not->toBeUsed()
|
||||||
|
|||||||
Reference in New Issue
Block a user