SilentConfigurationUpgradeServiceTest.php 33.6 KB
Newer Older
1
<?php
2

3
declare(strict_types=1);
4
5
6
7
8
9
10
11
12
13
14
15
16
17

/*
 * This file is part of the TYPO3 CMS project.
 *
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * The TYPO3 project - inspiring people to share!
 */

18
19
namespace TYPO3\CMS\Install\Tests\Unit\Service;

20
use PHPUnit\Framework\MockObject\MockObject;
21
use Prophecy\Argument;
22
use Prophecy\PhpUnit\ProphecyTrait;
23
24
25
use TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend;
use TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend;
use TYPO3\CMS\Core\Cache\Frontend\VariableFrontend;
26
use TYPO3\CMS\Core\Configuration\ConfigurationManager;
27
use TYPO3\CMS\Core\Crypto\PasswordHashing\Argon2idPasswordHash;
28
29
use TYPO3\CMS\Core\Crypto\PasswordHashing\Argon2iPasswordHash;
use TYPO3\CMS\Core\Crypto\PasswordHashing\BcryptPasswordHash;
30
use TYPO3\CMS\Core\Package\UnitTestPackageManager;
31
use TYPO3\CMS\Core\Tests\Unit\Utility\AccessibleProxies\ExtensionManagementUtilityAccessibleProxy;
32
use TYPO3\CMS\Core\Utility\Exception\MissingArrayPathException;
33
use TYPO3\CMS\Core\Utility\GeneralUtility;
34
use TYPO3\CMS\Fluid\Core\Cache\FluidTemplateCache;
35
use TYPO3\CMS\Install\Service\Exception\ConfigurationChangedException;
36
use TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService;
37
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
38

39
40
41
/**
 * Test case
 */
42
class SilentConfigurationUpgradeServiceTest extends UnitTestCase
43
{
44
45
    use ProphecyTrait;

46
    /**
47
     * @var ConfigurationManager|MockObject
48
49
50
     */
    protected $configurationManager;

51
    /**
52
     * @var UnitTestPackageManager A backup of unit test package manager
53
54
55
56
57
58
     */
    protected $backupPackageManager;

    /**
     * Set up
     */
59
    protected function setUp(): void
60
61
    {
        $this->backupPackageManager = ExtensionManagementUtilityAccessibleProxy::getPackageManager();
62
        parent::setUp();
63
64
65
66
67
    }

    /**
     * Tear down
     */
68
    protected function tearDown(): void
69
70
71
72
73
    {
        ExtensionManagementUtilityAccessibleProxy::setPackageManager($this->backupPackageManager);
        parent::tearDown();
    }

74
75
76
    /**
     * @param array $methods
     */
77
    protected function createConfigurationManagerWithMockedMethods(array $methods): void
78
    {
79
        $this->configurationManager = $this->getMockBuilder(ConfigurationManager::class)
80
            ->onlyMethods($methods)
81
            ->getMock();
82
83
84
85
86
    }

    /**
     * @test
     */
87
    public function removeObsoleteLocalConfigurationSettingsIfThereAreOldSettings(): void
88
89
90
    {
        $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
            SilentConfigurationUpgradeService::class,
91
92
            ['dummy'],
            [],
93
94
95
96
            '',
            false
        );

97
        $obsoleteLocalConfigurationSettings = [
98
            'SYS/form_enctype',
99
        ];
100

101
        $currentLocalConfiguration = [
102
            [$obsoleteLocalConfigurationSettings, true],
103
        ];
104
        $this->createConfigurationManagerWithMockedMethods(
105
            [
106
                'removeLocalConfigurationKeysByPath',
107
            ]
108
        );
109
        $this->configurationManager->expects(self::once())
110
            ->method('removeLocalConfigurationKeysByPath')
111
            ->willReturnMap($currentLocalConfiguration);
112

113
        $this->expectException(ConfigurationChangedException::class);
114
115
116
117
118
119
120
121
122
123

        $silentConfigurationUpgradeServiceInstance->_set('obsoleteLocalConfigurationSettings', $obsoleteLocalConfigurationSettings);
        $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);

        $silentConfigurationUpgradeServiceInstance->_call('removeObsoleteLocalConfigurationSettings');
    }

    /**
     * @test
     */
124
    public function doNotRemoveObsoleteLocalConfigurationSettingsIfThereAreNoOldSettings(): void
