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 Liip\MonitorBundle\Tests\DependencyInjection; |
||
4 | |||
5 | use Laminas\Diagnostics\Check\ApcFragmentation; |
||
6 | use Laminas\Diagnostics\Check\ApcMemory; |
||
7 | use Laminas\Diagnostics\Check\ClassExists; |
||
8 | use Laminas\Diagnostics\Check\CpuPerformance; |
||
9 | use Laminas\Diagnostics\Check\DirReadable; |
||
10 | use Laminas\Diagnostics\Check\DirWritable; |
||
11 | use Laminas\Diagnostics\Check\DiskUsage; |
||
12 | use Laminas\Diagnostics\Check\ExtensionLoaded; |
||
13 | use Laminas\Diagnostics\Check\GuzzleHttpService; |
||
14 | use Laminas\Diagnostics\Check\HttpService; |
||
15 | use Laminas\Diagnostics\Check\IniFile; |
||
16 | use Laminas\Diagnostics\Check\JsonFile; |
||
17 | use Laminas\Diagnostics\Check\Memcache; |
||
18 | use Laminas\Diagnostics\Check\OpCacheMemory; |
||
19 | use Laminas\Diagnostics\Check\PDOCheck; |
||
20 | use Laminas\Diagnostics\Check\PhpFlag; |
||
21 | use Laminas\Diagnostics\Check\PhpVersion; |
||
22 | use Laminas\Diagnostics\Check\ProcessRunning; |
||
23 | use Laminas\Diagnostics\Check\RabbitMQ; |
||
24 | use Laminas\Diagnostics\Check\Redis; |
||
25 | use Laminas\Diagnostics\Check\SecurityAdvisory; |
||
26 | use Laminas\Diagnostics\Check\StreamWrapperExists; |
||
27 | use Laminas\Diagnostics\Check\XmlFile; |
||
28 | use Laminas\Diagnostics\Check\YamlFile; |
||
29 | use Liip\MonitorBundle\Check\CustomErrorPages; |
||
30 | use Liip\MonitorBundle\Check\DoctrineDbal; |
||
31 | use Liip\MonitorBundle\Check\Expression; |
||
32 | use Liip\MonitorBundle\Check\SymfonyVersion; |
||
33 | use Liip\MonitorBundle\DependencyInjection\Compiler\AddGroupsCompilerPass; |
||
34 | use Liip\MonitorBundle\DependencyInjection\Compiler\CheckCollectionTagCompilerPass; |
||
35 | use Liip\MonitorBundle\DependencyInjection\Compiler\CheckTagCompilerPass; |
||
36 | use Liip\MonitorBundle\DependencyInjection\Compiler\GroupRunnersCompilerPass; |
||
37 | use Liip\MonitorBundle\DependencyInjection\LiipMonitorExtension; |
||
38 | use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; |
||
39 | use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
||
40 | |||
41 | /** |
||
42 | * @author Kevin Bond <[email protected]> |
||
43 | */ |
||
44 | class LiipMonitorExtensionTest extends AbstractExtensionTestCase |
||
45 | { |
||
46 | protected function setUp(): void |
||
47 | { |
||
48 | parent::setUp(); |
||
49 | |||
50 | $doctrineMock = $this->getMockBuilder('Doctrine\Persistence\ConnectionRegistry')->getMock(); |
||
51 | $this->container->set('doctrine', $doctrineMock); |
||
52 | $this->container->addCompilerPass(new AddGroupsCompilerPass()); |
||
53 | $this->container->addCompilerPass(new GroupRunnersCompilerPass()); |
||
54 | $this->container->addCompilerPass(new CheckTagCompilerPass()); |
||
55 | $this->container->addCompilerPass(new CheckCollectionTagCompilerPass()); |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * @dataProvider checkProvider |
||
60 | */ |
||
61 | public function testChecksLoaded($name, $config, $checkClass, $checkAlias = null, $checkCount = 1) |
||
62 | { |
||
63 | // skip checks for missing classes |
||
64 | if (!class_exists($checkClass)) { |
||
65 | $this->setExpectedException('InvalidArgumentException'); |
||
0 ignored issues
–
show
|
|||
66 | } |
||
67 | |||
68 | if (!$checkAlias) { |
||
69 | $checkAlias = $name; |
||
70 | } |
||
71 | |||
72 | $this->container->setParameter('kernel.project_dir', __DIR__); |
||
73 | $this->load(['checks' => [$name => $config]]); |
||
74 | $this->compile(); |
||
75 | |||
76 | $runner = $this->container->get('liip_monitor.runner'); |
||
77 | |||
78 | $this->assertCount($checkCount, $runner->getChecks()); |
||
79 | $this->assertInstanceOf($checkClass, $runner->getCheck($checkAlias)); |
||
80 | } |
||
81 | |||
82 | public function testDefaultNoChecks() |
||
83 | { |
||
84 | $this->load(); |
||
85 | $this->compile(); |
||
86 | |||
87 | $this->assertCount(0, $this->container->get('liip_monitor.runner')->getChecks()); |
||
88 | } |
||
89 | |||
90 | public function testDefaultGroupParameterHasNoChecks() |
||
91 | { |
||
92 | $this->load(); |
||
93 | $this->compile(); |
||
94 | |||
95 | $this->assertTrue($this->container->hasParameter('liip_monitor.default_group')); |
||
96 | $this->assertSame('default', $this->container->getParameter('liip_monitor.default_group')); |
||
97 | } |
||
98 | |||
99 | View Code Duplication | public function testDefaultGroupParameter() |
|
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...
|
|||
100 | { |
||
101 | $this->load(['checks' => ['php_extensions' => ['foo']]]); |
||
102 | $this->compile(); |
||
103 | |||
104 | $this->assertTrue($this->container->hasParameter('liip_monitor.default_group')); |
||
105 | $this->assertSame('default', $this->container->getParameter('liip_monitor.default_group')); |
||
106 | } |
||
107 | |||
108 | View Code Duplication | public function testDefaultGroupParameterCustom() |
|
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...
|
|||
109 | { |
||
110 | $this->load(['checks' => ['php_extensions' => ['foo']], 'default_group' => 'foo_bar']); |
||
111 | $this->compile(); |
||
112 | |||
113 | $this->assertTrue($this->container->hasParameter('liip_monitor.default_group')); |
||
114 | $this->assertSame('foo_bar', $this->container->getParameter('liip_monitor.default_group')); |
||
115 | } |
||
116 | |||
117 | public function testEnableController() |
||
118 | { |
||
119 | $this->load(); |
||
120 | |||
121 | $this->assertFalse($this->container->has('liip_monitor.health_controller')); |
||
122 | |||
123 | $this->load(['enable_controller' => true]); |
||
124 | |||
125 | $this->assertTrue($this->container->has('liip_monitor.health_controller')); |
||
126 | } |
||
127 | |||
128 | public function testDisabledDefaultMailer() |
||
129 | { |
||
130 | $this->load(); |
||
131 | |||
132 | $this->assertFalse($this->container->hasParameter('liip_monitor.mailer.enabled')); |
||
133 | $this->assertFalse($this->container->hasParameter('liip_monitor.mailer.recipient')); |
||
134 | $this->assertFalse($this->container->hasParameter('liip_monitor.mailer.sender')); |
||
135 | $this->assertFalse($this->container->hasParameter('liip_monitor.mailer.subject')); |
||
136 | $this->assertFalse($this->container->hasParameter('liip_monitor.mailer.send_on_warning')); |
||
137 | } |
||
138 | |||
139 | public function testDisabledMailer() |
||
140 | { |
||
141 | $this->load( |
||
142 | [ |
||
143 | 'mailer' => [ |
||
144 | 'enabled' => false, |
||
145 | 'recipient' => '[email protected]', |
||
146 | 'sender' => '[email protected]', |
||
147 | 'subject' => 'Health Check', |
||
148 | 'send_on_warning' => true, |
||
149 | ], |
||
150 | ] |
||
151 | ); |
||
152 | |||
153 | $this->assertFalse($this->container->hasParameter('liip_monitor.mailer.enabled')); |
||
154 | $this->assertFalse($this->container->hasParameter('liip_monitor.mailer.recipient')); |
||
155 | $this->assertFalse($this->container->hasParameter('liip_monitor.mailer.sender')); |
||
156 | $this->assertFalse($this->container->hasParameter('liip_monitor.mailer.subject')); |
||
157 | $this->assertFalse($this->container->hasParameter('liip_monitor.mailer.send_on_warning')); |
||
158 | } |
||
159 | |||
160 | public function testEnabledMailer() |
||
161 | { |
||
162 | $this->load( |
||
163 | [ |
||
164 | 'mailer' => [ |
||
165 | 'enabled' => true, |
||
166 | 'recipient' => '[email protected]', |
||
167 | 'sender' => '[email protected]', |
||
168 | 'subject' => 'Health Check', |
||
169 | 'send_on_warning' => true, |
||
170 | ], |
||
171 | ] |
||
172 | ); |
||
173 | |||
174 | $this->assertContainerBuilderHasParameter('liip_monitor.mailer.enabled', true); |
||
175 | $this->assertContainerBuilderHasParameter('liip_monitor.mailer.recipient', ['[email protected]']); |
||
176 | $this->assertContainerBuilderHasParameter('liip_monitor.mailer.sender', '[email protected]'); |
||
177 | $this->assertContainerBuilderHasParameter('liip_monitor.mailer.subject', 'Health Check'); |
||
178 | $this->assertContainerBuilderHasParameter('liip_monitor.mailer.send_on_warning', true); |
||
179 | } |
||
180 | |||
181 | /** |
||
182 | * @dataProvider mailerConfigProvider |
||
183 | */ |
||
184 | public function testInvalidMailerConfig($config) |
||
185 | { |
||
186 | $this->expectException(InvalidConfigurationException::class); |
||
187 | |||
188 | $this->load($config); |
||
189 | } |
||
190 | |||
191 | public function mailerConfigProvider() |
||
192 | { |
||
193 | return [ |
||
194 | [ |
||
195 | [ |
||
196 | 'mailer' => [ |
||
197 | 'recipient' => '[email protected]', |
||
198 | ], |
||
199 | ], |
||
200 | ], |
||
201 | [ |
||
202 | [ |
||
203 | 'mailer' => [ |
||
204 | 'recipient' => '[email protected]', |
||
205 | 'sender' => '[email protected]', |
||
206 | 'subject' => null, |
||
207 | ], |
||
208 | ], |
||
209 | ], |
||
210 | ]; |
||
211 | } |
||
212 | |||
213 | /** |
||
214 | * @dataProvider invalidCheckProvider |
||
215 | */ |
||
216 | public function testInvalidExpressionConfig(array $config) |
||
217 | { |
||
218 | $this->expectException(InvalidConfigurationException::class); |
||
219 | |||
220 | $this->load(['checks' => ['expressions' => $config]]); |
||
221 | $this->compile(); |
||
222 | } |
||
223 | |||
224 | public function invalidCheckProvider() |
||
225 | { |
||
226 | return [ |
||
227 | [['foo']], |
||
228 | [['foo' => ['critical_expression' => 'true']]], |
||
229 | [['foo' => ['label' => 'foo']]], |
||
230 | ]; |
||
231 | } |
||
232 | |||
233 | public function checkProvider() |
||
234 | { |
||
235 | return [ |
||
236 | ['php_extensions', ['foo'], ExtensionLoaded::class], |
||
237 | ['php_flags', ['foo' => 'true'], PhpFlag::class, 'php_flag_foo'], |
||
238 | ['php_version', ['5.3.3' => '='], PhpVersion::class, 'php_version_5.3.3'], |
||
239 | ['process_running', 'foo', ProcessRunning::class, 'process_foo_running'], |
||
240 | ['process_running', ['foo'], ProcessRunning::class, 'process_foo_running'], |
||
241 | ['process_running', ['foo', 'bar'], ProcessRunning::class, 'process_foo_running', 2], |
||
242 | ['process_running', ['foo', 'bar'], ProcessRunning::class, 'process_bar_running', 2], |
||
243 | ['readable_directory', ['foo'], DirReadable::class], |
||
244 | ['writable_directory', ['foo'], DirWritable::class], |
||
245 | ['class_exists', ['Foo'], ClassExists::class], |
||
246 | ['cpu_performance', 0.5, CpuPerformance::class], |
||
247 | ['disk_usage', ['path' => __DIR__], DiskUsage::class], |
||
248 | ['symfony_requirements', ['file' => __DIR__.'/../../LiipMonitorBundle.php'], 'Liip\MonitorBundle\Check\SymfonyRequirements'], |
||
249 | ['opcache_memory', null, OpCacheMemory::class], |
||
250 | ['apc_memory', null, ApcMemory::class], |
||
251 | ['apc_fragmentation', null, ApcFragmentation::class], |
||
252 | ['doctrine_dbal', 'foo', DoctrineDbal::class, 'doctrine_dbal_foo_connection'], |
||
253 | ['doctrine_dbal', ['foo'], DoctrineDbal::class, 'doctrine_dbal_foo_connection'], |
||
254 | ['doctrine_dbal', ['foo', 'bar'], DoctrineDbal::class, 'doctrine_dbal_foo_connection', 2], |
||
255 | ['doctrine_dbal', ['foo', 'bar'], DoctrineDbal::class, 'doctrine_dbal_bar_connection', 2], |
||
256 | ['memcache', ['foo' => null], Memcache::class, 'memcache_foo'], |
||
257 | ['redis', ['foo' => null], Redis::class, 'redis_foo'], |
||
258 | ['http_service', ['foo' => null], HttpService::class, 'http_service_foo'], |
||
259 | ['guzzle_http_service', ['foo' => null], GuzzleHttpService::class, 'guzzle_http_service_foo'], |
||
260 | ['rabbit_mq', ['foo' => null], RabbitMQ::class, 'rabbit_mq_foo'], |
||
261 | ['symfony_version', null, SymfonyVersion::class], |
||
262 | ['custom_error_pages', ['error_codes' => [500]], CustomErrorPages::class], |
||
263 | ['security_advisory', ['lock_file' => __DIR__.'/../../composer.lock'], SecurityAdvisory::class], |
||
264 | ['stream_wrapper_exists', ['foo'], StreamWrapperExists::class], |
||
265 | ['file_ini', ['foo.ini'], IniFile::class], |
||
266 | ['file_json', ['foo.json'], JsonFile::class], |
||
267 | ['file_xml', ['foo.xml'], XmlFile::class], |
||
268 | ['file_yaml', ['foo.yaml'], YamlFile::class], |
||
269 | ['expressions', ['foo' => ['label' => 'foo', 'critical_expression' => 'true']], Expression::class, 'expression_foo'], |
||
270 | ['pdo_connections', ['foo' => ['dsn' => 'my-dsn']], PDOCheck::class, 'pdo_foo'], |
||
271 | ]; |
||
272 | } |
||
273 | |||
274 | protected function getContainerExtensions(): array |
||
275 | { |
||
276 | return [new LiipMonitorExtension()]; |
||
277 | } |
||
278 | } |
||
279 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.