Issues (13)

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/TestCaseTrait.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 declare(strict_types=1);
2
3
namespace Limoncello\Testing;
4
5
/**
6
 * Copyright 2015-2020 [email protected]
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 * http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
21
use Closure;
22
use Limoncello\Contracts\Core\ApplicationInterface;
23
use Psr\Http\Message\ResponseInterface;
24
use Psr\Http\Message\StreamInterface;
25
26
/**
27
 * @package Limoncello\Testing
28
 */
29
trait TestCaseTrait
30
{
31
    /**
32
     * @var array
33
     */
34
    private $eventHandlers = [];
35
36
    /**
37
     * @param array|null                      $server
38
     * @param array|null                      $queryParams
39
     * @param array|object|null               $parsedBody
0 ignored issues
show
Consider making the type for parameter $parsedBody a bit more specific; maybe use null|array.
Loading history...
40
     * @param array|null                      $cookies
41
     * @param array|null                      $files
42
     * @param string|resource|StreamInterface $messageBody
43
     * @param string                          $protocolVersion
44
     *
45
     * @return Sapi
46
     */
47
    abstract protected function createSapi(
48
        array $server = null,
49
        array $queryParams = null,
50
        array $parsedBody = null,
51
        array $cookies = null,
52
        array $files = null,
53
        $messageBody = 'php://input',
54
        string $protocolVersion = '1.1'
55
    ): Sapi;
56
57
    /**
58
     * @return ApplicationInterface
59
     */
60
    abstract protected function createApplication(): ApplicationInterface;
61
62
    /** @noinspection PhpTooManyParametersInspection
63
     * @param string                          $method
64
     * @param string                          $uri
65
     * @param array                           $queryParams
66
     * @param array                           $parsedBody
67
     * @param array                           $headers
68
     * @param array                           $cookies
69
     * @param array                           $files
70
     * @param array                           $server
71
     * @param string|resource|StreamInterface $content
72
     * @param string                          $host
73
     * @param string                          $protocolVersion
74
     *
75
     * @return ResponseInterface
76
     *
77
     * @SuppressWarnings(PHPMD.ExcessiveParameterList)
78
     */
79 9
    protected function call(
80
        string $method,
81
        string $uri,
82
        array $queryParams = [],
83
        array $parsedBody = [],
84
        array $headers = [],
85
        array $cookies = [],
86
        array $files = [],
87
        array $server = [],
88
        $content = 'php://input',
89
        string $host = 'localhost',
90
        string $protocolVersion = '1.1'
91
    ): ResponseInterface {
92 9
        $headers['host'] = $host;
93
94 9
        $prefix = 'HTTP_';
95 9
        foreach ($headers as $name => $value) {
96 9
            $name = strtr(strtoupper($name), '-', '_');
97 9
            if ($name !== 'CONTENT_TYPE' && strpos($name, $prefix) !== 0) {
98 9
                $name = $prefix . $name;
99
            }
100 9
            $server[$name] = $value;
101
        }
102
103 9
        $server['REQUEST_URI']    = $uri;
104 9
        $server['REQUEST_METHOD'] = $method;
105
106 9
        $app  = $this->createApplication();
107 9
        $sapi = $this->createSapi($server, $queryParams, $parsedBody, $cookies, $files, $content, $protocolVersion);
108 9
        $app->setSapi($sapi)->run();
109 9
        unset($app);
110
111 9
        $response = $sapi->getResponse();
112 9
        unset($sapi);
113
114 9
        return $response;
115
    }
116
117
    /**
118
     * @return void
119
     */
120 1
    protected function resetEventHandlers(): void
121
    {
122 1
        $this->eventHandlers = [];
123
    }
124
125
    /**
126
     * @param Closure $handler
127
     *
128
     * @return void
129
     */
130 1
    protected function addOnHandleRequestEvent(Closure $handler): void
131
    {
132 1
        $this->eventHandlers[ApplicationWrapperInterface::EVENT_ON_HANDLE_REQUEST][] = $handler;
133
    }
134
135
    /**
136
     * @param Closure $handler
137
     *
138
     * @return void
139
     */
140 1
    protected function addOnHandleResponseEvent(Closure $handler): void
141
    {
142 1
        $this->eventHandlers[ApplicationWrapperInterface::EVENT_ON_HANDLE_RESPONSE][] = $handler;
143
    }
144
145
    /**
146
     * @param Closure $handler
147
     *
148
     * @return void
149
     */
150 1
    protected function addOnContainerCreatedEvent(Closure $handler): void
151
    {
152 1
        $this->eventHandlers[ApplicationWrapperInterface::EVENT_ON_CONTAINER_CREATED][] = $handler;
153
    }
154
155
    /**
156
     * @param Closure $handler
157
     *
158
     * @return void
159
     */
160 1
    protected function addOnContainerConfiguredEvent(Closure $handler): void
161
    {
162 1
        $this->eventHandlers[ApplicationWrapperInterface::EVENT_ON_CONTAINER_LAST_CONFIGURATOR][] = $handler;
163
    }
164
165
    /**
166
     * @return array
167
     */
168 1
    protected function getHandleRequestEvents(): array
169
    {
170 1
        return $this->eventHandlers[ApplicationWrapperInterface::EVENT_ON_HANDLE_REQUEST] ?? [];
171
    }
172
173
    /**
174
     * @return array
175
     */
176 1
    protected function getHandleResponseEvents(): array
177
    {
178 1
        return $this->eventHandlers[ApplicationWrapperInterface::EVENT_ON_HANDLE_RESPONSE] ?? [];
179
    }
180
181
    /**
182
     * @return array
183
     */
184 1
    protected function getContainerCreatedEvents(): array
185
    {
186 1
        return $this->eventHandlers[ApplicationWrapperInterface::EVENT_ON_CONTAINER_CREATED] ?? [];
187
    }
188
189
    /**
190
     * @return array
191
     */
192 1
    protected function getContainerConfiguredEvents(): array
193
    {
194 1
        return $this->eventHandlers[ApplicationWrapperInterface::EVENT_ON_CONTAINER_LAST_CONFIGURATOR] ?? [];
195
    }
196
}
197