125
126
127
    {
        $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
            SilentConfigurationUpgradeService::class,
128
129
            ['dummy'],
            [],
130
131
132
133
            '',
            false
        );

134
        $obsoleteLocalConfigurationSettings = [
135
            'SYS/form_enctype',
136
        ];
137

138
        $currentLocalConfiguration = [
139
            [$obsoleteLocalConfigurationSettings, false],
140
        ];
141
        $this->createConfigurationManagerWithMockedMethods(
142
            [
143
                'removeLocalConfigurationKeysByPath',
144
            ]
145
        );
146
        $this->configurationManager->expects(self::once())
147
            ->method('removeLocalConfigurationKeysByPath')
148
            ->willReturnMap($currentLocalConfiguration);
149
150
151
152
153
154
155
156
157
158

        $silentConfigurationUpgradeServiceInstance->_set('obsoleteLocalConfigurationSettings', $obsoleteLocalConfigurationSettings);
        $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);

        $silentConfigurationUpgradeServiceInstance->_call('removeObsoleteLocalConfigurationSettings');
    }

    /**
     * @test
     */
159
    public function doNotGenerateEncryptionKeyIfExists(): void
160
161
162
    {
        $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
            SilentConfigurationUpgradeService::class,
163
164
            ['dummy'],
            [],
165
166
167
168
            '',
            false
        );

169
        $currentLocalConfiguration = [
170
            ['SYS/encryptionKey', 'EnCrYpTiOnKeY'],
171
        ];
172
173

        $this->createConfigurationManagerWithMockedMethods(
174
            [
175
176
                'getLocalConfigurationValueByPath',
                'setLocalConfigurationValueByPath',
177
            ]
178
        );
179
        $this->configurationManager->expects(self::once())
180
            ->method('getLocalConfigurationValueByPath')
181
            ->willReturnMap($currentLocalConfiguration);
182
        $this->configurationManager->expects(self::never())
183
184
185
186
187
188
189
190
191
192
            ->method('setLocalConfigurationValueByPath');

        $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);

        $silentConfigurationUpgradeServiceInstance->_call('generateEncryptionKeyIfNeeded');
    }

    /**
     * @test
     */
193
    public function generateEncryptionKeyIfNotExists(): void
194
195
196
    {
        $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
            SilentConfigurationUpgradeService::class,
197
198
            ['dummy'],
            [],
199
200
201
202
            '',
            false
        );

203
        $closure = static function () {
204
            throw new MissingArrayPathException('Path does not exist in array', 1476109266);
205
206
207
        };

        $this->createConfigurationManagerWithMockedMethods(
208
            [
209
210
                'getLocalConfigurationValueByPath',
                'setLocalConfigurationValueByPath',
211
            ]
212
        );
213
        $this->configurationManager->expects(self::once())
214
            ->method('getLocalConfigurationValueByPath')
215
            ->willReturnCallback($closure);
216
        $this->configurationManager->expects(self::once())
217
            ->method('setLocalConfigurationValueByPath')
218
            ->with(self::equalTo('SYS/encryptionKey'), self::isType('string'));
219

220
        $this->expectException(ConfigurationChangedException::class);
221
222
223
224
225
226
227

        $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);

        $silentConfigurationUpgradeServiceInstance->_call('generateEncryptionKeyIfNeeded');
    }

    /**
228
     * Data provider for transferHttpSettings
229
230
231
     *
     * @return array
     */
232
    public function httpSettingsMappingDataProvider(): array
