Issues (76)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Runners/PHPUnit/TestFileLoader.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
declare(strict_types=1);
4
5
namespace ParaTest\Runners\PHPUnit;
6
7
class TestFileLoader
8
{
9
    /**
10
     * The pattern used for grabbing test files. Uses the *Test.php convention
11
     * that PHPUnit defaults to.
12
     */
13
    const TEST_PATTERN = '/.+Test\.php$/';
14
15
    /**
16
     * Matches php files.
17
     */
18
    const FILE_PATTERN = '/.+\.php$/';
19
20
    /**
21
     * Used to ignore directory paths '.' and '..'.
22
     *
23
     * @var string
24
     */
25
    private static $dotPattern = '/([.]+)$/';
26
27
    /**
28
     * The collection of loaded files for this test suite.
29
     *
30
     * @var array
31
     */
32
    protected $files = [];
33
34
    /**
35
     * The collection of excluded files.
36
     *
37
     * @var array
38
     */
39
    protected $excludedFiles = [];
40
41
    /**
42
     * When true, the SuiteLoader add the files to excluded files.
43
     *
44
     * @var bool
45
     */
46
    protected $excludingFiles = false;
47
48 24
    public function __construct(Options $options = null)
49
    {
50 24
        $this->options = $options;
0 ignored issues
show
The property options does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
51 24
    }
52
53
    /**
54
     * Loads a SuitePath and makes sure to
55
     * take into account the excluded directory / files.
56
     *
57
     * @param SuitePath $path
58
     *
59
     * @return string[]
60
     */
61 12
    public function loadSuitePath(SuitePath $path): array
62
    {
63
        // First initialize the list of files and excluded files
64 12
        $this->files = [];
65 12
        $this->excludedFiles = [];
66 12
        $this->excludingFiles = true;
67 12
        foreach ($path->getExcludedPaths() as $excludedPath) {
68 2
            $this->loadPath($excludedPath, $path->getPattern());
69
        }
70
71
        // Load the SuitePath
72 12
        $this->excludingFiles = false;
73 12
        $this->loadPath($path->getPath(), $path->getPattern());
74
75
        // Reinitialise the excluded files
76 12
        $this->excludedFiles = [];
77
78 12
        return $this->files;
79
    }
80
81
    /**
82
     * Loads suites based on a specific path.
83
     * A valid path can be a directory or file.
84
     *
85
     * @param $path
86
     * @param $pattern
87
     *
88
     * @throws \InvalidArgumentException
89
     *
90
     * @return string[]
91
     */
92 22
    public function loadPath(string $path, string $pattern = null): array
93
    {
94 22
        $this->files = [];
95 22
        $path = $path ?: $this->options->path;
96 22
        $pattern = null === $pattern ? self::TEST_PATTERN : $pattern;
97
98 22
        if (!file_exists($path)) {
99 2
            throw new \InvalidArgumentException("$path is not a valid directory or file");
100
        }
101 20
        if (is_dir($path)) {
102 13
            $this->loadDir($path, $pattern);
103 11
        } elseif (file_exists($path)) {
104 11
            $this->loadFile($path);
105
        }
106
107 20
        return $this->files;
108
    }
109
110
    /**
111
     * Loads suites from a directory.
112
     *
113
     * @param string $path
114
     * @param string $pattern
115
     */
116 13
    private function loadDir(string $path, string $pattern = self::TEST_PATTERN)
117
    {
118 13
        $files = scandir($path);
119 13
        foreach ($files as $file) {
120 13
            $this->tryLoadTests($path . DIRECTORY_SEPARATOR . $file, $pattern);
121
        }
122 13
    }
123
124
    /**
125
     * Load a single suite file.
126
     *
127
     * @param $path
128
     */
129 11
    private function loadFile(string $path)
130
    {
131 11
        $this->tryLoadTests($path, self::FILE_PATTERN);
132 11
    }
133
134
    /**
135
     * Attempts to load suites from a path.
136
     *
137
     * @param string $path
138
     * @param string $pattern regular expression for matching file names
139
     */
140 20
    private function tryLoadTests(string $path, string $pattern = self::TEST_PATTERN)
141
    {
142 20
        if (preg_match($pattern, $path)) {
143 20
            if ($this->excludingFiles) {
144 2
                $this->excludedFiles[$path] = $path;
145 20
            } elseif (!array_key_exists($path, $this->excludedFiles)) {
146 20
                $this->files[] = $path;
147
            }
148
        }
149
150 20
        if (!preg_match(self::$dotPattern, $path) && is_dir($path)) {
151 8
            $this->loadDir($path, $pattern);
152
        }
153 20
    }
154
}
155