55
55
use OCP \ITempManager ;
56
56
use OCP \IURLGenerator ;
57
57
use OCP \Lock \ILockingProvider ;
58
+ use OCP \Notification \IManager ;
58
59
use PHPUnit \Framework \MockObject \MockObject ;
59
60
use Psr \Http \Message \ResponseInterface ;
60
61
use Psr \Log \LoggerInterface ;
@@ -102,6 +103,8 @@ class CheckSetupControllerTest extends TestCase {
102
103
private $ connection ;
103
104
/** @var ITempManager|\PHPUnit\Framework\MockObject\MockObject */
104
105
private $ tempManager ;
106
+ /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
107
+ private $ notificationManager ;
105
108
106
109
/**
107
110
* Holds a list of directories created during tests.
@@ -145,6 +148,7 @@ protected function setUp(): void {
145
148
$ this ->connection = $ this ->getMockBuilder (IDBConnection::class)
146
149
->disableOriginalConstructor ()->getMock ();
147
150
$ this ->tempManager = $ this ->getMockBuilder (ITempManager::class)->getMock ();
151
+ $ this ->notificationManager = $ this ->getMockBuilder (IManager::class)->getMock ();
148
152
$ this ->checkSetupController = $ this ->getMockBuilder (CheckSetupController::class)
149
153
->setConstructorArgs ([
150
154
'settings ' ,
@@ -164,6 +168,7 @@ protected function setUp(): void {
164
168
$ this ->iniGetWrapper ,
165
169
$ this ->connection ,
166
170
$ this ->tempManager ,
171
+ $ this ->notificationManager ,
167
172
])
168
173
->setMethods ([
169
174
'isReadOnlyConfig ' ,
@@ -186,7 +191,6 @@ protected function setUp(): void {
186
191
'hasBigIntConversionPendingColumns ' ,
187
192
'isMysqlUsedWithoutUTF8MB4 ' ,
188
193
'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed ' ,
189
- 'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed ' ,
190
194
])->getMock ();
191
195
}
192
196
@@ -342,7 +346,7 @@ public function testIsPhpSupportedTrue() {
342
346
* @param string $remoteAddr
343
347
* @param bool $result
344
348
*/
345
- public function testForwardedForHeadersWorking (array $ trustedProxies , string $ remoteAddrNotForwarded , string $ remoteAddr , bool $ result ) {
349
+ public function testForwardedForHeadersWorking (array $ trustedProxies , string $ remoteAddrNotForwarded , string $ remoteAddr , bool $ result ): void {
346
350
$ this ->config ->expects ($ this ->once ())
347
351
->method ('getSystemValue ' )
348
352
->with ('trusted_proxies ' , [])
@@ -363,7 +367,7 @@ public function testForwardedForHeadersWorking(array $trustedProxies, string $re
363
367
);
364
368
}
365
369
366
- public function dataForwardedForHeadersWorking () {
370
+ public function dataForwardedForHeadersWorking (): array {
367
371
return [
368
372
// description => trusted proxies, getHeader('REMOTE_ADDR'), getRemoteAddr, expected result
369
373
'no trusted proxies ' => [[], '2.2.2.2 ' , '2.2.2.2 ' , true ],
@@ -373,7 +377,28 @@ public function dataForwardedForHeadersWorking() {
373
377
];
374
378
}
375
379
376
- public function testForwardedHostPresentButTrustedProxiesEmpty () {
380
+ public function testForwardedHostPresentButTrustedProxiesNotAnArray (): void {
381
+ $ this ->config ->expects ($ this ->once ())
382
+ ->method ('getSystemValue ' )
383
+ ->with ('trusted_proxies ' , [])
384
+ ->willReturn ('1.1.1.1 ' );
385
+ $ this ->request ->expects ($ this ->atLeastOnce ())
386
+ ->method ('getHeader ' )
387
+ ->willReturnMap ([
388
+ ['REMOTE_ADDR ' , '1.1.1.1 ' ],
389
+ ['X-Forwarded-Host ' , 'nextcloud.test ' ]
390
+ ]);
391
+ $ this ->request ->expects ($ this ->any ())
392
+ ->method ('getRemoteAddress ' )
393
+ ->willReturn ('1.1.1.1 ' );
394
+
395
+ $ this ->assertEquals (
396
+ false ,
397
+ self ::invokePrivate ($ this ->checkSetupController , 'forwardedForHeadersWorking ' )
398
+ );
399
+ }
400
+
401
+ public function testForwardedHostPresentButTrustedProxiesEmpty (): void {
377
402
$ this ->config ->expects ($ this ->once ())
378
403
->method ('getSystemValue ' )
379
404
->with ('trusted_proxies ' , [])
@@ -594,7 +619,7 @@ public function testCheck() {
594
619
'eol ' => true ,
595
620
'version ' => PHP_VERSION
596
621
],
597
- 'forwardedForHeadersWorking ' => true ,
622
+ 'forwardedForHeadersWorking ' => false ,
598
623
'reverseProxyDocs ' => 'reverse-proxy-doc-link ' ,
599
624
'isCorrectMemcachedPHPModuleInstalled ' => true ,
600
625
'hasPassedCodeIntegrityCheck ' => true ,
@@ -623,6 +648,8 @@ public function testCheck() {
623
648
'imageMagickLacksSVGSupport ' => false ,
624
649
'isDefaultPhoneRegionSet ' => false ,
625
650
'OCA\Settings\SetupChecks\SupportedDatabase ' => ['pass ' => true , 'description ' => '' , 'severity ' => 'info ' ],
651
+ 'isFairUseOfFreePushService ' => false ,
652
+ 'temporaryDirectoryWritable ' => false ,
626
653
]
627
654
);
628
655
$ this ->assertEquals ($ expected , $ this ->checkSetupController ->check ());
@@ -647,6 +674,8 @@ public function testGetCurlVersion() {
647
674
$ this ->secureRandom ,
648
675
$ this ->iniGetWrapper ,
649
676
$ this ->connection ,
677
+ $ this ->tempManager ,
678
+ $ this ->notificationManager ,
650
679
])
651
680
->setMethods (null )->getMock ();
652
681
@@ -1401,23 +1430,25 @@ public function testIsMysqlUsedWithoutUTF8MB4(string $db, bool $useUTF8MB4, bool
1401
1430
});
1402
1431
1403
1432
$ checkSetupController = new CheckSetupController (
1404
- 'settings ' ,
1405
- $ this ->request ,
1406
- $ this ->config ,
1407
- $ this ->clientService ,
1408
- $ this ->urlGenerator ,
1409
- $ this ->l10n ,
1410
- $ this ->checker ,
1411
- $ this ->logger ,
1412
- $ this ->dispatcher ,
1413
- $ this ->db ,
1414
- $ this ->lockingProvider ,
1415
- $ this ->dateTimeFormatter ,
1416
- $ this ->memoryInfo ,
1417
- $ this ->secureRandom ,
1418
- $ this ->iniGetWrapper ,
1419
- $ this ->connection
1420
- );
1433
+ 'settings ' ,
1434
+ $ this ->request ,
1435
+ $ this ->config ,
1436
+ $ this ->clientService ,
1437
+ $ this ->urlGenerator ,
1438
+ $ this ->l10n ,
1439
+ $ this ->checker ,
1440
+ $ this ->logger ,
1441
+ $ this ->dispatcher ,
1442
+ $ this ->db ,
1443
+ $ this ->lockingProvider ,
1444
+ $ this ->dateTimeFormatter ,
1445
+ $ this ->memoryInfo ,
1446
+ $ this ->secureRandom ,
1447
+ $ this ->iniGetWrapper ,
1448
+ $ this ->connection ,
1449
+ $ this ->tempManager ,
1450
+ $ this ->notificationManager
1451
+ );
1421
1452
1422
1453
$ this ->assertSame ($ expected , $ this ->invokePrivate ($ checkSetupController , 'isMysqlUsedWithoutUTF8MB4 ' ));
1423
1454
}
@@ -1466,7 +1497,9 @@ public function testIsEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed(string $m
1466
1497
$ this ->memoryInfo ,
1467
1498
$ this ->secureRandom ,
1468
1499
$ this ->iniGetWrapper ,
1469
- $ this ->connection
1500
+ $ this ->connection ,
1501
+ $ this ->tempManager ,
1502
+ $ this ->notificationManager
1470
1503
);
1471
1504
1472
1505
$ this ->assertSame ($ expected , $ this ->invokePrivate ($ checkSetupController , 'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed ' ));
0 commit comments