233
    {
234
235
236
237
        return [
            'No changes overridden in Local Configuration' => [
                ['timeout' => 100],
                ['HTTP/timeout' => 100],
238
                false,
239
240
241
242
            ],
            'Old and unused settings removed' => [
                ['adapter' => 'curl'],
                [],
243
                true,
244
245
246
247
            ],
            'Old and used settings changed' => [
                ['protocol_version' => '1.1'],
                ['HTTP/version' => '1.1'],
248
                true,
249
250
251
252
253
254
            ],

            /** redirect options */
            'Redirects moved to default' => [
                ['follow_redirects' => true],
                [],
255
                true,
256
257
258
259
            ],
            'Redirects moved #1' => [
                ['follow_redirects' => true, 'max_redirects' => 200, 'strict_redirects' => false],
                ['HTTP/allow_redirects' => ['max' => 200]],
260
                true,
261
262
263
264
            ],
            'Redirects moved #2' => [
                ['follow_redirects' => false, 'max_redirects' => 200, 'strict_redirects' => false],
                ['HTTP/allow_redirects' => false],
265
                true,
266
267
268
269
            ],
            'Redirects moved #3' => [
                ['follow_redirects' => true, 'max_redirects' => 400, 'strict_redirects' => 1],
                ['HTTP/allow_redirects' => ['max' => 400, 'strict' => true]],
270
                true,
271
272
273
274
275
276
            ],

            /** Proxy settings */
            'Proxy host set' => [
                ['proxy_host' => 'vpn.myproxy.com'],
                ['HTTP/proxy' => 'http://vpn.myproxy.com'],
277
                true,
278
279
280
281
            ],
            'Proxy host set + port' => [
                ['proxy_host' => 'vpn.myproxy.com', 'proxy_port' => 8080],
                ['HTTP/proxy' => 'http://vpn.myproxy.com:8080'],
282
                true,
283
284
285
286
            ],
            'Proxy host set + port + verification' => [
                ['proxy_host' => 'vpn.myproxy.com', 'proxy_port' => 8080, 'proxy_auth_scheme' => 'basic', 'proxy_user' => 'myuser', 'proxy_password' => 'mysecret'],
                ['HTTP/proxy' => 'http://myuser:mysecret@vpn.myproxy.com:8080'],
287
                true,
288
289
290
291
292
293
            ],

            /** SSL verification */
            'Only ssl_capath set, invalid migration' => [
                ['ssl_capath' => '/foo/bar/'],
                [],
294
                true,
295
296
297
298
            ],
            'Verification activated, but only ssl_capath set, using default' => [
                ['ssl_verify_peer' => 1, 'ssl_capath' => '/foo/bar/'],
                [],
299
                true,
300
301
302
303
            ],
            'Verification activated, with ssl_capath and ssl_cafile set' => [
                ['ssl_verify_peer' => 1, 'ssl_capath' => '/foo/bar/', 'ssl_cafile' => 'supersecret.crt'],
                ['HTTP/verify' => '/foo/bar/supersecret.crt'],
304
                true,
305
306
307
308
309
310
            ],

            /** SSL key + passphrase */
            'SSL key certification' => [
                ['ssl_local_cert' => '/foo/bar/supersecret.key'],
                ['HTTP/ssl_key' => '/foo/bar/supersecret.key'],
311
                true,
312
313
314
315
            ],
            'SSL key certification + passphrase' => [
                ['ssl_local_cert' => '/foo/bar/supersecret.key', 'ssl_passphrase' => 'donotcopypasteme'],
                ['HTTP/ssl_key' => ['/foo/bar/supersecret.key', 'donotcopypasteme']],
316
                true,
317
318
319
320
            ],
            'SSL key passphrase only - no migration' => [
                ['ssl_passphrase' => 'donotcopypasteme'],
                [],
321
                true,
322
323
            ],
        ];
324
325
326
327
    }

    /**
     * @test
328
329
330
331
     * @dataProvider httpSettingsMappingDataProvider
     * @param array $currentLocalConfiguration
     * @param array $newSettings
     * @param bool $localConfigurationNeedsUpdate
332
     */
333
    public function transferHttpSettingsIfSet(array $currentLocalConfiguration, array $newSettings, bool $localConfigurationNeedsUpdate): void
334
335
336
    {
        $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
            SilentConfigurationUpgradeService::class,
337
338
            ['dummy'],
            [],
339
340
341
342
343
            '',
            false
        );

        $this->createConfigurationManagerWithMockedMethods(
344
            [
345
346
                'setLocalConfigurationValuesByPathValuePairs',
                'removeLocalConfigurationKeysByPath',
347
                'getLocalConfiguration',
348
            ]
349
350
        );

351
        $this->configurationManager
352
353
354
355
            ->method('getLocalConfiguration')
            ->willReturn(['HTTP' => $currentLocalConfiguration]);
        if ($localConfigurationNeedsUpdate) {
            if (!empty($newSettings)) {
356
                $this->configurationManager->expects(self::once())
357
358
359
                    ->method('setLocalConfigurationValuesByPathValuePairs')
                    ->with($newSettings);
            }
360
            $this->configurationManager->expects(self::atMost(1))->method('removeLocalConfigurationKeysByPath');
361
        }
