Issues (27)

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.

tests/Unit/DsnTest.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
/*
4
 * This file is part of php-cache organization.
5
 *
6
 * (c) 2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Cache\AdapterBundle\Tests\Unit;
13
14
use Cache\AdapterBundle\DSN;
15
use PHPUnit\Framework\TestCase;
16
17
/**
18
 * DsnTest.
19
 */
20
class DsnTest extends TestCase
21
{
22
    /**
23
     * @static
24
     *
25
     * @return array
26
     */
27
    public static function hostValues()
28
    {
29
        return [
30
            ['redis://localhost', 'localhost'],
31
            ['redis://localhost/1', 'localhost'],
32
            ['redis://localhost:63790', 'localhost'],
33
            ['redis://localhost:63790/10', 'localhost'],
34
            ['redis://pw@localhost:63790/10', 'localhost'],
35
            ['redis://127.0.0.1', '127.0.0.1'],
36
            ['redis://127.0.0.1/1', '127.0.0.1'],
37
            ['redis://127.0.0.1:63790', '127.0.0.1'],
38
            ['redis://127.0.0.1:63790/10', '127.0.0.1'],
39
            ['redis://[email protected]:63790/10', '127.0.0.1'],
40
            ['mongodb://localhost', 'localhost'],
41
            ['mongodb://127.0.0.1', '127.0.0.1'],
42
            ['mongodb://dev:[email protected]', '127.0.0.1'],
43
            ['mongodb://dev:[email protected]:27371', '127.0.0.1'],
44
            ['mongodb://dev:[email protected]:27371/database', '127.0.0.1'],
45
            ['mongodb://dev:[email protected],192.168.1.1:27371/database', ['127.0.0.1', '192.168.1.1']],
46
        ];
47
    }
48
49
    /**
50
     * @param string $dsn  DSN
51
     * @param string $host Host
52
     *
53
     * @dataProvider hostValues
54
     */
55 View Code Duplication
    public function testHost($dsn, $host)
0 ignored issues
show
This method seems to be duplicated in 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...
56
    {
57
        $dsn = new DSN($dsn);
58
        if (is_array($host)) {
59
            foreach ($dsn->getHosts() as $index => $h) {
60
                $this->assertEquals($host[$index], $h['host']);
61
            }
62
        } else {
63
            $this->assertEquals($host, $dsn->getFirstHost());
64
        }
65
    }
66
67
    /**
68
     * @static
69
     *
70
     * @return array
71
     */
72
    public static function portValues()
73
    {
74
        return [
75
            ['redis://localhost', 6379],
76
            ['tcp://localhost', 6379],
77
            ['redis://localhost/1', 6379],
78
            ['redis://localhost:63790', 63790],
79
            ['redis://localhost:63790/10', 63790],
80
            ['redis://pw@localhost:63790/10', 63790],
81
            ['redis://127.0.0.1', 6379],
82
            ['redis://127.0.0.1/1', 6379],
83
            ['redis://127.0.0.1:63790', 63790],
84
            ['redis://127.0.0.1:63790/10', 63790],
85
            ['redis://[email protected]:63790/10', 63790],
86
            ['mongodb://localhost', 27017],
87
            ['mongodb://127.0.0.1', 27017],
88
            ['mongodb://dev:[email protected]', 27017],
89
            ['mongodb://dev:[email protected]:27371', 27371],
90
            ['mongodb://dev:[email protected]:27371/database', 27371],
91
            ['mongodb://dev:[email protected],192.168.1.1:27371/database', [27017, 27371]],
92
        ];
93
    }
94
95
    /**
96
     * @param string $dsn  DSN
97
     * @param int    $port Port
98
     *
99
     * @dataProvider portValues
100
     */
101 View Code Duplication
    public function testPort($dsn, $port)
0 ignored issues
show
This method seems to be duplicated in 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...
102
    {
103
        $dsn = new DSN($dsn);
104
        if (is_array($port)) {
105
            foreach ($dsn->getHosts() as $index => $host) {
106
                $this->assertEquals($port[$index], $host['port']);
107
            }
108
        } else {
109
            $this->assertEquals($port, $dsn->getFirstPort());
110
        }
111
    }
112
113
    /**
114
     * @static
115
     *
116
     * @return array
117
     */
118
    public static function databaseValues()
119
    {
120
        return [
121
            ['redis://localhost', null],
122
            ['redis://localhost/0', 0],
123
            ['redis://localhost/1', 1],
124
            ['redis://localhost:63790', null],
125
            ['redis://localhost:63790/10', 10],
126
            ['redis://pw@localhost:63790/10', 10],
127
            ['redis://127.0.0.1', null],
128
            ['redis://127.0.0.1/0', 0],
129
            ['redis://127.0.0.1/1', 1],
130
            ['redis://127.0.0.1:63790', null],
131
            ['redis://127.0.0.1:63790/10', 10],
132
            ['redis://[email protected]:63790/10', 10],
133
            ['mongodb://localhost', null],
134
            ['mongodb://127.0.0.1', null],
135
            ['mongodb://dev:[email protected]', null],
136
            ['mongodb://dev:[email protected]:27371', null],
137
            ['mongodb://dev:[email protected]:27371/database', 'database'],
138
            ['mongodb://dev:[email protected],192.168.1.1:27371/database', 'database'],
139
        ];
140
    }
141
142
    /**
143
     * @param string $dsn      DSN
144
     * @param int    $database Database
145
     *
146
     * @dataProvider databaseValues
147
     */
148
    public function testDatabase($dsn, $database)
149
    {
150
        $dsn = new DSN($dsn);
151
        $this->assertEquals($database, $dsn->getDatabase());
152
    }
153
154
    /**
155
     * @static
156
     *
157
     * @return array
158
     */
159
    public static function passwordValues()
160
    {
161
        return [
162
            ['redis://localhost', null],
163
            ['redis://localhost/1', null],
164
            ['redis://user:pass@localhost:63790/10', ['user', 'pass']],
165
            ['redis://pw@localhost:63790/10', 'pw'],
166
            ['redis://p\@w@localhost:63790/10', 'p@w'],
167
            ['redis://mB(.z9},6o?zl>v!LM76A]lCg77,;.@localhost:63790/10', 'mB(.z9},6o?zl>v!LM76A]lCg77,;.'],
168
            ['redis://127.0.0.1', null],
169
            ['redis://127.0.0.1/1', null],
170
            ['redis://[email protected]:63790/10', 'pw'],
171
            ['redis://p\@[email protected]:63790/10', 'p@w'],
172
            ['redis://mB(.z9},6o?zl>v!LM76A]lCg77,;[email protected]:63790/10', 'mB(.z9},6o?zl>v!LM76A]lCg77,;.'],
173
            ['mongodb://localhost', null],
174
            ['mongodb://127.0.0.1', null],
175
            ['mongodb://dev:[email protected]', ['dev', 'pass']],
176
            ['mongodb://dev:[email protected]:27371', ['dev', 'pass']],
177
            ['mongodb://dev:[email protected]:27371/database', ['dev', 'pass']],
178
            ['mongodb://dev:[email protected],192.168.1.1:27371/database', ['dev', 'pass']],
179
        ];
180
    }
181
182
    /**
183
     * @param string $dsn      DSN
184
     * @param string $password Password
185
     *
186
     * @dataProvider passwordValues
187
     */
188
    public function testPassword($dsn, $password)
189
    {
190
        $dsn = new DSN($dsn);
191
192
        if (is_array($password)) {
193
            $this->assertEquals($password[0], $dsn->getUsername());
194
            $this->assertEquals($password[1], $dsn->getPassword());
195
        } else {
196
            $this->assertEquals($password, $dsn->getPassword());
197
        }
198
    }
199
200
    /**
201
     * @static
202
     *
203
     * @return array
204
     */
205
    public static function isValidValues()
206
    {
207
        return [
208
            ['redis://localhost', true],
209
            ['redis://localhost/1', true],
210
            ['redis://pw@localhost:63790/10', true],
211
            ['redis://127.0.0.1', true],
212
            ['redis://127.0.0.1/1', true],
213
            ['redis://[email protected]:63790/10', true],
214
            ['mongodb://localhost', true],
215
            ['mongodb://127.0.0.1', true],
216
            ['mongodb://dev:[email protected]', true],
217
            ['mongodb://dev:[email protected]:27371', true],
218
            ['mongodb://dev:[email protected]:27371/database', true],
219
            ['mongodb://dev:[email protected],192.168.1.1:27371/database', true],
220
            ['mongo://localhost', false],
221
            ['localhost', false],
222
            ['localhost/1', false],
223
            ['pw@localhost:63790/10', false],
224
        ];
225
    }
226
227
    /**
228
     * @param string $dsn   DSN
229
     * @param bool   $valid Valid
230
     *
231
     * @dataProvider isValidValues
232
     */
233
    public function testIsValid($dsn, $valid)
234
    {
235
        $dsn = new DSN($dsn);
236
        $this->assertEquals($valid, $dsn->isValid(), 'Failed validating: '.$dsn->getDsn());
237
    }
238
239
    /**
240
     * @static
241
     *
242
     * @return array
243
     */
244
    public static function parameterValues()
245
    {
246
        return [
247
            ['redis://localhost', []],
248
            ['redis://localhost/1?weight=1&alias=master', ['weight' => 1, 'alias' => 'master']],
249
            ['redis://pw@localhost:63790/10?alias=master&weight=2', ['weight' => 2, 'alias' => 'master']],
250
            ['redis://127.0.0.1?weight=3', ['weight' => 3]],
251
            ['redis://127.0.0.1/1?alias=master&weight=4', ['weight' => 4, 'alias' => 'master']],
252
            ['redis://[email protected]:63790/10?weight=5&alias=master', ['weight' => 5, 'alias' => 'master']],
253
            ['redis://localhost?alias=master', ['alias' => 'master']],
254
            ['mongodb://dev:[email protected],192.168.1.1:27371/database?replicaSet=test', ['replicaSet' => 'test']],
255
            ['mongodb://dev:[email protected],192.168.1.1:27371/database?test', ['test' => null]],
256
        ];
257
    }
258
259
    /**
260
     * @param string $dsn
261
     * @param array  $parameters
262
     *
263
     * @dataProvider parameterValues
264
     */
265
    public function testParameterValues($dsn, $parameters)
266
    {
267
        $dsn = new DSN($dsn);
268
        foreach ($parameters as $key => $value) {
269
            $this->assertEquals($value, $dsn->getParameters()[$key]);
270
        }
271
    }
272
}
273