Issues (1490)

Security Analysis    not enabled

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/Tools/Plugin/Codeception.php (1 issue)

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
namespace Fabrica\Tools\Plugin;
4
5
use Fabrica\Tools\Builder;
6
use Fabrica\Models\Infra\Ci\Build;
7
use Fabrica\Tools\Plugin\Util\TestResultParsers\Codeception as Parser;
8
use Fabrica\Tools\Plugin;
9
use Symfony\Component\Yaml\Parser as YamlParser;
10
use Fabrica\Tools\ZeroConfigPluginInterface;
11
12
/**
13
 * Codeception Plugin - Enables full acceptance, unit, and functional testing.
14
 *
15
 * @author Don Gilbert <[email protected]>
16
 * @author Igor Timoshenko <[email protected]>
17
 * @author Adam Cooper <[email protected]>
18
 */
19
class Codeception extends Plugin implements ZeroConfigPluginInterface
20
{
21
    /**
22
     * @var string
23
     */
24
    protected $args = '';
25
26
    /**
27
     * @var string $ymlConfigFile The path of a yml config for Codeception
28
     */
29
    protected $ymlConfigFile;
30
31
    /**
32
     * default sub-path for report.xml file
33
     *
34
     * @var array $path The path to the report.xml file
35
     */
36
    protected $outputPath = [
37
        'tests/_output',
38
        'tests/_log',
39
    ];
40
41
    /**
42
     * @return string
43
     */
44
    public static function pluginName()
45
    {
46
        return 'codeception';
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function __construct(Builder $builder, Build $build, array $options = [])
53
    {
54
        parent::__construct($builder, $build, $options);
55
56
        if (empty($options['config'])) {
57
            $this->ymlConfigFile = self::findConfigFile($this->directory);
58
        } else {
59
            $this->ymlConfigFile = $this->directory . $options['config'];
60
        }
61
62
        if (isset($options['args'])) {
63
            $this->args = (string) $options['args'];
64
        }
65
66
        /**
67
 * @deprecated Option "path" is deprecated and will be deleted in version 2.0. Use the option "output_path" instead. 
68
*/
69
        if (isset($options['path']) && !isset($options['output_path'])) {
70
            $this->builder->logWarning(
71
                '[DEPRECATED] Option "path" is deprecated and will be deleted in version 2.0. Use the option "output_path" instead.'
72
            );
73
74
            $options['output_path'] = $options['path'];
75
        }
76
77
        if (isset($options['output_path'])) {
78
            array_unshift($this->outputPath, $options['output_path']);
79
        }
80
81
        if (isset($options['executable'])) {
82
            $this->executable = $options['executable'];
83
        } else {
84
            $this->executable = $this->findBinary('codecept');
85
        }
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91
    public static function canExecuteOnStage($stage, Build $build)
92
    {
93
        return (Build::STAGE_TEST === $stage && !is_null(self::findConfigFile($build->getBuildPath())));
94
    }
95
96
    /**
97
     * Try and find the codeception YML config file.
98
     *
99
     * @param  $buildPath
100
     * @return null|string
101
     */
102
    public static function findConfigFile($buildPath)
103
    {
104
        if (file_exists($buildPath . 'codeception.yml')) {
105
            return $buildPath . 'codeception.yml';
106
        }
107
108
        if (file_exists($buildPath . 'codeception.dist.yml')) {
109
            return $buildPath . 'codeception.dist.yml';
110
        }
111
112
        return null;
113
    }
114
115
    /**
116
     * Runs Codeception tests
117
     */
118
    public function execute()
119
    {
120
        if (empty($this->ymlConfigFile)) {
121
            throw new \Exception("No configuration file found");
122
        }
123
124
        // Run any config files first. This can be either a single value or an array.
125
        return $this->runConfigFile();
126
    }
127
128
    /**
129
     * Run tests from a Codeception config file.
130
     *
131
     * @return bool|mixed
132
     * @throws \Exception
133
     */
134
    protected function runConfigFile()
135
    {
136
        $codeception = $this->executable;
137
138
        if (!$codeception) {
139
            $this->builder->logFailure(sprintf('Could not find "%s" binary', 'codecept'));
140
141
            return false;
142
        }
143
144
        $cmd = 'cd "%s" && ' . $codeception . ' run -c "%s" ' . $this->args . ' --xml';
145
146
        $success = $this->builder->executeCommand($cmd, $this->directory, $this->ymlConfigFile);
147
        if (!$success) {
148
            return false;
149
        }
150
151
        $parser = new YamlParser();
152
        $yaml   = file_get_contents($this->ymlConfigFile);
153
        $config = (array)$parser->parse($yaml);
154
155
        $trueReportXmlPath = null;
156
        if ($config && isset($config['paths']['log'])) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $config of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
157
            $trueReportXmlPath = rtrim($config['paths']['log'], '/\\') . '/';
158
        }
159
160
        if (!file_exists($trueReportXmlPath . 'report.xml')) {
161
            foreach ($this->outputPath as $outputPath) {
162
                $trueReportXmlPath = rtrim($outputPath, '/\\') . '/';
163
                if (file_exists($trueReportXmlPath . 'report.xml')) {
164
                    break;
165
                }
166
            }
167
        }
168
169
        if (!file_exists($trueReportXmlPath . 'report.xml')) {
170
            $this->builder->logFailure('"report.xml" file can not be found in configured "output_path!"');
171
172
            return false;
173
        }
174
175
        $parser = new Parser($this->builder, ($trueReportXmlPath . 'report.xml'));
176
        $output = $parser->parse();
177
178
        $meta = [
179
            'tests'     => $parser->getTotalTests(),
180
            'timetaken' => $parser->getTotalTimeTaken(),
181
            'failures'  => $parser->getTotalFailures(),
182
        ];
183
184
        // NOTE: Codeception does not use stderr, so failure can only be detected
185
        // through tests
186
        $success = $success && (intval($meta['failures']) < 1);
187
188
        $this->build->storeMeta((self::pluginName() . '-meta'), $meta);
189
        $this->build->storeMeta((self::pluginName() . '-data'), $output);
190
        $this->build->storeMeta((self::pluginName() . '-errors'), $parser->getTotalFailures());
191
192
        return $success;
193
    }
194
}
195