362

363
        if ($localConfigurationNeedsUpdate) {
364
            $this->expectException(ConfigurationChangedException::class);
365
        }
366
367
368

        $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);

369
        $silentConfigurationUpgradeServiceInstance->_call('transferHttpSettings');
370
371
372
373
374
    }

    /**
     * @test
     */
375
    public function disableImageMagickDetailSettingsIfImageMagickIsDisabled(): void
376
377
378
    {
        $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
            SilentConfigurationUpgradeService::class,
379
380
            ['dummy'],
            [],
381
382
383
384
            '',
            false
        );

385
386
387
388
        $currentLocalConfiguration = [
            ['GFX/im', 0],
            ['GFX/im_path', ''],
            ['GFX/imagefile_ext', 'gif,jpg,png'],
389
            ['GFX/thumbnails', 0],
390
        ];
391
        $this->createConfigurationManagerWithMockedMethods(
392
            [
393
394
395
                'getLocalConfigurationValueByPath',
                'getDefaultConfigurationValueByPath',
                'setLocalConfigurationValuesByPathValuePairs',
396
            ]
397
        );
398
        $this->configurationManager->expects(self::exactly(4))
399
            ->method('getLocalConfigurationValueByPath')
400
            ->willReturnMap($currentLocalConfiguration);
401
        $this->configurationManager->expects(self::never())
402
            ->method('getDefaultConfigurationValueByPath');
403
        $this->configurationManager->expects(self::once())
404
405
            ->method('setLocalConfigurationValuesByPathValuePairs')
            ->withConsecutive(
406
                [['GFX/imagefile_ext' => 'gif,jpg,jpeg,png']]
407
408
            );

409
        $this->expectException(ConfigurationChangedException::class);
410
411
412
413
414
415
416
417
418

        $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);

        $silentConfigurationUpgradeServiceInstance->_call('disableImageMagickDetailSettingsIfImageMagickIsDisabled');
    }

    /**
     * @test
     */
419
    public function doNotDisableImageMagickDetailSettingsIfImageMagickIsEnabled(): void
420
421
422
    {
        $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
            SilentConfigurationUpgradeService::class,
423
424
            ['dummy'],
            [],
425
426
427
428
            '',
            false
        );

429
430
431
432
        $currentLocalConfiguration = [
            ['GFX/im', 1],
            ['GFX/im_path', ''],
            ['GFX/imagefile_ext', 'gif,jpg,jpeg,png'],
433
            ['GFX/thumbnails', 0],
434
        ];
435
        $this->createConfigurationManagerWithMockedMethods(
436
            [
437
438
439
                'getLocalConfigurationValueByPath',
                'getDefaultConfigurationValueByPath',
                'setLocalConfigurationValuesByPathValuePairs',
440
            ]
441
        );
442
        $this->configurationManager->expects(self::exactly(4))
443
            ->method('getLocalConfigurationValueByPath')
444
            ->willReturnMap($currentLocalConfiguration);
445
        $this->configurationManager->expects(self::never())
446
            ->method('getDefaultConfigurationValueByPath');
447
        $this->configurationManager->expects(self::never())
448
449
450
451
452
453
454
455
456
457
            ->method('setLocalConfigurationValuesByPathValuePairs');

        $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);

        $silentConfigurationUpgradeServiceInstance->_call('disableImageMagickDetailSettingsIfImageMagickIsDisabled');
    }

    /**
     * @test
     */
458
    public function setImageMagickDetailSettings(): void
459
460
461
    {
        $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
            SilentConfigurationUpgradeService::class,
462
463
            ['dummy'],
            [],
464
465
466
467
            '',
            false
        );

468
469
470
        $currentLocalConfiguration = [
            ['GFX/processor', 'GraphicsMagick'],
            ['GFX/processor_allowTemporaryMasksAsPng', 1],
471
            ['GFX/processor_effects', false],
472
        ];
473
        $this->createConfigurationManagerWithMockedMethods(
474
            [
475
476
477
                'getLocalConfigurationValueByPath',
                'getDefaultConfigurationValueByPath',
                'setLocalConfigurationValuesByPathValuePairs',
478
            ]
479
        );
480
        $this->configurationManager->expects(self::exactly(3))
481
            ->method('getLocalConfigurationValueByPath')
482
            ->willReturnMap($currentLocalConfiguration);
