Issues (3103)

Branch: master

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.

ConfigResolver/ChainConfigResolverTest.php (1 issue)

Labels
Severity

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
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace eZ\Bundle\EzPublishCoreBundle\Tests\DependencyInjection\Configuration\ConfigResolver;
10
11
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ChainConfigResolver;
12
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ConfigResolver\DefaultScopeConfigResolver;
13
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ConfigResolver\GlobalScopeConfigResolver;
14
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ConfigResolver\SiteAccessGroupConfigResolver;
15
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ConfigResolver\StaticSiteAccessConfigResolver;
16
use eZ\Publish\Core\MVC\ConfigResolverInterface;
17
use eZ\Publish\Core\MVC\Symfony\SiteAccess;
18
use eZ\Publish\Core\MVC\Symfony\SiteAccess\Provider\StaticSiteAccessProvider;
19
use eZ\Publish\Core\MVC\Symfony\SiteAccessGroup;
20
use PHPUnit\Framework\TestCase;
21
use function sprintf;
22
use Symfony\Component\DependencyInjection\ContainerInterface;
23
24
class ChainConfigResolverTest extends TestCase
25
{
26
    private const FIRST_SA_NAME = 'first_sa';
27
    private const SECOND_SA_NAME = 'second_sa';
28
    private const SA_GROUP = 'sa_group';
29
30
    private const DEFAULT_NAMESPACE = 'ezsettings';
31
32
    private const SCOPE_DEFAULT = 'default';
33
    private const SCOPE_GLOBAL = 'global';
34
35
    /** @var \eZ\Publish\Core\MVC\Symfony\SiteAccess|\PHPUnit\Framework\MockObject\MockObject */
36
    private $siteAccess;
37
38
    /** @var \Symfony\Component\DependencyInjection\ContainerInterface|\PHPUnit\Framework\MockObject\MockObject */
39
    private $containerMock;
40
41
    protected function setUp(): void
42
    {
43
        parent::setUp();
44
        $this->siteAccess = new SiteAccess(self::FIRST_SA_NAME);
45
        $this->siteAccess->groups = [new SiteAccessGroup(self::SA_GROUP)];
46
        $this->containerMock = $this->createMock(ContainerInterface::class);
47
    }
48
49
    /**
50
     * @dataProvider parameterProvider
51
     */
52
    public function testGetParameterDefaultScope(string $paramName, $expectedValue): void
53
    {
54
        $globalScopeParameter = $this->getParameter($paramName, self::SCOPE_GLOBAL);
55
        $relativeScopeParameter = $this->getParameter($paramName, $this->siteAccess->name);
56
        $saGroupScopeParameter = $this->getParameter($paramName, self::SA_GROUP);
57
        $defaultScopeParameter = $this->getParameter($paramName, self::SCOPE_DEFAULT);
58
        $this->containerMock
59
             ->expects($this->exactly(4))
60
             ->method('hasParameter')
61
             ->with(
62
                 $this->logicalOr(
63
                     $globalScopeParameter,
64
                     $relativeScopeParameter,
65
                     $saGroupScopeParameter,
66
                     $defaultScopeParameter
67
                 )
68
             )
69
             // First call is for "global" scope, second for SA scope, third fo SA group scope, last is the right one
70
             ->will($this->onConsecutiveCalls(false, false, false, true));
71
        $this->containerMock
72
             ->expects($this->once())
73
             ->method('getParameter')
74
             ->with($defaultScopeParameter)
75
             ->willReturn($expectedValue);
76
77
        $this->assertSame($expectedValue, $this->getChainConfigResolver()->getParameter($paramName));
78
    }
79
80
    /**
81
     * @dataProvider parameterProvider
82
     */
83
    public function testGetParameterRelativeScope(string $paramName, $expectedValue): void
84
    {
85
        $globalScopeParameter = $this->getParameter($paramName, self::SCOPE_GLOBAL);
86
        $relativeScopeParameter = $this->getParameter($paramName, $this->siteAccess->name);
87
        $this->containerMock
88
             ->expects($this->exactly(2))
89
             ->method('hasParameter')
90
             ->with(
91
                 $this->logicalOr(
92
                     $globalScopeParameter,
93
                     $relativeScopeParameter
94
                 )
95
             )
96
             // First call is for "global" scope, second is the right one
97
             ->will($this->onConsecutiveCalls(false, true));
98
        $this->containerMock
99
             ->expects($this->once())
100
             ->method('getParameter')
101
             ->with($relativeScopeParameter)
102
             ->willReturn($expectedValue);
103
104
        $this->assertSame($expectedValue, $this->getChainConfigResolver()->getParameter($paramName));
105
    }
106
107
    /**
108
     * @dataProvider parameterProvider
109
     */
110
    public function testGetParameterSpecificScope(string $paramName, $expectedValue): void
111
    {
112
        $specificScopeParameter = $this->getParameter($paramName, self::FIRST_SA_NAME);
113
        $this->containerMock
114
             ->expects($this->exactly(2))
115
             ->method('hasParameter')
116
             ->with(
117
                 $this->logicalOr(
118
                     "ezsettings.global.$paramName",
119
                     $specificScopeParameter
120
                 )
121
             )
122
             // First call is for "global" scope, second is the right one
123
             ->will($this->onConsecutiveCalls(false, true));
124
        $this->containerMock
125
             ->expects($this->once())
126
             ->method('getParameter')
127
             ->with($specificScopeParameter)
128
             ->willReturn($expectedValue);
129
130
        $this->assertSame(
131
             $expectedValue,
132
             $this->getChainConfigResolver()->getParameter($paramName, self::DEFAULT_NAMESPACE, self::FIRST_SA_NAME)
133
         );
134
    }
135
136
    /**
137
     * @dataProvider parameterProvider
138
     */
139
    public function testGetParameterGlobalScope(string $paramName, $expectedValue): void
140
    {
141
        $globalScopeParameter = $this->getParameter($paramName, self::SCOPE_GLOBAL);
142
        $this->containerMock
143
             ->expects($this->once())
144
             ->method('hasParameter')
145
             ->with($globalScopeParameter)
146
             ->willReturn(true);
147
        $this->containerMock
148
             ->expects($this->once())
149
             ->method('getParameter')
150
             ->with($globalScopeParameter)
151
             ->willReturn($expectedValue);
152
153
        $this->assertSame($expectedValue, $this->getChainConfigResolver()->getParameter($paramName));
154
    }
155
156
    /**
157
     * @dataProvider hasParameterProvider
158
     */
159
    public function testHasParameterNoNamespace(
160
         bool $defaultMatch,
161
         bool $groupMatch,
162
         bool $scopeMatch,
163
         bool $globalMatch,
164
         bool $expectedResult
165
     ): void {
166
        $paramName = 'foo.bar';
167
        $groupName = self::SA_GROUP;
168
169
        $chainConfigResolver = $this->getChainConfigResolver();
170
171
        $this->containerMock->expects($this->atLeastOnce())
172
             ->method('hasParameter')
173
             ->willReturnMap(
174
                 [
175
                     ["ezsettings.default.$paramName", $defaultMatch],
176
                     ["ezsettings.$groupName.$paramName", $groupMatch],
177
                     ["ezsettings.{$this->siteAccess->name}.$paramName", $scopeMatch],
178
                     ["ezsettings.global.$paramName", $globalMatch],
179
                 ]
180
             );
181
182
        $this->assertSame($expectedResult, $chainConfigResolver->hasParameter($paramName));
183
    }
184
185
    /**
186
     * @dataProvider hasParameterProvider
187
     */
188
    public function testHasParameterWithNamespaceAndScope(
189
         bool $defaultMatch,
190
         bool $groupMatch,
191
         bool $scopeMatch,
192
         bool $globalMatch,
193
         bool $expectedResult
194
     ): void {
195
        $paramName = 'foo.bar';
196
        $namespace = 'my.namespace';
197
        $scope = self::SECOND_SA_NAME;
198
        $groupName = self::SA_GROUP;
199
200
        $chainConfigResolver = $this->getChainConfigResolver();
201
202
        $this->containerMock->expects($this->atLeastOnce())
203
             ->method('hasParameter')
204
             ->willReturnMap(
205
                 [
206
                     ["$namespace.default.$paramName", $defaultMatch],
207
                     ["$namespace.$groupName.$paramName", $groupMatch],
208
                     ["$namespace.$scope.$paramName", $scopeMatch],
209
                     ["$namespace.global.$paramName", $globalMatch],
210
                 ]
211
             );
212
213
        $this->assertSame($expectedResult, $chainConfigResolver->hasParameter($paramName, $namespace, $scope));
214
    }
215
216
    private function getGlobalConfigResolver(string $defaultNamespace = self::DEFAULT_NAMESPACE): ConfigResolverInterface
217
    {
218
        $configResolver = new GlobalScopeConfigResolver(
219
             $defaultNamespace
220
         );
221
        $configResolver->setContainer($this->containerMock);
222
223
        return $configResolver;
224
    }
225
226
    private function getDefaultConfigResolver(string $defaultNamespace = self::DEFAULT_NAMESPACE): ConfigResolverInterface
227
    {
228
        $configResolver = new DefaultScopeConfigResolver(
229
             $defaultNamespace
230
         );
231
        $configResolver->setContainer($this->containerMock);
232
233
        return $configResolver;
234
    }
235
236
    protected function getSiteAccessGroupConfigResolver(string $defaultNamespace = self::DEFAULT_NAMESPACE): ConfigResolverInterface
237
    {
238
        $siteAccess = new SiteAccess(
239
             self::FIRST_SA_NAME,
240
         );
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected ')'
Loading history...
241
        $configResolver = new SiteAccessGroupConfigResolver(
242
             $this->getStaticSiteAccessProvider(),
243
             $defaultNamespace,
244
             []
245
         );
246
        $configResolver->setContainer($this->containerMock);
247
        $configResolver->setSiteAccess($siteAccess);
248
249
        return $configResolver;
250
    }
251
252
    protected function getSiteAccessConfigResolver(string $defaultNamespace = self::DEFAULT_NAMESPACE): ConfigResolverInterface
253
    {
254
        $siteAccess = new SiteAccess(
255
             self::FIRST_SA_NAME,
256
         );
257
        $configResolver = new StaticSiteAccessConfigResolver(
258
             $this->getStaticSiteAccessProvider(),
259
             $defaultNamespace
260
         );
261
        $configResolver->setContainer($this->containerMock);
262
        $configResolver->setSiteAccess($siteAccess);
263
264
        return $configResolver;
265
    }
266
267
    private function getStaticSiteAccessProvider(): StaticSiteAccessProvider
268
    {
269
        return new StaticSiteAccessProvider(
270
             [
271
                 self::FIRST_SA_NAME,
272
                 self::SECOND_SA_NAME,
273
             ],
274
             [
275
                 self::FIRST_SA_NAME => [self::SA_GROUP],
276
                 self::SECOND_SA_NAME => [self::SA_GROUP],
277
             ],
278
         );
279
    }
280
281
    public function parameterProvider(): array
282
    {
283
        return [
284
             ['foo', 'bar'],
285
             ['some.parameter', true],
286
             ['some.other.parameter', ['foo', 'bar', 'baz']],
287
             ['a.hash.parameter', ['foo' => 'bar', 'tata' => 'toto']],
288
             [
289
                 'a.deep.hash', [
290
                 'foo' => 'bar',
291
                 'tata' => 'toto',
292
                 'deeper_hash' => [
293
                     'likeStarWars' => true,
294
                     'jedi' => ['Obi-Wan Kenobi', 'Mace Windu', 'Luke Skywalker', 'Leïa Skywalker (yes! Read episodes 7-8-9!)'],
295
                     'sith' => ['Darth Vader', 'Darth Maul', 'Palpatine'],
296
                     'roles' => [
297
                         'Amidala' => ['Queen'],
298
                         'Palpatine' => ['Senator', 'Emperor', 'Villain'],
299
                         'C3PO' => ['Droid', 'Annoying guy'],
300
                         'Jar-Jar' => ['Still wondering his role', 'Annoying guy'],
301
                     ],
302
                 ],
303
             ],
304
             ],
305
         ];
306
    }
307
308
    public function hasParameterProvider(): array
309
    {
310
        return [
311
             [true, true, true, true, true],
312
             [true, true, true, false, true],
313
             [true, true, false, false, true],
314
             [false, false, false, false, false],
315
             [false, false, true, false, true],
316
             [false, false, false, true, true],
317
             [false, false, true, true, true],
318
             [false, true, false, false, true],
319
         ];
320
    }
321
322
    private function getChainConfigResolver(): ChainConfigResolver
323
    {
324
        $chainConfigResolver = new ChainConfigResolver();
325
        $chainConfigResolver->addResolver($this->getDefaultConfigResolver(), 0);
326
        $chainConfigResolver->addResolver($this->getSiteAccessGroupConfigResolver(), 50);
327
        $chainConfigResolver->addResolver($this->getSiteAccessConfigResolver(), 100);
328
        $chainConfigResolver->addResolver($this->getGlobalConfigResolver(), 255);
329
330
        return $chainConfigResolver;
331
    }
332
333
    private function getParameter(
334
        string $paramName,
335
        string $scope,
336
        string $namespace = self::DEFAULT_NAMESPACE
337
     ): string {
338
        return sprintf('%s.%s.%s', $namespace, $scope, $paramName);
339
    }
340
}
341