Issues (171)

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.

Unit/DependencyInjection/ConfigurationTest.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
declare(strict_types=1);
4
5
namespace Http\HttplugBundle\Tests\Unit\DependencyInjection;
6
7
use Http\Adapter\Guzzle7\Client;
8
use Http\HttplugBundle\DependencyInjection\Configuration;
9
use Http\HttplugBundle\DependencyInjection\HttplugExtension;
10
use Http\Message\MessageFactory\GuzzleMessageFactory;
11
use Http\Message\StreamFactory\GuzzleStreamFactory;
12
use Http\Message\UriFactory\GuzzleUriFactory;
13
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionConfigurationTestCase;
14
use Nyholm\Psr7\Factory\Psr17Factory;
15
use Symfony\Component\Config\Definition\ConfigurationInterface;
16
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
17
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
18
19
/**
20
 * @author David Buchmann <[email protected]>
21
 */
22
class ConfigurationTest extends AbstractExtensionConfigurationTestCase
23
{
24
    private $emptyConfig = [
25
        'default_client_autowiring' => true,
26
        'main_alias' => [
27
            'client' => 'httplug.client.default',
28
            'message_factory' => 'httplug.message_factory.default',
29
            'uri_factory' => 'httplug.uri_factory.default',
30
            'stream_factory' => 'httplug.stream_factory.default',
31
            'psr18_client' => 'httplug.psr18_client.default',
32
            'psr17_request_factory' => 'httplug.psr17_request_factory.default',
33
            'psr17_response_factory' => 'httplug.psr17_response_factory.default',
34
            'psr17_stream_factory' => 'httplug.psr17_stream_factory.default',
35
            'psr17_uri_factory' => 'httplug.psr17_uri_factory.default',
36
            'psr17_uploaded_file_factory' => 'httplug.psr17_uploaded_file_factory.default',
37
            'psr17_server_request_factory' => 'httplug.psr17_server_request_factory.default',
38
        ],
39
        'classes' => [
40
            'client' => null,
41
            'psr18_client' => null,
42
            'message_factory' => null,
43
            'uri_factory' => null,
44
            'stream_factory' => null,
45
            'psr17_request_factory' => null,
46
            'psr17_response_factory' => null,
47
            'psr17_stream_factory' => null,
48
            'psr17_uri_factory' => null,
49
            'psr17_uploaded_file_factory' => null,
50
            'psr17_server_request_factory' => null,
51
        ],
52
        'clients' => [],
53
        'profiling' => [
54
            'enabled' => true,
55
            'formatter' => null,
56
            'captured_body_length' => 0,
57
        ],
58
        'plugins' => [
59
            'authentication' => [],
60
            'cache' => [
61
                'enabled' => false,
62
                'stream_factory' => 'httplug.stream_factory',
63
                'config' => [
64
                    'methods' => ['GET', 'HEAD'],
65
                    'blacklisted_paths' => [],
66
                    'cache_listeners' => [],
67
                ],
68
            ],
69
            'cookie' => [
70
                'enabled' => false,
71
            ],
72
            'decoder' => [
73
                'enabled' => true,
74
                'use_content_encoding' => true,
75
            ],
76
            'history' => [
77
                'enabled' => false,
78
            ],
79
            'logger' => [
80
                'enabled' => true,
81
                'logger' => 'logger',
82
                'formatter' => null,
83
            ],
84
            'redirect' => [
85
                'enabled' => true,
86
                'preserve_header' => true,
87
                'use_default_for_multiple' => true,
88
            ],
89
            'retry' => [
90
                'enabled' => true,
91
                'retry' => 1,
92
            ],
93
            'stopwatch' => [
94
                'enabled' => true,
95
                'stopwatch' => 'debug.stopwatch',
96
            ],
97
        ],
98
        'discovery' => [
99
            'client' => 'auto',
100
            'async_client' => null,
101
        ],
102
    ];
103
104
    protected function getContainerExtension(): ExtensionInterface
105
    {
106
        return new HttplugExtension();
107
    }
108
109
    protected function getConfiguration(): ConfigurationInterface
110
    {
111
        return new Configuration(true);
112
    }
113
114 View Code Duplication
    public function testEmptyConfiguration(): void
115
    {
116
        $formats = array_map(function ($path) {
117
            return __DIR__.'/../../Resources/Fixtures/'.$path;
118
        }, [
119
            'config/empty.yml',
120
            'config/empty.xml',
121
            'config/empty.php',
122
        ]);
123
124
        foreach ($formats as $format) {
125
            $this->assertProcessedConfigurationEquals($this->emptyConfig, [$format]);
126
        }
127
    }
128
129
    public function testSupportsAllConfigFormats(): void
130
    {
131
        if (!class_exists(Client::class)) {
132
            $this->markTestSkipped('Guzzle 7 adapter is not installed');
133
        }
134
135
        $expectedConfiguration = [
136
            'default_client_autowiring' => false,
137
            'main_alias' => [
138
                'client' => 'my_client',
139
                'message_factory' => 'my_message_factory',
140
                'uri_factory' => 'my_uri_factory',
141
                'stream_factory' => 'my_stream_factory',
142
                'psr18_client' => 'httplug.psr18_client.default',
143
                'psr17_request_factory' => 'httplug.psr17_request_factory.default',
144
                'psr17_response_factory' => 'httplug.psr17_response_factory.default',
145
                'psr17_stream_factory' => 'httplug.psr17_stream_factory.default',
146
                'psr17_uri_factory' => 'httplug.psr17_uri_factory.default',
147
                'psr17_uploaded_file_factory' => 'httplug.psr17_uploaded_file_factory.default',
148
                'psr17_server_request_factory' => 'httplug.psr17_server_request_factory.default',
149
            ],
150
            'classes' => [
151
                'client' => Client::class,
152
                'message_factory' => GuzzleMessageFactory::class,
153
                'uri_factory' => GuzzleUriFactory::class,
154
                'stream_factory' => GuzzleStreamFactory::class,
155
                'psr18_client' => Client::class,
156
                'psr17_request_factory' => Psr17Factory::class,
157
                'psr17_response_factory' => Psr17Factory::class,
158
                'psr17_stream_factory' => Psr17Factory::class,
159
                'psr17_uri_factory' => Psr17Factory::class,
160
                'psr17_uploaded_file_factory' => Psr17Factory::class,
161
                'psr17_server_request_factory' => Psr17Factory::class,
162
            ],
163
            'clients' => [
164
                'test' => [
165
                    'factory' => 'httplug.factory.guzzle7',
166
                    'http_methods_client' => true,
167
                    'service' => null,
168
                    'public' => null,
169
                    'flexible_client' => false,
170
                    'batch_client' => false,
171
                    'plugins' => [
172
                        [
173
                            'reference' => [
174
                                'enabled' => true,
175
                                'id' => 'httplug.plugin.redirect',
176
                            ],
177
                        ],
178
                        [
179
                            'add_host' => [
180
                                'enabled' => true,
181
                                'host' => 'http://localhost',
182
                                'replace' => false,
183
                            ],
184
                        ],
185
                        [
186
                            'add_path' => [
187
                                'enabled' => true,
188
                                'path' => '/api/v1',
189
                            ],
190
                        ],
191
                        [
192
                            'base_uri' => [
193
                                'enabled' => true,
194
                                'uri' => 'http://localhost',
195
                                'replace' => false,
196
                            ],
197
                        ],
198
                        [
199
                            'content_type' => [
200
                                'enabled' => true,
201
                                'skip_detection' => true,
202
                            ],
203
                        ],
204
                        [
205
                            'header_set' => [
206
                                'enabled' => true,
207
                                'headers' => [
208
                                    'X-FOO' => 'bar',
209
                                ],
210
                            ],
211
                        ],
212
                        [
213
                            'header_remove' => [
214
                                'enabled' => true,
215
                                'headers' => [
216
                                    'X-FOO',
217
                                ],
218
                            ],
219
                        ],
220
                        [
221
                            'authentication' => [
222
                                'my_basic' => [
223
                                    'type' => 'basic',
224
                                    'username' => 'foo',
225
                                    'password' => 'bar',
226
                                    'params' => [],
227
                                ],
228
                            ],
229
                        ],
230
                    ],
231
                    'config' => [],
232
                ],
233
            ],
234
            'profiling' => [
235
                'enabled' => true,
236
                'formatter' => 'my_toolbar_formatter',
237
                'captured_body_length' => 0,
238
            ],
239
            'plugins' => [
240
                'authentication' => [
241
                    'my_basic' => [
242
                        'type' => 'basic',
243
                        'username' => 'foo',
244
                        'password' => 'bar',
245
                        'params' => [],
246
                    ],
247
                    'my_wsse' => [
248
                        'type' => 'wsse',
249
                        'username' => 'foo',
250
                        'password' => 'bar',
251
                        'params' => [],
252
                    ],
253
                    'my_bearer' => [
254
                        'type' => 'bearer',
255
                        'token' => 'foo',
256
                        'params' => [],
257
                    ],
258
                    'my_service' => [
259
                        'type' => 'service',
260
                        'service' => 'my_auth_service',
261
                        'params' => [],
262
                    ],
263
                ],
264
                'cache' => [
265
                    'enabled' => true,
266
                    'cache_pool' => 'my_cache_pool',
267
                    'stream_factory' => 'my_other_stream_factory',
268
                    'config' => [
269
                        'cache_lifetime' => 2592000,
270
                        'default_ttl' => 42,
271
                        'hash_algo' => 'sha1',
272
                        'methods' => ['GET'],
273
                        'cache_key_generator' => null,
274
                        'respect_response_cache_directives' => ['X-Foo'],
275
                        'blacklisted_paths' => ['@/path/not-to-be/cached@'],
276
                        'cache_listeners' => [
277
                            'my_cache_listener_0',
278
                            'my_cache_listener_1',
279
                        ],
280
                    ],
281
                ],
282
                'cookie' => [
283
                    'enabled' => true,
284
                    'cookie_jar' => 'my_cookie_jar',
285
                ],
286
                'decoder' => [
287
                    'enabled' => false,
288
                    'use_content_encoding' => true,
289
                ],
290
                'history' => [
291
                    'enabled' => true,
292
                    'journal' => 'my_journal',
293
                ],
294
                'logger' => [
295
                    'enabled' => false,
296
                    'logger' => 'logger',
297
                    'formatter' => null,
298
                ],
299
                'redirect' => [
300
                    'enabled' => false,
301
                    'preserve_header' => true,
302
                    'use_default_for_multiple' => true,
303
                ],
304
                'retry' => [
305
                    'enabled' => false,
306
                    'retry' => 1,
307
                ],
308
                'stopwatch' => [
309
                    'enabled' => false,
310
                    'stopwatch' => 'debug.stopwatch',
311
                ],
312
            ],
313
            'discovery' => [
314
                'client' => 'auto',
315
                'async_client' => null,
316
            ],
317
        ];
318
319
        $formats = array_map(function ($path) {
320
            return __DIR__.'/../../Resources/Fixtures/'.$path;
321
        }, [
322
            'config/full.yml',
323
            'config/full.xml',
324
            'config/full.php',
325
        ]);
326
327
        foreach ($formats as $format) {
328
            $this->assertProcessedConfigurationEquals($expectedConfiguration, [$format]);
329
        }
330
    }
331
332 View Code Duplication
    public function testMissingClass(): void
333
    {
334
        $file = __DIR__.'/../../Resources/Fixtures/config/invalid_class.yml';
335
336
        $this->expectException(InvalidConfigurationException::class);
337
        $this->expectExceptionMessage('Nonexisting\Class');
338
        $this->assertProcessedConfigurationEquals([], [$file]);
339
    }
340
341 View Code Duplication
    public function testInvalidPlugin(): void
342
    {
343
        $file = __DIR__.'/../../Resources/Fixtures/config/invalid_plugin.yml';
344
345
        $this->expectException(InvalidConfigurationException::class);
346
        $this->expectExceptionMessage('Unrecognized option "foobar" under "httplug.clients.acme.plugins.0"');
347
        $this->assertProcessedConfigurationEquals([], [$file]);
348
    }
349
350 View Code Duplication
    public function testInvalidAuthentication(): void
351
    {
352
        $file = __DIR__.'/../../Resources/Fixtures/config/invalid_auth.yml';
353
354
        $this->expectException(InvalidConfigurationException::class);
355
        $this->expectExceptionMessage('password, service, username');
356
        $this->assertProcessedConfigurationEquals([], [$file]);
357
    }
358
359
    /**
360
     * @group legacy
361
     */
362 View Code Duplication
    public function testInvalidCacheConfig(): void
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...
363
    {
364
        $file = __DIR__.'/../../Resources/Fixtures/config/invalid_cache_config.yml';
365
366
        $this->expectException(InvalidConfigurationException::class);
367
        $this->expectExceptionMessage('Invalid configuration for path "httplug.plugins.cache.config": You can\'t provide config option "respect_cache_headers" and "respect_response_cache_directives" simultaniously. Use "respect_response_cache_directives" instead.');
368
        $this->assertProcessedConfigurationEquals([], [$file]);
369
    }
370
371
    /**
372
     * @group legacy
373
     */
374 View Code Duplication
    public function testBackwardCompatibility(): void
375
    {
376
        $formats = array_map(function ($path) {
377
            return __DIR__.'/../../Resources/Fixtures/'.$path;
378
        }, [
379
            'config/bc/toolbar.yml',
380
            'config/bc/toolbar_auto.yml',
381
        ]);
382
383
        foreach ($formats as $format) {
384
            $this->assertProcessedConfigurationEquals($this->emptyConfig, [$format]);
385
        }
386
    }
387
388
    /**
389
     * @group legacy
390
     */
391 View Code Duplication
    public function testCacheConfigDeprecationCompatibility(): void
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...
392
    {
393
        $file = __DIR__.'/../../Resources/Fixtures/config/bc/cache_config.yml';
394
        $config = $this->emptyConfig;
395
        $config['plugins']['cache'] = array_merge($config['plugins']['cache'], [
396
            'enabled' => true,
397
            'cache_pool' => 'my_cache_pool',
398
            'config' => [
399
                'methods' => ['GET', 'HEAD'],
400
                'respect_cache_headers' => true,
401
                'blacklisted_paths' => [],
402
                'cache_listeners' => [],
403
            ],
404
        ]);
405
        $this->assertProcessedConfigurationEquals($config, [$file]);
406
    }
407
408
    /**
409
     * @group legacy
410
     */
411 View Code Duplication
    public function testCacheConfigDeprecationCompatibilityIssue166(): void
412
    {
413
        $file = __DIR__.'/../../Resources/Fixtures/config/bc/issue-166.yml';
414
        $config = $this->emptyConfig;
415
        $config['plugins']['cache'] = array_merge($config['plugins']['cache'], [
416
            'enabled' => true,
417
            'cache_pool' => 'my_cache_pool',
418
            'config' => [
419
                'methods' => ['GET', 'HEAD'],
420
                'respect_cache_headers' => false,
421
                'blacklisted_paths' => [],
422
                'cache_listeners' => [],
423
            ],
424
        ]);
425
        $this->assertProcessedConfigurationEquals($config, [$file]);
426
    }
427
428 View Code Duplication
    public function testProfilingToolbarCollision(): void
429
    {
430
        $file = __DIR__.'/../../Resources/Fixtures/config/bc/profiling_toolbar.yml';
431
432
        $this->expectException(InvalidConfigurationException::class);
433
        $this->expectExceptionMessage('Can\'t configure both "toolbar" and "profiling" section. The "toolbar" config is deprecated as of version 1.3.0, please only use "profiling".');
434
        $this->assertProcessedConfigurationEquals([], [$file]);
435
    }
436
437 View Code Duplication
    public function testClientCacheConfigMustHavePool(): void
438
    {
439
        $file = __DIR__.'/../../Resources/Fixtures/config/client_cache_config_with_no_pool.yml';
440
441
        $this->expectException(InvalidConfigurationException::class);
442
        $this->expectExceptionMessage('httplug.clients.test.plugins.0.cache');
443
        $this->assertProcessedConfigurationEquals([], [$file]);
444
    }
445
446 View Code Duplication
    public function testCacheConfigMustHavePool(): void
447
    {
448
        $file = __DIR__.'/../../Resources/Fixtures/config/cache_config_with_no_pool.yml';
449
450
        $this->expectException(InvalidConfigurationException::class);
451
        $this->expectExceptionMessage('cache_pool');
452
        $this->assertProcessedConfigurationEquals([], [$file]);
453
    }
454
455
    public function testLimitlessCapturedBodyLength(): void
456
    {
457
        $file = __DIR__.'/../../Resources/Fixtures/config/limitless_captured_body_length.yml';
458
        $config = $this->emptyConfig;
459
        $config['profiling']['captured_body_length'] = null;
460
        $this->assertProcessedConfigurationEquals($config, [$file]);
461
    }
462
463 View Code Duplication
    public function testInvalidCapturedBodyLengthString(): void
464
    {
465
        $file = __DIR__.'/../../Resources/Fixtures/config/invalid_captured_body_length.yml';
466
467
        $this->expectException(InvalidConfigurationException::class);
468
        $this->expectExceptionMessage('The child node "captured_body_length" at path "httplug.profiling" must be an integer or null');
469
        $this->assertProcessedConfigurationEquals([], [$file]);
470
    }
471
}
472