483
        $this->configurationManager->expects(self::never())
484
            ->method('getDefaultConfigurationValueByPath');
485
        $this->configurationManager->expects(self::once())
486
            ->method('setLocalConfigurationValuesByPathValuePairs')
487
488
489
            ->withConsecutive([
                [
                    'GFX/processor_allowTemporaryMasksAsPng' => 0,
490
                ],
491
            ]);
492

493
        $this->expectException(ConfigurationChangedException::class);
494
495
496
497
498
499
500
501
502

        $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);

        $silentConfigurationUpgradeServiceInstance->_call('setImageMagickDetailSettings');
    }

    /**
     * @test
     */
503
    public function doNotSetImageMagickDetailSettings(): void
504
505
506
    {
        $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
            SilentConfigurationUpgradeService::class,
507
508
            ['dummy'],
            [],
509
510
511
512
            '',
            false
        );

513
514
515
        $currentLocalConfiguration = [
            ['GFX/processor', ''],
            ['GFX/processor_allowTemporaryMasksAsPng', 0],
516
            ['GFX/processor_effects', 0],
517
        ];
518
        $this->createConfigurationManagerWithMockedMethods(
519
            [
520
521
522
                'getLocalConfigurationValueByPath',
                'getDefaultConfigurationValueByPath',
                'setLocalConfigurationValuesByPathValuePairs',
523
            ]
524
        );
525
        $this->configurationManager->expects(self::exactly(3))
526
            ->method('getLocalConfigurationValueByPath')
527
            ->willReturnMap($currentLocalConfiguration);
528
        $this->configurationManager->expects(self::never())
529
            ->method('getDefaultConfigurationValueByPath');
530
        $this->configurationManager->expects(self::never())
531
532
533
534
535
536
            ->method('setLocalConfigurationValuesByPathValuePairs');

        $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);

        $silentConfigurationUpgradeServiceInstance->_call('setImageMagickDetailSettings');
    }
537

538
539
540
541
542
543
544
    /**
     * @test
     * @dataProvider graphicsProcessorEffects
     *
     * @param mixed $currentValue
     * @param bool $expectedMigratedValue
     */
545
    public function migratesGraphicsProcessorEffects($currentValue, bool $expectedMigratedValue): void
546
547
548
549
550
551
552
553
554
555
556
557
    {
        $configurationManager = $this->prophesize(ConfigurationManager::class);
        $configurationManager->getLocalConfigurationValueByPath('GFX/processor')->willReturn('GraphicsMagick');
        $configurationManager->getLocalConfigurationValueByPath('GFX/processor_allowTemporaryMasksAsPng')->willReturn(false);
        $configurationManager->getLocalConfigurationValueByPath('GFX/processor_effects')->willReturn($currentValue);
        $configurationManager->setLocalConfigurationValuesByPathValuePairs([
            'GFX/processor_effects' => $expectedMigratedValue,
        ])->shouldBeCalled();

        $this->expectException(ConfigurationChangedException::class);

        $silentConfigurationUpgradeService = new SilentConfigurationUpgradeService($configurationManager->reveal());
558
559
560
561
        // Call protected method
        \Closure::bind(function () {
            return $this->setImageMagickDetailSettings();
        }, $silentConfigurationUpgradeService, SilentConfigurationUpgradeService::class)();
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
    }

    /**
     * @return array
     */
    public function graphicsProcessorEffects(): array
    {
        return [
            'integer 1' => [
                1,
                true,
            ],
            'integer 0' => [
                0,
                false,
            ],
            'integer -1' => [
                -1,
                false,
            ],
            'string "1"' => [
                '1',
                true,
            ],
            'string "0"' => [
                '0',
                false,
            ],
            'string "-1"' => [
                '-1',
                false,
            ],
        ];
    }

597
598
599
    /**
     * @test
     */
600
    public function migrateNonExistingLangDebug(): void
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
    {
        $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
            SilentConfigurationUpgradeService::class,
            ['dummy'],
            [],
            '',
            false
        );

        $currentLocalConfiguration = [
        ];
        $this->createConfigurationManagerWithMockedMethods(
            [
                'getLocalConfigurationValueByPath',
                'setLocalConfigurationValueByPath',
            ]
        );

619
        $this->configurationManager->expects(self::once())
620
            ->method('getLocalConfigurationValueByPath')
