This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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\EventListener; |
||
4 | |||
5 | use Kunstmaan\MultiDomainBundle\EventListener\HostOverrideListener; |
||
6 | use PHPUnit\Framework\TestCase; |
||
7 | use Symfony\Component\HttpFoundation\Request; |
||
8 | use Symfony\Component\HttpKernel\HttpKernelInterface; |
||
9 | |||
10 | class HostOverrideListenerTest extends TestCase |
||
11 | { |
||
12 | /** |
||
13 | * @var HostOverrideListener |
||
14 | */ |
||
15 | protected $object; |
||
16 | |||
17 | /** |
||
18 | * @var |
||
19 | */ |
||
20 | protected $session; |
||
21 | |||
22 | /** |
||
23 | * @covers \Kunstmaan\MultiDomainBundle\EventListener\HostOverrideListener::__construct |
||
24 | * @covers \Kunstmaan\MultiDomainBundle\EventListener\HostOverrideListener::onKernelResponse |
||
25 | */ |
||
26 | View Code Duplication | public function testHostOverrideMessageIsSetForAdmin() |
|
27 | { |
||
28 | $flashBag = $this->createMock('Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface'); |
||
29 | $flashBag |
||
30 | ->expects($this->once()) |
||
31 | ->method('add') |
||
32 | ->with('warning', 'multi_domain.host_override_active'); |
||
33 | |||
34 | $object = $this->getHostOverrideListener($flashBag); |
||
35 | |||
36 | $event = $this->getFilterResponseEvent($this->getAdminRequest(), $this->getResponse()); |
||
37 | $object->onKernelResponse($event); |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * @covers \Kunstmaan\MultiDomainBundle\EventListener\HostOverrideListener::__construct |
||
42 | * @covers \Kunstmaan\MultiDomainBundle\EventListener\HostOverrideListener::onKernelResponse |
||
43 | */ |
||
44 | View Code Duplication | public function testHostOverrideMessageIsNotSetForAdminRedirectResponse() |
|
45 | { |
||
46 | $flashBag = $this->createMock('Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface'); |
||
47 | $flashBag |
||
48 | ->expects($this->never()) |
||
49 | ->method('add'); |
||
50 | |||
51 | $object = $this->getHostOverrideListener($flashBag); |
||
52 | |||
53 | $event = $this->getFilterResponseEvent($this->getAdminRequest(), $this->getRedirectResponse()); |
||
54 | $object->onKernelResponse($event); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * @covers \Kunstmaan\MultiDomainBundle\EventListener\HostOverrideListener::__construct |
||
59 | * @covers \Kunstmaan\MultiDomainBundle\EventListener\HostOverrideListener::onKernelResponse |
||
60 | */ |
||
61 | View Code Duplication | public function testHostOverrideMessageIsNotSetForSubRequest() |
|
62 | { |
||
63 | $flashBag = $this->createMock('Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface'); |
||
64 | $flashBag |
||
65 | ->expects($this->never()) |
||
66 | ->method('add'); |
||
67 | |||
68 | $object = $this->getHostOverrideListener($flashBag); |
||
69 | |||
70 | $event = $this->getFilterResponseEvent($this->getAdminRequest(), $this->getResponse(), HttpKernelInterface::SUB_REQUEST); |
||
71 | $object->onKernelResponse($event); |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * @covers \Kunstmaan\MultiDomainBundle\EventListener\HostOverrideListener::__construct |
||
76 | * @covers \Kunstmaan\MultiDomainBundle\EventListener\HostOverrideListener::onKernelResponse |
||
77 | */ |
||
78 | View Code Duplication | public function testHostOverrideMessageIsNotSetForXmlRequest() |
|
79 | { |
||
80 | $flashBag = $this->createMock('Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface'); |
||
81 | $flashBag |
||
82 | ->expects($this->never()) |
||
83 | ->method('add'); |
||
84 | |||
85 | $object = $this->getHostOverrideListener($flashBag); |
||
86 | |||
87 | $event = $this->getFilterResponseEvent($this->getXmlHttpRequest(), $this->getResponse()); |
||
88 | $object->onKernelResponse($event); |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * @covers \Kunstmaan\MultiDomainBundle\EventListener\HostOverrideListener::__construct |
||
93 | * @covers \Kunstmaan\MultiDomainBundle\EventListener\HostOverrideListener::onKernelResponse |
||
94 | */ |
||
95 | View Code Duplication | public function testHostOverrideMessageIsNotSetForPreview() |
|
96 | { |
||
97 | $flashBag = $this->createMock('Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface'); |
||
98 | $flashBag |
||
99 | ->expects($this->never()) |
||
100 | ->method('add'); |
||
101 | |||
102 | $object = $this->getHostOverrideListener($flashBag); |
||
103 | |||
104 | $event = $this->getFilterResponseEvent($this->getAdminPreviewRequest(), $this->getResponse()); |
||
105 | $object->onKernelResponse($event); |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * @covers \Kunstmaan\MultiDomainBundle\EventListener\HostOverrideListener::__construct |
||
110 | * @covers \Kunstmaan\MultiDomainBundle\EventListener\HostOverrideListener::onKernelResponse |
||
111 | */ |
||
112 | View Code Duplication | public function testHostOverrideMessageIsNotSetForFrontend() |
|
113 | { |
||
114 | $flashBag = $this->createMock('Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface'); |
||
115 | $flashBag |
||
116 | ->expects($this->never()) |
||
117 | ->method('add'); |
||
118 | |||
119 | $object = $this->getHostOverrideListener($flashBag); |
||
120 | |||
121 | $event = $this->getFilterResponseEvent($this->getFrontendRequest(), $this->getResponse()); |
||
122 | $object->onKernelResponse($event); |
||
123 | } |
||
124 | |||
125 | private function getHostOverrideListener($flashBag) |
||
126 | { |
||
127 | $session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\Session') |
||
128 | ->disableOriginalConstructor() |
||
129 | ->getMock(); |
||
130 | $session->method('getFlashBag') |
||
131 | ->willReturn($flashBag); |
||
132 | |||
133 | $domainConfiguration = $this->createMock('Kunstmaan\AdminBundle\Helper\DomainConfigurationInterface'); |
||
134 | $domainConfiguration->method('getHost') |
||
135 | ->willReturn('override-domain.tld'); |
||
136 | $translator = $this->createMock('Symfony\Component\Translation\TranslatorInterface'); |
||
137 | $translator->method('trans') |
||
0 ignored issues
–
show
|
|||
138 | ->willReturnArgument(0); |
||
139 | |||
140 | $adminRouteReturnValueMap = array( |
||
141 | array('/nl/admin/preview/some-uri', false), |
||
142 | array('/nl/some-uri', false), |
||
143 | array('/nl/admin/some-admin-uri', true), |
||
144 | ); |
||
145 | |||
146 | $adminRouteHelper = $this->getMockBuilder('Kunstmaan\AdminBundle\Helper\AdminRouteHelper') |
||
147 | ->disableOriginalConstructor() |
||
148 | ->getMock(); |
||
149 | $adminRouteHelper |
||
150 | ->expects($this->any()) |
||
151 | ->method('isAdminRoute') |
||
152 | ->willReturnMap($adminRouteReturnValueMap); |
||
153 | |||
154 | $listener = new HostOverrideListener($session, $translator, $domainConfiguration, $adminRouteHelper); |
||
155 | |||
156 | return $listener; |
||
157 | } |
||
158 | |||
159 | private function getFilterResponseEvent($request, $response, $requestType = HttpKernelInterface::MASTER_REQUEST) |
||
160 | { |
||
161 | $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\FilterResponseEvent') |
||
162 | ->disableOriginalConstructor() |
||
163 | ->getMock(); |
||
164 | $event->method('getRequestType') |
||
165 | ->willReturn($requestType); |
||
166 | |||
167 | $event->method('getResponse') |
||
168 | ->willReturn($response); |
||
169 | |||
170 | $event->method('getRequest') |
||
171 | ->willReturn($request); |
||
172 | |||
173 | return $event; |
||
174 | } |
||
175 | |||
176 | private function getResponse() |
||
177 | { |
||
178 | return $this->createMock('Symfony\Component\HttpFoundation\Response'); |
||
179 | } |
||
180 | |||
181 | private function getRedirectResponse() |
||
182 | { |
||
183 | $response = $this->getMockBuilder('Symfony\Component\HttpFoundation\RedirectResponse') |
||
184 | ->disableOriginalConstructor() |
||
185 | ->getMock(); |
||
186 | |||
187 | return $response; |
||
188 | } |
||
189 | |||
190 | private function getXmlHttpRequest() |
||
191 | { |
||
192 | $request = Request::create('http://domain.tld/nl/admin/some-admin-uri'); |
||
193 | $request->headers->set('X-Requested-With', 'XMLHttpRequest'); |
||
194 | |||
195 | return $request; |
||
196 | } |
||
197 | |||
198 | private function getAdminRequest() |
||
199 | { |
||
200 | return Request::create('http://domain.tld/nl/admin/some-admin-uri'); |
||
201 | } |
||
202 | |||
203 | private function getAdminPreviewRequest() |
||
204 | { |
||
205 | return Request::create('http://domain.tld/nl/admin/preview/some-uri'); |
||
206 | } |
||
207 | |||
208 | private function getFrontendRequest() |
||
209 | { |
||
210 | return Request::create('http://domain.tld/nl/some-uri'); |
||
211 | } |
||
212 | } |
||
213 |
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.