TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
SilentConfigurationUpgradeServiceTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Install\Service;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
22 
27 {
32 
37 
41  protected function setUp()
42  {
44  }
45 
49  protected function tearDown()
50  {
52  parent::tearDown();
53  }
54 
58  protected function createConfigurationManagerWithMockedMethods(array $methods)
59  {
60  $this->configurationManager = $this->getMockBuilder(ConfigurationManager::class)
61  ->setMethods($methods)
62  ->getMock();
63  }
64 
71  {
72  return [
73  ['', 'rsa', true, false],
74  ['normal', 'rsa', true, true],
75  ['rsa', 'normal', false, true],
76  ];
77  }
78 
87  public function configureBackendLoginSecurity($current, $setting, $isPackageActive, $hasLocalConfig)
88  {
90  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
91  SilentConfigurationUpgradeService::class,
92  ['dummy'],
93  [],
94  '',
95  false
96  );
97 
99  $packageManager = $this->createMock(PackageManager::class);
100  $packageManager->expects($this->any())
101  ->method('isPackageActive')
102  ->will($this->returnValue($isPackageActive));
104 
105  $currentLocalConfiguration = [
106  ['BE/loginSecurityLevel', $current]
107  ];
108  $closure = function () {
109  throw new \RuntimeException('Path does not exist in array', 1476109311);
110  };
111 
113  [
114  'getLocalConfigurationValueByPath',
115  'setLocalConfigurationValueByPath',
116  ]
117  );
118  if ($hasLocalConfig) {
119  $this->configurationManager->expects($this->once())
120  ->method('getLocalConfigurationValueByPath')
121  ->will($this->returnValueMap($currentLocalConfiguration));
122  } else {
123  $this->configurationManager->expects($this->once())
124  ->method('getLocalConfigurationValueByPath')
125  ->will($this->returnCallback($closure));
126  }
127  $this->configurationManager->expects($this->once())
128  ->method('setLocalConfigurationValueByPath')
129  ->with($this->equalTo('BE/loginSecurityLevel'), $this->equalTo($setting));
130 
131  $this->expectException(RedirectException::class);
132 
133  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
134 
135  $silentConfigurationUpgradeServiceInstance->_call('configureBackendLoginSecurity');
136  }
137 
141  public function removeObsoleteLocalConfigurationSettingsIfThereAreOldSettings()
142  {
144  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
145  SilentConfigurationUpgradeService::class,
146  ['dummy'],
147  [],
148  '',
149  false
150  );
151 
152  $obsoleteLocalConfigurationSettings = [
153  'SYS/form_enctype',
154  ];
155 
156  $currentLocalConfiguration = [
157  [$obsoleteLocalConfigurationSettings, true]
158  ];
160  [
161  'removeLocalConfigurationKeysByPath',
162  ]
163  );
164  $this->configurationManager->expects($this->exactly(1))
165  ->method('removeLocalConfigurationKeysByPath')
166  ->will($this->returnValueMap($currentLocalConfiguration));
167 
168  $this->expectException(RedirectException::class);
169 
170  $silentConfigurationUpgradeServiceInstance->_set('obsoleteLocalConfigurationSettings', $obsoleteLocalConfigurationSettings);
171  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
172 
173  $silentConfigurationUpgradeServiceInstance->_call('removeObsoleteLocalConfigurationSettings');
174  }
175 
179  public function doNotRemoveObsoleteLocalConfigurationSettingsIfThereAreNoOldSettings()
180  {
182  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
183  SilentConfigurationUpgradeService::class,
184  ['dummy'],
185  [],
186  '',
187  false
188  );
189 
190  $obsoleteLocalConfigurationSettings = [
191  'SYS/form_enctype',
192  ];
193 
194  $currentLocalConfiguration = [
195  [$obsoleteLocalConfigurationSettings, false]
196  ];
198  [
199  'removeLocalConfigurationKeysByPath',
200  ]
201  );
202  $this->configurationManager->expects($this->exactly(1))
203  ->method('removeLocalConfigurationKeysByPath')
204  ->will($this->returnValueMap($currentLocalConfiguration));
205 
206  $silentConfigurationUpgradeServiceInstance->_set('obsoleteLocalConfigurationSettings', $obsoleteLocalConfigurationSettings);
207  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
208 
209  $silentConfigurationUpgradeServiceInstance->_call('removeObsoleteLocalConfigurationSettings');
210  }
211 
215  public function doNotGenerateEncryptionKeyIfExists()
216  {
218  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
219  SilentConfigurationUpgradeService::class,
220  ['dummy'],
221  [],
222  '',
223  false
224  );
225 
226  $currentLocalConfiguration = [
227  ['SYS/encryptionKey', 'EnCrYpTiOnKeY']
228  ];
229 
231  [
232  'getLocalConfigurationValueByPath',
233  'setLocalConfigurationValueByPath',
234  ]
235  );
236  $this->configurationManager->expects($this->exactly(1))
237  ->method('getLocalConfigurationValueByPath')
238  ->will($this->returnValueMap($currentLocalConfiguration));
239  $this->configurationManager->expects($this->never())
240  ->method('setLocalConfigurationValueByPath');
241 
242  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
243 
244  $silentConfigurationUpgradeServiceInstance->_call('generateEncryptionKeyIfNeeded');
245  }
246 
250  public function generateEncryptionKeyIfNotExists()
251  {
253  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
254  SilentConfigurationUpgradeService::class,
255  ['dummy'],
256  [],
257  '',
258  false
259  );
260 
261  $closure = function () {
262  throw new \RuntimeException('Path does not exist in array', 1476109266);
263  };
264 
266  [
267  'getLocalConfigurationValueByPath',
268  'setLocalConfigurationValueByPath',
269  ]
270  );
271  $this->configurationManager->expects($this->exactly(1))
272  ->method('getLocalConfigurationValueByPath')
273  ->will($this->returnCallback($closure));
274  $this->configurationManager->expects($this->once())
275  ->method('setLocalConfigurationValueByPath')
276  ->with($this->equalTo('SYS/encryptionKey'), $this->isType('string'));
277 
278  $this->expectException(RedirectException::class);
279 
280  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
281 
282  $silentConfigurationUpgradeServiceInstance->_call('generateEncryptionKeyIfNeeded');
283  }
284 
291  {
292  return [
293  'No changes overridden in Local Configuration' => [
294  ['timeout' => 100],
295  ['HTTP/timeout' => 100],
296  false
297  ],
298  'Old and unused settings removed' => [
299  ['adapter' => 'curl'],
300  [],
301  true
302  ],
303  'Old and used settings changed' => [
304  ['protocol_version' => '1.1'],
305  ['HTTP/version' => '1.1'],
306  true
307  ],
308 
310  'Redirects moved to default' => [
311  ['follow_redirects' => true],
312  [],
313  true
314  ],
315  'Redirects moved #1' => [
316  ['follow_redirects' => true, 'max_redirects' => 200, 'strict_redirects' => false],
317  ['HTTP/allow_redirects' => ['max' => 200]],
318  true
319  ],
320  'Redirects moved #2' => [
321  ['follow_redirects' => false, 'max_redirects' => 200, 'strict_redirects' => false],
322  ['HTTP/allow_redirects' => false],
323  true
324  ],
325  'Redirects moved #3' => [
326  ['follow_redirects' => true, 'max_redirects' => 400, 'strict_redirects' => 1],
327  ['HTTP/allow_redirects' => ['max' => 400, 'strict' => true]],
328  true
329  ],
330 
332  'Proxy host set' => [
333  ['proxy_host' => 'vpn.myproxy.com'],
334  ['HTTP/proxy' => 'http://vpn.myproxy.com'],
335  true
336  ],
337  'Proxy host set + port' => [
338  ['proxy_host' => 'vpn.myproxy.com', 'proxy_port' => 8080],
339  ['HTTP/proxy' => 'http://vpn.myproxy.com:8080'],
340  true
341  ],
342  'Proxy host set + port + verification' => [
343  ['proxy_host' => 'vpn.myproxy.com', 'proxy_port' => 8080, 'proxy_auth_scheme' => 'basic', 'proxy_user' => 'myuser', 'proxy_password' => 'mysecret'],
344  ['HTTP/proxy' => 'http://myuser:mysecret@vpn.myproxy.com:8080'],
345  true
346  ],
347 
349  'Only ssl_capath set, invalid migration' => [
350  ['ssl_capath' => '/foo/bar/'],
351  [],
352  true
353  ],
354  'Verification activated, but only ssl_capath set, using default' => [
355  ['ssl_verify_peer' => 1, 'ssl_capath' => '/foo/bar/'],
356  [],
357  true
358  ],
359  'Verification activated, with ssl_capath and ssl_cafile set' => [
360  ['ssl_verify_peer' => 1, 'ssl_capath' => '/foo/bar/', 'ssl_cafile' => 'supersecret.crt'],
361  ['HTTP/verify' => '/foo/bar/supersecret.crt'],
362  true
363  ],
364 
366  'SSL key certification' => [
367  ['ssl_local_cert' => '/foo/bar/supersecret.key'],
368  ['HTTP/ssl_key' => '/foo/bar/supersecret.key'],
369  true
370  ],
371  'SSL key certification + passphrase' => [
372  ['ssl_local_cert' => '/foo/bar/supersecret.key', 'ssl_passphrase' => 'donotcopypasteme'],
373  ['HTTP/ssl_key' => ['/foo/bar/supersecret.key', 'donotcopypasteme']],
374  true
375  ],
376  'SSL key passphrase only - no migration' => [
377  ['ssl_passphrase' => 'donotcopypasteme'],
378  [],
379  true
380  ],
381  ];
382  }
383 
391  public function transferHttpSettingsIfSet($currentLocalConfiguration, $newSettings, $localConfigurationNeedsUpdate)
392  {
394  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
395  SilentConfigurationUpgradeService::class,
396  ['dummy'],
397  [],
398  '',
399  false
400  );
401 
403  [
404  'setLocalConfigurationValuesByPathValuePairs',
405  'removeLocalConfigurationKeysByPath',
406  'getLocalConfiguration'
407  ]
408  );
409 
410  $this->configurationManager->expects($this->any())
411  ->method('getLocalConfiguration')
412  ->willReturn(['HTTP' => $currentLocalConfiguration]);
413  if ($localConfigurationNeedsUpdate) {
414  if (!empty($newSettings)) {
415  $this->configurationManager->expects($this->once())
416  ->method('setLocalConfigurationValuesByPathValuePairs')
417  ->with($newSettings);
418  }
419  $this->configurationManager->expects($this->atMost(1))->method('removeLocalConfigurationKeysByPath');
420  }
421 
422  if ($localConfigurationNeedsUpdate) {
423  $this->expectException(RedirectException::class);
424  }
425 
426  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
427 
428  $silentConfigurationUpgradeServiceInstance->_call('transferHttpSettings');
429  }
430 
434  public function disableImageMagickDetailSettingsIfImageMagickIsDisabled()
435  {
437  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
438  SilentConfigurationUpgradeService::class,
439  ['dummy'],
440  [],
441  '',
442  false
443  );
444 
445  $currentLocalConfiguration = [
446  ['GFX/im', 0],
447  ['GFX/im_path', ''],
448  ['GFX/im_path_lzw', ''],
449  ['GFX/imagefile_ext', 'gif,jpg,png'],
450  ['GFX/thumbnails', 0]
451  ];
453  [
454  'getLocalConfigurationValueByPath',
455  'getDefaultConfigurationValueByPath',
456  'setLocalConfigurationValuesByPathValuePairs',
457  ]
458  );
459  $this->configurationManager->expects($this->exactly(5))
460  ->method('getLocalConfigurationValueByPath')
461  ->will($this->returnValueMap($currentLocalConfiguration));
462  $this->configurationManager->expects($this->never())
463  ->method('getDefaultConfigurationValueByPath');
464  $this->configurationManager->expects($this->once())
465  ->method('setLocalConfigurationValuesByPathValuePairs')
466  ->withConsecutive(
467  [['GFX/imagefile_ext' => 'gif,jpg,jpeg,png']]
468  );
469 
470  $this->expectException(RedirectException::class);
471 
472  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
473 
474  $silentConfigurationUpgradeServiceInstance->_call('disableImageMagickDetailSettingsIfImageMagickIsDisabled');
475  }
476 
480  public function doNotDisableImageMagickDetailSettingsIfImageMagickIsEnabled()
481  {
483  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
484  SilentConfigurationUpgradeService::class,
485  ['dummy'],
486  [],
487  '',
488  false
489  );
490 
491  $currentLocalConfiguration = [
492  ['GFX/im', 1],
493  ['GFX/im_path', ''],
494  ['GFX/im_path_lzw', ''],
495  ['GFX/imagefile_ext', 'gif,jpg,jpeg,png'],
496  ['GFX/thumbnails', 0]
497  ];
499  [
500  'getLocalConfigurationValueByPath',
501  'getDefaultConfigurationValueByPath',
502  'setLocalConfigurationValuesByPathValuePairs',
503  ]
504  );
505  $this->configurationManager->expects($this->exactly(5))
506  ->method('getLocalConfigurationValueByPath')
507  ->will($this->returnValueMap($currentLocalConfiguration));
508  $this->configurationManager->expects($this->never())
509  ->method('getDefaultConfigurationValueByPath');
510  $this->configurationManager->expects($this->never())
511  ->method('setLocalConfigurationValuesByPathValuePairs');
512 
513  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
514 
515  $silentConfigurationUpgradeServiceInstance->_call('disableImageMagickDetailSettingsIfImageMagickIsDisabled');
516  }
517 
521  public function setImageMagickDetailSettings()
522  {
524  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
525  SilentConfigurationUpgradeService::class,
526  ['dummy'],
527  [],
528  '',
529  false
530  );
531 
532  $currentLocalConfiguration = [
533  ['GFX/processor', 'GraphicsMagick'],
534  ['GFX/processor_allowTemporaryMasksAsPng', 1],
535  ['GFX/processor_effects', 0]
536  ];
538  [
539  'getLocalConfigurationValueByPath',
540  'getDefaultConfigurationValueByPath',
541  'setLocalConfigurationValuesByPathValuePairs',
542  ]
543  );
544  $this->configurationManager->expects($this->exactly(3))
545  ->method('getLocalConfigurationValueByPath')
546  ->will($this->returnValueMap($currentLocalConfiguration));
547  $this->configurationManager->expects($this->never())
548  ->method('getDefaultConfigurationValueByPath');
549  $this->configurationManager->expects($this->once())
550  ->method('setLocalConfigurationValuesByPathValuePairs')
551  ->withConsecutive(
552  [['GFX/processor_allowTemporaryMasksAsPng' => 0,
553  'GFX/processor_effects' => -1]]
554  );
555 
556  $this->expectException(RedirectException::class);
557 
558  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
559 
560  $silentConfigurationUpgradeServiceInstance->_call('setImageMagickDetailSettings');
561  }
562 
566  public function doNotSetImageMagickDetailSettings()
567  {
569  $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
570  SilentConfigurationUpgradeService::class,
571  ['dummy'],
572  [],
573  '',
574  false
575  );
576 
577  $currentLocalConfiguration = [
578  ['GFX/processor', ''],
579  ['GFX/processor_allowTemporaryMasksAsPng', 0],
580  ['GFX/processor_effects', 0]
581  ];
583  [
584  'getLocalConfigurationValueByPath',
585  'getDefaultConfigurationValueByPath',
586  'setLocalConfigurationValuesByPathValuePairs',
587  ]
588  );
589  $this->configurationManager->expects($this->exactly(3))
590  ->method('getLocalConfigurationValueByPath')
591  ->will($this->returnValueMap($currentLocalConfiguration));
592  $this->configurationManager->expects($this->never())
593  ->method('getDefaultConfigurationValueByPath');
594  $this->configurationManager->expects($this->never())
595  ->method('setLocalConfigurationValuesByPathValuePairs');
596 
597  $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
598 
599  $silentConfigurationUpgradeServiceInstance->_call('setImageMagickDetailSettings');
600  }
601 }
static setPackageManager(PackageManager $packageManager)
getAccessibleMock($originalClassName, $methods=[], array $arguments=[], $mockClassName= '', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)