621
            ->willReturnMap($currentLocalConfiguration);
622
        $this->configurationManager->expects(self::never())
623
624
625
626
627
628
629
630
631
632
            ->method('setLocalConfigurationValueByPath');

        $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);

        $silentConfigurationUpgradeServiceInstance->_call('migrateLangDebug');
    }

    /**
     * @test
     */
633
    public function migrateExistingLangDebug(): void
634
635
636
637
638
639
640
641
642
643
    {
        $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
            SilentConfigurationUpgradeService::class,
            ['dummy'],
            [],
            '',
            false
        );

        $currentLocalConfiguration = [
644
            ['BE/lang/debug', false],
645
646
647
648
649
650
651
652
        ];
        $this->createConfigurationManagerWithMockedMethods(
            [
                'getLocalConfigurationValueByPath',
                'setLocalConfigurationValueByPath',
            ]
        );

653
        $this->configurationManager->expects(self::once())
654
            ->method('getLocalConfigurationValueByPath')
655
            ->willReturnMap($currentLocalConfiguration);
656
        $this->configurationManager->expects(self::once())
657
            ->method('setLocalConfigurationValueByPath')
658
            ->with(self::equalTo('BE/languageDebug'), false);
659

660
661
        $this->expectException(ConfigurationChangedException::class);
        $this->expectExceptionCode(1379024938);
662

663
        $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $this->configurationManager);
664
665
        $silentConfigurationUpgradeServiceInstance->_call('migrateLangDebug');
    }
666
667
668
669

    /**
     * @test
     */
670
    public function migrateCacheHashOptions(): void
671
    {
672
673
674
675
        $oldConfig = [
            'FE/cHashOnlyForParameters' => 'foo,bar',
            'FE/cHashExcludedParameters' => 'bar,foo',
            'FE/cHashRequiredParameters' => 'bar,baz',
676
            'FE/cHashExcludedParametersIfEmpty' => '*',
677
678
        ];

679
680
        $configurationManager = $this->prophesize(ConfigurationManager::class);

681
        foreach ($oldConfig as $key => $value) {
682
683
684
685
686
            $configurationManager->getLocalConfigurationValueByPath($key)
                ->shouldBeCalled()
                ->willReturn($value);
        }

687
688
        $configurationManager->setLocalConfigurationValuesByPathValuePairs(Argument::cetera())->shouldBeCalled();
        $configurationManager->removeLocalConfigurationKeysByPath(Argument::cetera())->shouldBeCalled();
689

690
        $this->expectException(ConfigurationChangedException::class);
691
        $this->expectExceptionCode(1379024938);
692
693
694
695
696
697
698
699
700
701
702
703

        $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
            SilentConfigurationUpgradeService::class,
            ['dummy'],
            [],
            '',
            false
        );

        $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $configurationManager->reveal());
        $silentConfigurationUpgradeServiceInstance->_call('migrateCacheHashOptions');
    }
704
705
706
707

    /**
     * @test
     */
708
    public function migrateSaltedPasswordsSettingsDoesNothingIfExtensionConfigsAreNotSet(): void
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
    {
        $configurationManagerProphecy = $this->prophesize(ConfigurationManager::class);
        $configurationManagerException = new MissingArrayPathException('Path does not exist in array', 1533989414);
        $configurationManagerProphecy->getLocalConfigurationValueByPath('EXTENSIONS/saltedpasswords')
            ->shouldBeCalled()->willThrow($configurationManagerException);
        $configurationManagerProphecy->setLocalConfigurationValuesByPathValuePairs(Argument::cetera())
            ->shouldNotBeCalled();
        $silentConfigurationUpgradeService = $this->getAccessibleMock(
            SilentConfigurationUpgradeService::class,
            ['dummy'],
            [$configurationManagerProphecy->reveal()]
        );
        $silentConfigurationUpgradeService->_call('migrateSaltedPasswordsSettings');
    }

    /**
     * @test
     */
