Issues (3099)

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.

Tests/unit/Router/DomainBasedLocaleRouterTest.php (9 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
namespace Kunstmaan\MultiDomainBundle\Tests\Router;
4
5
use Kunstmaan\MultiDomainBundle\Router\DomainBasedLocaleRouter;
6
use Kunstmaan\NodeBundle\Entity\NodeTranslation;
7
use PHPUnit\Framework\TestCase;
8
use ReflectionClass;
9
use Symfony\Component\DependencyInjection\Container;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
12
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
13
14
class DomainBasedLocaleRouterTest extends TestCase
15
{
16
    public function testGenerate()
17
    {
18
        $request = $this->getRequest();
19
        $object = $this->getDomainBasedLocaleRouter($request);
20
        $url = $object->generate('_slug', array('url' => 'some-uri', '_locale' => 'en_GB'), UrlGeneratorInterface::ABSOLUTE_URL);
21
        $this->assertEquals('http://multilangdomain.tld/en/some-uri', $url);
22
23
        $url = $object->generate('_slug', array('url' => 'some-uri', '_locale' => 'en_GB'), UrlGeneratorInterface::ABSOLUTE_PATH);
24
        $this->assertEquals('/en/some-uri', $url);
25
    }
26
27 View Code Duplication
    public function testGenerateWithOtherSite()
28
    {
29
        $request = $this->getRequest();
30
        $request->setLocale('nl_BE');
31
        $object = $this->getDomainBasedLocaleRouter($request);
32
        $url = $object->generate('_slug', array('url' => 'some-uri', 'otherSite' => 'https://cia.gov'), UrlGeneratorInterface::ABSOLUTE_URL);
33
        $this->assertEquals('http://multilangdomain.tld/nl/some-uri', $url);
34
35
        $url = $object->generate('_slug', array('url' => 'some-uri'), UrlGeneratorInterface::ABSOLUTE_PATH);
36
        $this->assertEquals('/nl/some-uri', $url);
37
    }
38
39 View Code Duplication
    public function testGenerateWithLocaleBasedOnCurrentRequest()
40
    {
41
        $request = $this->getRequest();
42
        $request->setLocale('nl_BE');
43
        $object = $this->getDomainBasedLocaleRouter($request);
44
        $url = $object->generate('_slug', array('url' => 'some-uri'), UrlGeneratorInterface::ABSOLUTE_URL);
45
        $this->assertEquals('http://multilangdomain.tld/nl/some-uri', $url);
46
47
        $url = $object->generate('_slug', array('url' => 'some-uri'), UrlGeneratorInterface::ABSOLUTE_PATH);
48
        $this->assertEquals('/nl/some-uri', $url);
49
    }
50
51
    public function testMatchWithNodeTranslation()
52
    {
53
        $request = $this->getRequest();
54
        $nodeTranslation = new NodeTranslation();
55
        $object = $this->getDomainBasedLocaleRouter($request, $nodeTranslation);
56
        $result = $object->match('/en/some-uri');
57
        $this->assertEquals('some-uri', $result['url']);
58
        $this->assertEquals('en_GB', $result['_locale']);
59
        $this->assertEquals($nodeTranslation, $result['_nodeTranslation']);
60
    }
61
62
    public function testMatchWithoutNodeTranslation()
63
    {
64
        $this->expectException(ResourceNotFoundException::class);
65
        $request = $this->getRequest();
66
        $object = $this->getDomainBasedLocaleRouter($request);
67
        $object->match('/en/some-uri');
68
    }
69
70
    /**
71
     * @throws \ReflectionException
72
     */
73 View Code Duplication
    public function testAddMultiLangSlugRoute()
74
    {
75
        $domainConfiguration = $this->createMock('Kunstmaan\AdminBundle\Helper\DomainConfigurationInterface');
76
        $domainConfiguration->method('getHost')
77
            ->willReturn('override-domain.tld');
78
79
        $domainConfiguration->method('isMultiDomainHost')
80
            ->willReturn(true);
81
82
        $domainConfiguration->method('isMultiLanguage')
83
            ->willReturn(true);
84
85
        $domainConfiguration->method('getDefaultLocale')
86
            ->willReturn('nl_BE');
87
88
        $domainConfiguration->method('getFrontendLocales')
89
            ->willReturn(array('nl', 'en'));
90
91
        $node = $this->createMock('Kunstmaan\NodeBundle\Entity\Node');
92
        $domainConfiguration->method('getRootNode')
93
            ->willReturn($node);
94
95
        $domainConfiguration->method('getBackendLocales')
96
            ->willReturn(array('nl_BE', 'en_GB'));
97
98
        $request = $this->getRequest('http://singlelangdomain.tld/');
99
100
        $object = new DomainBasedLocaleRouter($domainConfiguration, $this->getRequestStack($request), $this->getEntityManager(new NodeTranslation()));
101
102
        $mirror = new ReflectionClass(DomainBasedLocaleRouter::class);
103
        $property = $mirror->getProperty('otherSite');
104
        $property->setAccessible(true);
105
        $property->setValue($object, ['host' => 'https://cia.gov']);
106
        $collection = $object->getRouteCollection();
107
        $array = $collection->getIterator()->getArrayCopy();
108
        $this->assertArrayHasKey('_slug', $array);
109
        $this->assertArrayHasKey('_slug_preview', $array);
110
    }
111
112
    /**
113
     * @throws \ReflectionException
114
     */
115 View Code Duplication
    public function testGetRouteCollection()
116
    {
117
        $domainConfiguration = $this->createMock('Kunstmaan\AdminBundle\Helper\DomainConfigurationInterface');
118
        $domainConfiguration->method('getHost')
119
            ->willReturn('override-domain.tld');
120
121
        $domainConfiguration->method('isMultiDomainHost')
122
            ->willReturn(false);
123
124
        $domainConfiguration->method('isMultiLanguage')
125
            ->willReturn(false);
126
127
        $domainConfiguration->method('getDefaultLocale')
128
            ->willReturn('nl_BE');
129
130
        $domainConfiguration->method('getFrontendLocales')
131
            ->willReturn(array('nl', 'en'));
132
133
        $node = $this->createMock('Kunstmaan\NodeBundle\Entity\Node');
134
        $domainConfiguration->method('getRootNode')
135
            ->willReturn($node);
136
137
        $domainConfiguration->method('getBackendLocales')
138
            ->willReturn(array('nl_BE', 'en_GB'));
139
140
        $request = $this->getRequest('http://singlelangdomain.tld/');
141
142
        /** @var Container $container */
143
        $object = new DomainBasedLocaleRouter($domainConfiguration, $this->getRequestStack($request), $this->getEntityManager(new NodeTranslation()));
144
        $mirror = new ReflectionClass(DomainBasedLocaleRouter::class);
145
        $property = $mirror->getProperty('otherSite');
146
        $property->setAccessible(true);
147
        $property->setValue($object, ['host' => 'https://cia.gov']);
148
        $collection = $object->getRouteCollection();
149
        $array = $collection->getIterator()->getArrayCopy();
150
        $this->assertArrayHasKey('_slug', $array);
151
        $this->assertArrayHasKey('_slug_preview', $array);
152
    }
153
154
    private function getRequestStack($request)
155
    {
156
        $requestStack = $this->createMock('Symfony\Component\HttpFoundation\RequestStack');
157
        $requestStack->expects($this->any())->method('getMasterRequest')->willReturn($request);
158
159
        return $requestStack;
160
    }
161
162
    private function getDomainConfiguration()
163
    {
164
        $domainConfiguration = $this->createMock('Kunstmaan\AdminBundle\Helper\DomainConfigurationInterface');
165
        $domainConfiguration->method('getHost')
0 ignored issues
show
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
166
            ->willReturn('override-domain.tld');
167
168
        $domainConfiguration->method('isMultiDomainHost')
0 ignored issues
show
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
169
            ->willReturn(true);
170
171
        $domainConfiguration->method('isMultiLanguage')
0 ignored issues
show
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
172
            ->willReturn(true);
173
174
        $domainConfiguration->method('getDefaultLocale')
0 ignored issues
show
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
175
            ->willReturn('nl_BE');
176
177
        $domainConfiguration->method('getFrontendLocales')
0 ignored issues
show
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
178
            ->willReturn(array('nl', 'en'));
179
180
        $node = $this->createMock('Kunstmaan\NodeBundle\Entity\Node');
181
        $domainConfiguration->method('getRootNode')
0 ignored issues
show
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
182
            ->willReturn($node);
183
184
        $domainConfiguration->method('getBackendLocales')
0 ignored issues
show
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
185
            ->willReturn(array('nl_BE', 'en_GB'));
186
187
        return $domainConfiguration;
188
    }
189
190
    private function getRequest($url = 'http://multilangdomain.tld/')
191
    {
192
        return Request::create($url);
193
    }
194
195 View Code Duplication
    private function getEntityManager($nodeTranslation = null)
196
    {
197
        $em = $this->createMock('Doctrine\ORM\EntityManagerInterface');
198
        $em
0 ignored issues
show
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
199
            ->method('getRepository')
200
            ->with($this->equalTo(NodeTranslation::class))
201
            ->willReturn($this->getNodeTranslationRepository($nodeTranslation));
202
203
        return $em;
204
    }
205
206 View Code Duplication
    private function getNodeTranslationRepository($nodeTranslation = null)
207
    {
208
        $repository = $this->getMockBuilder('Kunstmaan\NodeBundle\Repository\NodeTranslationRepository')
209
            ->disableOriginalConstructor()
210
            ->getMock();
211
        $repository
0 ignored issues
show
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
212
            ->method('getNodeTranslationForUrl')
213
            ->willReturn($nodeTranslation);
214
215
        return $repository;
216
    }
217
218
    private function getDomainBasedLocaleRouter($request, $nodeTranslation = null)
219
    {
220
        return new DomainBasedLocaleRouter($this->getDomainConfiguration(), $this->getRequestStack($request), $this->getEntityManager($nodeTranslation));
221
    }
222
}
223