Issues (9)

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.

features/bootstrap/FeatureContext.php (2 issues)

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
use Behat\Behat\Context\SnippetAcceptingContext;
4
use Behat\Gherkin\Node\PyStringNode;
5
use Symfony\Component\Process\PhpExecutableFinder;
6
use Symfony\Component\Process\Process;
7
8
/**
9
 * Behat context class.
10
 */
11
class FeatureContext implements SnippetAcceptingContext
12
{
13
    /**
14
     * @var string
15
     */
16
    private $phpBin;
17
    /**
18
     * @var Process
19
     */
20
    private $process;
21
    /**
22
     * @var string
23
     */
24
    private $workingDir;
25
26
    /**
27
     * Cleans test folders in the temporary directory.
28
     *
29
     * @BeforeSuite
30
     * @AfterSuite
31
     */
32
    public static function cleanTestFolders()
33
    {
34
        if (is_dir($dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'behat-web-api')) {
35
            self::clearDirectory($dir);
36
        }
37
    }
38
39
    /**
40
     * Prepares test folders in the temporary directory.
41
     *
42
     * @BeforeScenario
43
     */
44
    public function prepareScenario()
45
    {
46
        $dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'behat-web-api' . DIRECTORY_SEPARATOR .
47
            md5(microtime() * rand(0, 10000));
48
49
        mkdir($dir . '/features/bootstrap', 0777, true);
50
51
        $phpFinder = new PhpExecutableFinder();
52
        if (false === $php = $phpFinder->find()) {
53
            throw new \RuntimeException('Unable to find the PHP executable.');
54
        }
55
        $this->workingDir = $dir;
56
        $this->phpBin = $php;
57
        $this->process = new Process(null);
58
    }
59
60
    /**
61
     * Creates a file with specified name and context in current working dir.
62
     *
63
     * @Given /^(?:there is )?a file named "([^"]*)" with:$/
64
     *
65
     * @param string       $filename name of the file (relative path)
66
     * @param PyStringNode $content  PyString string instance
67
     */
68
    public function aFileNamedWith($filename, PyStringNode $content)
69
    {
70
        $content = strtr((string) $content, array("'''" => '"""'));
71
        $this->createFile($this->workingDir . '/' . $filename, $content);
72
    }
73
74
    /**
75
     * Runs behat command with provided parameters
76
     *
77
     * @When /^I run "behat(?: ((?:\"|[^"])*))?"$/
78
     *
79
     * @param string $argumentsString
80
     */
81
    public function iRunBehat($argumentsString = '')
82
    {
83
        $argumentsString = strtr($argumentsString, array('\'' => '"'));
84
85
        $this->process->setWorkingDirectory($this->workingDir);
86
        $this->process->setCommandLine(
87
            sprintf(
88
                '%s %s %s %s',
89
                $this->phpBin,
90
                escapeshellarg(BEHAT_BIN_PATH),
91
                $argumentsString,
92
                strtr('--format-settings=\'{"timer": false}\' --no-colors', array('\'' => '"', '"' => '\"'))
93
            )
94
        );
95
        $this->process->start();
96
        $this->process->wait();
97
    }
98
99
    /**
100
     * Checks whether previously runned command passes|failes with provided output.
101
     *
102
     * @Then /^it should (fail|pass) with:$/
103
     *
104
     * @param string       $success "fail" or "pass"
105
     * @param PyStringNode $text    PyString text instance
106
     */
107
    public function itShouldPassWith($success, PyStringNode $text)
108
    {
109
        $this->itShouldFail($success);
110
        $this->theOutputShouldContain($text);
111
    }
112
113
    /**
114
     * Checks whether last command output contains provided string.
115
     *
116
     * @Then the output should contain:
117
     *
118
     * @param PyStringNode $text PyString text instance
119
     */
120
    public function theOutputShouldContain(PyStringNode $text)
121
    {
122
        PHPUnit_Framework_Assert::assertContains($this->getExpectedOutput($text), $this->getOutput());
123
    }
124
125
    private function getExpectedOutput(PyStringNode $expectedText)
126
    {
127
        $text = strtr($expectedText, array('\'\'\'' => '"""'));
128
129
        // windows path fix
130
        if ('/' !== DIRECTORY_SEPARATOR) {
131
            $text = preg_replace_callback(
132
                '/ features\/[^\n ]+/', function ($matches) {
133
                    return str_replace('/', DIRECTORY_SEPARATOR, $matches[0]);
134
                }, $text
135
            );
136
            $text = preg_replace_callback(
137
                '/\<span class\="path"\>features\/[^\<]+/', function ($matches) {
138
                    return str_replace('/', DIRECTORY_SEPARATOR, $matches[0]);
139
                }, $text
140
            );
141
            $text = preg_replace_callback(
142
                '/\+[fd] [^ ]+/', function ($matches) {
143
                    return str_replace('/', DIRECTORY_SEPARATOR, $matches[0]);
144
                }, $text
145
            );
146
        }
147
148
        return $text;
149
    }
150
151
    /**
152
     * Checks whether previously run command failed|passed.
153
     *
154
     * @Then /^it should (fail|pass)$/
155
     *
156
     * @param string $success "fail" or "pass"
157
     */
158
    public function itShouldFail($success)
159
    {
160
        if ('fail' === $success) {
161 View Code Duplication
            if (0 === $this->getExitCode()) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
162
                echo 'Actual output:' . PHP_EOL . PHP_EOL . $this->getOutput();
163
            }
164
165
            PHPUnit_Framework_Assert::assertNotEquals(0, $this->getExitCode());
166
        } else {
167 View Code Duplication
            if (0 !== $this->getExitCode()) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
168
                echo 'Actual output:' . PHP_EOL . PHP_EOL . $this->getOutput();
169
            }
170
171
            PHPUnit_Framework_Assert::assertEquals(0, $this->getExitCode());
172
        }
173
    }
174
175
    private function getExitCode()
176
    {
177
        return $this->process->getExitCode();
178
    }
179
180
    private function getOutput()
181
    {
182
        $output = $this->process->getErrorOutput() . $this->process->getOutput();
183
184
        // Normalize the line endings in the output
185
        if ("\n" !== PHP_EOL) {
186
            $output = str_replace(PHP_EOL, "\n", $output);
187
        }
188
189
        return trim(preg_replace("/ +$/m", '', $output));
190
    }
191
192
    private function createFile($filename, $content)
193
    {
194
        $path = dirname($filename);
195
        if (!is_dir($path)) {
196
            mkdir($path, 0777, true);
197
        }
198
199
        file_put_contents($filename, $content);
200
    }
201
202
    private static function clearDirectory($path)
203
    {
204
        $files = scandir($path);
205
        array_shift($files);
206
        array_shift($files);
207
208
        foreach ($files as $file) {
209
            $file = $path . DIRECTORY_SEPARATOR . $file;
210
            if (is_dir($file)) {
211
                self::clearDirectory($file);
212
            } else {
213
                unlink($file);
214
            }
215
        }
216
217
        rmdir($path);
218
    }
219
}
220