727
    public function migrateSaltedPasswordsSettingsDoesNothingIfExtensionConfigsAreEmpty(): void
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
    {
        $configurationManagerProphecy = $this->prophesize(ConfigurationManager::class);
        $configurationManagerProphecy->getLocalConfigurationValueByPath('EXTENSIONS/saltedpasswords')
            ->shouldBeCalled()->willReturn([]);
        $configurationManagerProphecy->setLocalConfigurationValuesByPathValuePairs(Argument::cetera())
            ->shouldNotBeCalled();
        $silentConfigurationUpgradeService = $this->getAccessibleMock(
            SilentConfigurationUpgradeService::class,
            ['dummy'],
            [$configurationManagerProphecy->reveal()]
        );
        $silentConfigurationUpgradeService->_call('migrateSaltedPasswordsSettings');
    }

    /**
     * @test
     */
745
    public function migrateSaltedPasswordsSettingsRemovesExtensionsConfigAndSetsNothingElseIfArgon2iIsAvailable(): void
746
747
748
749
    {
        $configurationManagerProphecy = $this->prophesize(ConfigurationManager::class);
        $configurationManagerProphecy->getLocalConfigurationValueByPath('EXTENSIONS/saltedpasswords')
            ->shouldBeCalled()->willReturn(['thereIs' => 'something']);
750
        $argonBeProphecy = $this->prophesize(Argon2iPasswordHash::class);
751
        $argonBeProphecy->isAvailable()->shouldBeCalled()->willReturn(true);
752
753
        GeneralUtility::addInstance(Argon2iPasswordHash::class, $argonBeProphecy->reveal());
        $argonFeProphecy = $this->prophesize(Argon2iPasswordHash::class);
754
        $argonFeProphecy->isAvailable()->shouldBeCalled()->willReturn(true);
755
        GeneralUtility::addInstance(Argon2iPasswordHash::class, $argonFeProphecy->reveal());
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
        $configurationManagerProphecy->removeLocalConfigurationKeysByPath(['EXTENSIONS/saltedpasswords'])
            ->shouldBeCalled();
        $silentConfigurationUpgradeService = $this->getAccessibleMock(
            SilentConfigurationUpgradeService::class,
            ['dummy'],
            [$configurationManagerProphecy->reveal()]
        );
        $this->expectException(ConfigurationChangedException::class);
        $this->expectExceptionCode(1379024938);
        $silentConfigurationUpgradeService->_call('migrateSaltedPasswordsSettings');
    }

    /**
     * @test
     */
771
    public function migrateSaltedPasswordsSetsSpecificHashMethodIfArgon2idAndArgon2iIsNotAvailable(): void
772
773
774
775
    {
        $configurationManagerProphecy = $this->prophesize(ConfigurationManager::class);
        $configurationManagerProphecy->getLocalConfigurationValueByPath('EXTENSIONS/saltedpasswords')
            ->shouldBeCalled()->willReturn(['thereIs' => 'something']);
776
777
778
        $argon2idBeProphecy = $this->prophesize(Argon2idPasswordHash::class);
        $argon2idBeProphecy->isAvailable()->shouldBeCalled()->willReturn(false);
        GeneralUtility::addInstance(Argon2idPasswordHash::class, $argon2idBeProphecy->reveal());
779
        $argonBeProphecy = $this->prophesize(Argon2iPasswordHash::class);
780
        $argonBeProphecy->isAvailable()->shouldBeCalled()->willReturn(false);
781
782
        GeneralUtility::addInstance(Argon2iPasswordHash::class, $argonBeProphecy->reveal());
        $bcryptBeProphecy = $this->prophesize(BcryptPasswordHash::class);
783
        $bcryptBeProphecy->isAvailable()->shouldBeCalled()->willReturn(true);
784
        GeneralUtility::addInstance(BcryptPasswordHash::class, $bcryptBeProphecy->reveal());
785
786
787
        $argon2idFeProphecy = $this->prophesize(Argon2idPasswordHash::class);
        $argon2idFeProphecy->isAvailable()->shouldBeCalled()->willReturn(false);
        GeneralUtility::addInstance(Argon2idPasswordHash::class, $argon2idFeProphecy->reveal());
788
        $argonFeProphecy = $this->prophesize(Argon2iPasswordHash::class);
789
        $argonFeProphecy->isAvailable()->shouldBeCalled()->willReturn(false);
790
791
        GeneralUtility::addInstance(Argon2iPasswordHash::class, $argonFeProphecy->reveal());
        $bcryptFeProphecy = $this->prophesize(BcryptPasswordHash::class);
792
        $bcryptFeProphecy->isAvailable()->shouldBeCalled()->willReturn(true);
793
        GeneralUtility::addInstance(BcryptPasswordHash::class, $bcryptFeProphecy->reveal());
794
        $configurationManagerProphecy->setLocalConfigurationValuesByPathValuePairs([
795
796
            'BE/passwordHashing/className' => BcryptPasswordHash::class,
            'FE/passwordHashing/className' => BcryptPasswordHash::class,
797
        ])->shouldBeCalled();
798
        $configurationManagerProphecy->removeLocalConfigurationKeysByPath(['EXTENSIONS/saltedpasswords'])
799
800
801
802
803
804
805
806
807
808
            ->shouldBeCalled();
        $silentConfigurationUpgradeService = $this->getAccessibleMock(
            SilentConfigurationUpgradeService::class,
            ['dummy'],
            [$configurationManagerProphecy->reveal()]
        );
        $this->expectException(ConfigurationChangedException::class);
        $this->expectExceptionCode(1379024938);
        $silentConfigurationUpgradeService->_call('migrateSaltedPasswordsSettings');
    }
809
810
811
812

    /**
     * @test
     */
813
    public function migrateCachingFrameworkCachesMigratesData(): void
814
815
816
    {
        $oldCacheConfigurations = [
            'cache_rootline' => [
817
818
                'frontend' => VariableFrontend::class,
                'backend' => Typo3DatabaseBackend::class,
819
820
821
                'options' => [
                    'defaultLifetime' => 2592000,
                ],
822
                'groups' => ['pages'],
823
824
            ],
            'fluid_template' => [
825
826
                'backend' => SimpleFileBackend::class,
                'frontend' => FluidTemplateCache::class,
827
828
829
830
831
                'groups' => ['system'],
            ],
        ];
        $newCacheConfigurations = [
            'rootline' => [
832
833
                'frontend' => VariableFrontend::class,
                'backend' => Typo3DatabaseBackend::class,
834
835
836
                'options' => [
                    'defaultLifetime' => 2592000,
                ],
837
                'groups' => ['pages'],
838
839
            ],
            'fluid_template' => [
840
841
                'backend' => SimpleFileBackend::class,
                'frontend' => FluidTemplateCache::class,
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
                'groups' => ['system'],
            ],
        ];
        $configurationManager = $this->prophesize(ConfigurationManager::class);
        $configurationManager->getLocalConfigurationValueByPath('SYS/caching/cacheConfigurations')
            ->shouldBeCalled()
            ->willReturn($oldCacheConfigurations);

        $configurationManager->setLocalConfigurationValueByPath('SYS/caching/cacheConfigurations', $newCacheConfigurations)->shouldBeCalled();

        $this->expectException(ConfigurationChangedException::class);
        $this->expectExceptionCode(1379024938);

        $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
            SilentConfigurationUpgradeService::class,
            ['dummy'],
            [],
            '',
            false
        );

        $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $configurationManager->reveal());
        $silentConfigurationUpgradeServiceInstance->_call('migrateCachingFrameworkCaches');
    }

    /**
     * @test
     */
870
    public function migrateCachingFrameworkCachesDoesNotMigrateWithoutPrefix(): void
871
872
873
    {
        $oldCacheConfigurations = [
            'rootline' => [
874
875
                'frontend' => VariableFrontend::class,
                'backend' => Typo3DatabaseBackend::class,
876
877
878
                'options' => [
                    'defaultLifetime' => 2592000,
                ],
879
                'groups' => ['pages'],
880
881
            ],
            'fluid_template' => [
882
883
                'backend' => SimpleFileBackend::class,
                'frontend' => FluidTemplateCache::class,
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
                'groups' => ['system'],
            ],
        ];
        $configurationManager = $this->prophesize(ConfigurationManager::class);
        $configurationManager->getLocalConfigurationValueByPath('SYS/caching/cacheConfigurations')
            ->shouldBeCalled()
            ->willReturn($oldCacheConfigurations);

        $configurationManager->setLocalConfigurationValueByPath(Argument::cetera())->shouldNotBeCalled();

        $silentConfigurationUpgradeServiceInstance = $this->getAccessibleMock(
            SilentConfigurationUpgradeService::class,
            ['dummy'],
            [],
            '',
            false
        );

        $silentConfigurationUpgradeServiceInstance->_set('configurationManager', $configurationManager->reveal());
        $silentConfigurationUpgradeServiceInstance->_call('migrateCachingFrameworkCaches');
    }
905
}