CheckSetupControllerTest.php 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2015, ownCloud, Inc.
  4. *
  5. * @author Bjoern Schiessle <bjoern@schiessle.org>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author John Molakvoæ <skjnldsv@protonmail.com>
  10. * @author Lukas Reschke <lukas@statuscode.ch>
  11. * @author Michael Weimann <mail@michael-weimann.eu>
  12. * @author Morris Jobke <hey@morrisjobke.de>
  13. * @author nhirokinet <nhirokinet@nhiroki.net>
  14. * @author Robin Appelman <robin@icewind.nl>
  15. * @author Robin McCorkell <robin@mccorkell.me.uk>
  16. * @author Roeland Jago Douma <roeland@famdouma.nl>
  17. * @author Sylvia van Os <sylvia@hackerchick.me>
  18. * @author Timo Förster <tfoerster@webfoersterei.de>
  19. *
  20. * @license AGPL-3.0
  21. *
  22. * This code is free software: you can redistribute it and/or modify
  23. * it under the terms of the GNU Affero General Public License, version 3,
  24. * as published by the Free Software Foundation.
  25. *
  26. * This program is distributed in the hope that it will be useful,
  27. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  28. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  29. * GNU Affero General Public License for more details.
  30. *
  31. * You should have received a copy of the GNU Affero General Public License, version 3,
  32. * along with this program. If not, see <http://www.gnu.org/licenses/>
  33. *
  34. */
  35. namespace OCA\Settings\Tests\Controller;
  36. use bantu\IniGetWrapper\IniGetWrapper;
  37. use Doctrine\DBAL\Platforms\SqlitePlatform;
  38. use OC;
  39. use OC\DB\Connection;
  40. use OC\IntegrityCheck\Checker;
  41. use OC\MemoryInfo;
  42. use OC\Security\SecureRandom;
  43. use OCA\Settings\Controller\CheckSetupController;
  44. use OCP\App\IAppManager;
  45. use OCP\AppFramework\Http;
  46. use OCP\AppFramework\Http\DataDisplayResponse;
  47. use OCP\AppFramework\Http\DataResponse;
  48. use OCP\AppFramework\Http\RedirectResponse;
  49. use OCP\EventDispatcher\IEventDispatcher;
  50. use OCP\Http\Client\IClientService;
  51. use OCP\IConfig;
  52. use OCP\IDateTimeFormatter;
  53. use OCP\IDBConnection;
  54. use OCP\IL10N;
  55. use OCP\IRequest;
  56. use OCP\IServerContainer;
  57. use OCP\ITempManager;
  58. use OCP\IURLGenerator;
  59. use OCP\Lock\ILockingProvider;
  60. use OCP\Notification\IManager;
  61. use OCP\Security\Bruteforce\IThrottler;
  62. use PHPUnit\Framework\MockObject\MockObject;
  63. use Psr\Http\Message\ResponseInterface;
  64. use Psr\Log\LoggerInterface;
  65. use Test\TestCase;
  66. /**
  67. * Class CheckSetupControllerTest
  68. *
  69. * @backupStaticAttributes
  70. * @package Tests\Settings\Controller
  71. */
  72. class CheckSetupControllerTest extends TestCase {
  73. /** @var CheckSetupController | \PHPUnit\Framework\MockObject\MockObject */
  74. private $checkSetupController;
  75. /** @var IRequest | \PHPUnit\Framework\MockObject\MockObject */
  76. private $request;
  77. /** @var IConfig | \PHPUnit\Framework\MockObject\MockObject */
  78. private $config;
  79. /** @var IClientService | \PHPUnit\Framework\MockObject\MockObject*/
  80. private $clientService;
  81. /** @var IURLGenerator | \PHPUnit\Framework\MockObject\MockObject */
  82. private $urlGenerator;
  83. /** @var IL10N | \PHPUnit\Framework\MockObject\MockObject */
  84. private $l10n;
  85. /** @var LoggerInterface */
  86. private $logger;
  87. /** @var Checker|\PHPUnit\Framework\MockObject\MockObject */
  88. private $checker;
  89. /** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
  90. private $dispatcher;
  91. /** @var Connection|\PHPUnit\Framework\MockObject\MockObject */
  92. private $db;
  93. private IThrottler $throttler;
  94. /** @var ILockingProvider|\PHPUnit\Framework\MockObject\MockObject */
  95. private $lockingProvider;
  96. /** @var IDateTimeFormatter|\PHPUnit\Framework\MockObject\MockObject */
  97. private $dateTimeFormatter;
  98. /** @var MemoryInfo|MockObject */
  99. private $memoryInfo;
  100. /** @var SecureRandom|\PHPUnit\Framework\MockObject\MockObject */
  101. private $secureRandom;
  102. /** @var IniGetWrapper|\PHPUnit\Framework\MockObject\MockObject */
  103. private $iniGetWrapper;
  104. /** @var IDBConnection|\PHPUnit\Framework\MockObject\MockObject */
  105. private $connection;
  106. /** @var ITempManager|\PHPUnit\Framework\MockObject\MockObject */
  107. private $tempManager;
  108. /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
  109. private $notificationManager;
  110. /** @var IAppManager|MockObject */
  111. private $appManager;
  112. /** @var IServerContainer|MockObject */
  113. private $serverContainer;
  114. /**
  115. * Holds a list of directories created during tests.
  116. *
  117. * @var array
  118. */
  119. private $dirsToRemove = [];
  120. protected function setUp(): void {
  121. parent::setUp();
  122. $this->request = $this->getMockBuilder(IRequest::class)
  123. ->disableOriginalConstructor()->getMock();
  124. $this->config = $this->getMockBuilder(IConfig::class)
  125. ->disableOriginalConstructor()->getMock();
  126. $this->clientService = $this->getMockBuilder(IClientService::class)
  127. ->disableOriginalConstructor()->getMock();
  128. $this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)
  129. ->disableOriginalConstructor()->getMock();
  130. $this->l10n = $this->getMockBuilder(IL10N::class)
  131. ->disableOriginalConstructor()->getMock();
  132. $this->l10n->expects($this->any())
  133. ->method('t')
  134. ->willReturnCallback(function ($message, array $replace) {
  135. return vsprintf($message, $replace);
  136. });
  137. $this->dispatcher = $this->createMock(IEventDispatcher::class);
  138. $this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker')
  139. ->disableOriginalConstructor()->getMock();
  140. $this->logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
  141. $this->db = $this->getMockBuilder(Connection::class)
  142. ->disableOriginalConstructor()->getMock();
  143. $this->throttler = $this->createMock(IThrottler::class);
  144. $this->lockingProvider = $this->getMockBuilder(ILockingProvider::class)->getMock();
  145. $this->dateTimeFormatter = $this->getMockBuilder(IDateTimeFormatter::class)->getMock();
  146. $this->memoryInfo = $this->getMockBuilder(MemoryInfo::class)
  147. ->setMethods(['isMemoryLimitSufficient',])
  148. ->getMock();
  149. $this->secureRandom = $this->getMockBuilder(SecureRandom::class)->getMock();
  150. $this->iniGetWrapper = $this->getMockBuilder(IniGetWrapper::class)->getMock();
  151. $this->connection = $this->getMockBuilder(IDBConnection::class)
  152. ->disableOriginalConstructor()->getMock();
  153. $this->tempManager = $this->getMockBuilder(ITempManager::class)->getMock();
  154. $this->notificationManager = $this->getMockBuilder(IManager::class)->getMock();
  155. $this->appManager = $this->createMock(IAppManager::class);
  156. $this->serverContainer = $this->createMock(IServerContainer::class);
  157. $this->checkSetupController = $this->getMockBuilder(CheckSetupController::class)
  158. ->setConstructorArgs([
  159. 'settings',
  160. $this->request,
  161. $this->config,
  162. $this->clientService,
  163. $this->urlGenerator,
  164. $this->l10n,
  165. $this->checker,
  166. $this->logger,
  167. $this->dispatcher,
  168. $this->db,
  169. $this->lockingProvider,
  170. $this->dateTimeFormatter,
  171. $this->memoryInfo,
  172. $this->secureRandom,
  173. $this->iniGetWrapper,
  174. $this->connection,
  175. $this->throttler,
  176. $this->tempManager,
  177. $this->notificationManager,
  178. $this->appManager,
  179. $this->serverContainer,
  180. ])
  181. ->setMethods([
  182. 'isReadOnlyConfig',
  183. 'wasEmailTestSuccessful',
  184. 'hasValidTransactionIsolationLevel',
  185. 'hasFileinfoInstalled',
  186. 'hasWorkingFileLocking',
  187. 'hasDBFileLocking',
  188. 'getLastCronInfo',
  189. 'getSuggestedOverwriteCliURL',
  190. 'getCurlVersion',
  191. 'isPhpOutdated',
  192. 'getOpcacheSetupRecommendations',
  193. 'hasFreeTypeSupport',
  194. 'hasMissingIndexes',
  195. 'hasMissingPrimaryKeys',
  196. 'isSqliteUsed',
  197. 'isPHPMailerUsed',
  198. 'getAppDirsWithDifferentOwner',
  199. 'isImagickEnabled',
  200. 'areWebauthnExtensionsEnabled',
  201. 'is64bit',
  202. 'hasRecommendedPHPModules',
  203. 'hasBigIntConversionPendingColumns',
  204. 'isMysqlUsedWithoutUTF8MB4',
  205. 'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed',
  206. ])->getMock();
  207. }
  208. /**
  209. * Removes directories created during tests.
  210. *
  211. * @after
  212. * @return void
  213. */
  214. public function removeTestDirectories() {
  215. foreach ($this->dirsToRemove as $dirToRemove) {
  216. rmdir($dirToRemove);
  217. }
  218. $this->dirsToRemove = [];
  219. }
  220. public function testIsInternetConnectionWorkingDisabledViaConfig() {
  221. $this->config->expects($this->once())
  222. ->method('getSystemValue')
  223. ->with('has_internet_connection', true)
  224. ->willReturn(false);
  225. $this->assertFalse(
  226. self::invokePrivate(
  227. $this->checkSetupController,
  228. 'hasInternetConnectivityProblems'
  229. )
  230. );
  231. }
  232. public function testIsInternetConnectionWorkingCorrectly() {
  233. $this->config->expects($this->exactly(2))
  234. ->method('getSystemValue')
  235. ->withConsecutive(
  236. ['has_internet_connection', true],
  237. ['connectivity_check_domains', ['www.nextcloud.com', 'www.startpage.com', 'www.eff.org', 'www.edri.org']],
  238. )->willReturnArgument(1);
  239. $client = $this->getMockBuilder('\OCP\Http\Client\IClient')
  240. ->disableOriginalConstructor()->getMock();
  241. $client->expects($this->any())
  242. ->method('get');
  243. $this->clientService->expects($this->once())
  244. ->method('newClient')
  245. ->willReturn($client);
  246. $this->assertFalse(
  247. self::invokePrivate(
  248. $this->checkSetupController,
  249. 'hasInternetConnectivityProblems'
  250. )
  251. );
  252. }
  253. public function testIsInternetConnectionFail() {
  254. $this->config->expects($this->exactly(2))
  255. ->method('getSystemValue')
  256. ->withConsecutive(
  257. ['has_internet_connection', true],
  258. ['connectivity_check_domains', ['www.nextcloud.com', 'www.startpage.com', 'www.eff.org', 'www.edri.org']],
  259. )->willReturnArgument(1);
  260. $client = $this->getMockBuilder('\OCP\Http\Client\IClient')
  261. ->disableOriginalConstructor()->getMock();
  262. $client->expects($this->any())
  263. ->method('get')
  264. ->will($this->throwException(new \Exception()));
  265. $this->clientService->expects($this->exactly(4))
  266. ->method('newClient')
  267. ->willReturn($client);
  268. $this->assertTrue(
  269. self::invokePrivate(
  270. $this->checkSetupController,
  271. 'hasInternetConnectivityProblems'
  272. )
  273. );
  274. }
  275. public function testIsMemcacheConfiguredFalse() {
  276. $this->config->expects($this->once())
  277. ->method('getSystemValue')
  278. ->with('memcache.local', null)
  279. ->willReturn(null);
  280. $this->assertFalse(
  281. self::invokePrivate(
  282. $this->checkSetupController,
  283. 'isMemcacheConfigured'
  284. )
  285. );
  286. }
  287. public function testIsMemcacheConfiguredTrue() {
  288. $this->config->expects($this->once())
  289. ->method('getSystemValue')
  290. ->with('memcache.local', null)
  291. ->willReturn('SomeProvider');
  292. $this->assertTrue(
  293. self::invokePrivate(
  294. $this->checkSetupController,
  295. 'isMemcacheConfigured'
  296. )
  297. );
  298. }
  299. public function testIsPhpSupportedFalse() {
  300. $this->checkSetupController
  301. ->expects($this->once())
  302. ->method('isPhpOutdated')
  303. ->willReturn(true);
  304. $this->assertEquals(
  305. ['eol' => true, 'version' => PHP_VERSION],
  306. self::invokePrivate($this->checkSetupController, 'isPhpSupported')
  307. );
  308. }
  309. public function testIsPhpSupportedTrue() {
  310. $this->checkSetupController
  311. ->expects($this->exactly(2))
  312. ->method('isPhpOutdated')
  313. ->willReturn(false);
  314. $this->assertEquals(
  315. ['eol' => false, 'version' => PHP_VERSION],
  316. self::invokePrivate($this->checkSetupController, 'isPhpSupported')
  317. );
  318. $this->assertEquals(
  319. ['eol' => false, 'version' => PHP_VERSION],
  320. self::invokePrivate($this->checkSetupController, 'isPhpSupported')
  321. );
  322. }
  323. /**
  324. * @dataProvider dataForwardedForHeadersWorking
  325. *
  326. * @param array $trustedProxies
  327. * @param string $remoteAddrNotForwarded
  328. * @param string $remoteAddr
  329. * @param bool $result
  330. */
  331. public function testForwardedForHeadersWorking(array $trustedProxies, string $remoteAddrNotForwarded, string $remoteAddr, bool $result): void {
  332. $this->config->expects($this->once())
  333. ->method('getSystemValue')
  334. ->with('trusted_proxies', [])
  335. ->willReturn($trustedProxies);
  336. $this->request->expects($this->atLeastOnce())
  337. ->method('getHeader')
  338. ->willReturnMap([
  339. ['REMOTE_ADDR', $remoteAddrNotForwarded],
  340. ['X-Forwarded-Host', '']
  341. ]);
  342. $this->request->expects($this->any())
  343. ->method('getRemoteAddress')
  344. ->willReturn($remoteAddr);
  345. $this->assertEquals(
  346. $result,
  347. self::invokePrivate($this->checkSetupController, 'forwardedForHeadersWorking')
  348. );
  349. }
  350. public function dataForwardedForHeadersWorking(): array {
  351. return [
  352. // description => trusted proxies, getHeader('REMOTE_ADDR'), getRemoteAddr, expected result
  353. 'no trusted proxies' => [[], '2.2.2.2', '2.2.2.2', true],
  354. 'trusted proxy, remote addr not trusted proxy' => [['1.1.1.1'], '2.2.2.2', '2.2.2.2', true],
  355. 'trusted proxy, remote addr is trusted proxy, x-forwarded-for working' => [['1.1.1.1'], '1.1.1.1', '2.2.2.2', true],
  356. 'trusted proxy, remote addr is trusted proxy, x-forwarded-for not set' => [['1.1.1.1'], '1.1.1.1', '1.1.1.1', false],
  357. ];
  358. }
  359. public function testForwardedHostPresentButTrustedProxiesNotAnArray(): void {
  360. $this->config->expects($this->once())
  361. ->method('getSystemValue')
  362. ->with('trusted_proxies', [])
  363. ->willReturn('1.1.1.1');
  364. $this->request->expects($this->atLeastOnce())
  365. ->method('getHeader')
  366. ->willReturnMap([
  367. ['REMOTE_ADDR', '1.1.1.1'],
  368. ['X-Forwarded-Host', 'nextcloud.test']
  369. ]);
  370. $this->request->expects($this->any())
  371. ->method('getRemoteAddress')
  372. ->willReturn('1.1.1.1');
  373. $this->assertEquals(
  374. false,
  375. self::invokePrivate($this->checkSetupController, 'forwardedForHeadersWorking')
  376. );
  377. }
  378. public function testForwardedHostPresentButTrustedProxiesEmpty(): void {
  379. $this->config->expects($this->once())
  380. ->method('getSystemValue')
  381. ->with('trusted_proxies', [])
  382. ->willReturn([]);
  383. $this->request->expects($this->atLeastOnce())
  384. ->method('getHeader')
  385. ->willReturnMap([
  386. ['REMOTE_ADDR', '1.1.1.1'],
  387. ['X-Forwarded-Host', 'nextcloud.test']
  388. ]);
  389. $this->request->expects($this->any())
  390. ->method('getRemoteAddress')
  391. ->willReturn('1.1.1.1');
  392. $this->assertEquals(
  393. false,
  394. self::invokePrivate($this->checkSetupController, 'forwardedForHeadersWorking')
  395. );
  396. }
  397. public function testCheck() {
  398. $this->config->expects($this->any())
  399. ->method('getAppValue')
  400. ->willReturnMap([
  401. ['files_external', 'user_certificate_scan', '', '["a", "b"]'],
  402. ['core', 'cronErrors', '', ''],
  403. ['dav', 'needs_system_address_book_sync', 'no', 'no'],
  404. ]);
  405. $this->config->expects($this->any())
  406. ->method('getSystemValue')
  407. ->willReturnMap([
  408. ['connectivity_check_domains', ['www.nextcloud.com', 'www.startpage.com', 'www.eff.org', 'www.edri.org'], ['www.nextcloud.com', 'www.startpage.com', 'www.eff.org', 'www.edri.org']],
  409. ['memcache.local', null, 'SomeProvider'],
  410. ['has_internet_connection', true, true],
  411. ['appstoreenabled', true, false],
  412. ]);
  413. $this->request->expects($this->atLeastOnce())
  414. ->method('getHeader')
  415. ->willReturnMap([
  416. ['REMOTE_ADDR', '4.3.2.1'],
  417. ['X-Forwarded-Host', '']
  418. ]);
  419. $client = $this->getMockBuilder('\OCP\Http\Client\IClient')
  420. ->disableOriginalConstructor()->getMock();
  421. $client->expects($this->exactly(4))
  422. ->method('get')
  423. ->withConsecutive(
  424. ['http://www.nextcloud.com/', []],
  425. ['http://www.startpage.com/', []],
  426. ['http://www.eff.org/', []],
  427. ['http://www.edri.org/', []]
  428. )->will($this->throwException(new \Exception()));
  429. $this->clientService->expects($this->exactly(4))
  430. ->method('newClient')
  431. ->willReturn($client);
  432. $this->checkSetupController
  433. ->expects($this->once())
  434. ->method('isPhpOutdated')
  435. ->willReturn(true);
  436. $this->checkSetupController
  437. ->expects($this->once())
  438. ->method('getOpcacheSetupRecommendations')
  439. ->willReturn(['recommendation1', 'recommendation2']);
  440. $this->checkSetupController
  441. ->method('hasFreeTypeSupport')
  442. ->willReturn(false);
  443. $this->checkSetupController
  444. ->method('hasMissingIndexes')
  445. ->willReturn([]);
  446. $this->checkSetupController
  447. ->method('hasMissingPrimaryKeys')
  448. ->willReturn([]);
  449. $this->checkSetupController
  450. ->method('isSqliteUsed')
  451. ->willReturn(false);
  452. $this->checkSetupController
  453. ->expects($this->once())
  454. ->method('isReadOnlyConfig')
  455. ->willReturn(false);
  456. $this->checkSetupController
  457. ->expects($this->once())
  458. ->method('wasEmailTestSuccessful')
  459. ->willReturn(false);
  460. $this->checkSetupController
  461. ->expects($this->once())
  462. ->method('hasValidTransactionIsolationLevel')
  463. ->willReturn(true);
  464. $this->checkSetupController
  465. ->expects($this->once())
  466. ->method('hasFileinfoInstalled')
  467. ->willReturn(true);
  468. $this->checkSetupController
  469. ->expects($this->once())
  470. ->method('hasWorkingFileLocking')
  471. ->willReturn(true);
  472. $this->checkSetupController
  473. ->expects($this->once())
  474. ->method('hasDBFileLocking')
  475. ->willReturn(true);
  476. $this->checkSetupController
  477. ->expects($this->once())
  478. ->method('getSuggestedOverwriteCliURL')
  479. ->willReturn('');
  480. $this->checkSetupController
  481. ->expects($this->once())
  482. ->method('getLastCronInfo')
  483. ->willReturn([
  484. 'diffInSeconds' => 123,
  485. 'relativeTime' => '2 hours ago',
  486. 'backgroundJobsUrl' => 'https://example.org',
  487. ]);
  488. $this->checker
  489. ->expects($this->once())
  490. ->method('hasPassedCheck')
  491. ->willReturn(true);
  492. $this->memoryInfo
  493. ->method('isMemoryLimitSufficient')
  494. ->willReturn(true);
  495. $this->checkSetupController
  496. ->expects($this->once())
  497. ->method('getAppDirsWithDifferentOwner')
  498. ->willReturn([]);
  499. $this->checkSetupController
  500. ->expects($this->once())
  501. ->method('isImagickEnabled')
  502. ->willReturn(false);
  503. $this->checkSetupController
  504. ->expects($this->once())
  505. ->method('areWebauthnExtensionsEnabled')
  506. ->willReturn(false);
  507. $this->checkSetupController
  508. ->expects($this->once())
  509. ->method('is64bit')
  510. ->willReturn(false);
  511. $this->checkSetupController
  512. ->expects($this->once())
  513. ->method('hasRecommendedPHPModules')
  514. ->willReturn([]);
  515. $this->checkSetupController
  516. ->expects($this->once())
  517. ->method('hasBigIntConversionPendingColumns')
  518. ->willReturn([]);
  519. $this->checkSetupController
  520. ->expects($this->once())
  521. ->method('isMysqlUsedWithoutUTF8MB4')
  522. ->willReturn(false);
  523. $this->checkSetupController
  524. ->expects($this->once())
  525. ->method('isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed')
  526. ->willReturn(true);
  527. $this->urlGenerator->method('linkToDocs')
  528. ->willReturnCallback(function (string $key): string {
  529. if ($key === 'admin-performance') {
  530. return 'http://docs.example.org/server/go.php?to=admin-performance';
  531. }
  532. if ($key === 'admin-security') {
  533. return 'https://docs.example.org/server/8.1/admin_manual/configuration_server/hardening.html';
  534. }
  535. if ($key === 'admin-reverse-proxy') {
  536. return 'reverse-proxy-doc-link';
  537. }
  538. if ($key === 'admin-code-integrity') {
  539. return 'http://docs.example.org/server/go.php?to=admin-code-integrity';
  540. }
  541. if ($key === 'admin-db-conversion') {
  542. return 'http://docs.example.org/server/go.php?to=admin-db-conversion';
  543. }
  544. return '';
  545. });
  546. $this->urlGenerator->method('getAbsoluteURL')
  547. ->willReturnCallback(function (string $url): string {
  548. if ($url === 'index.php/settings/admin') {
  549. return 'https://server/index.php/settings/admin';
  550. }
  551. if ($url === 'index.php') {
  552. return 'https://server/index.php';
  553. }
  554. return '';
  555. });
  556. $sqlitePlatform = $this->getMockBuilder(SqlitePlatform::class)->getMock();
  557. $this->connection->method('getDatabasePlatform')
  558. ->willReturn($sqlitePlatform);
  559. $expected = new DataResponse(
  560. [
  561. 'isGetenvServerWorking' => true,
  562. 'isReadOnlyConfig' => false,
  563. 'wasEmailTestSuccessful' => false,
  564. 'hasValidTransactionIsolationLevel' => true,
  565. 'hasFileinfoInstalled' => true,
  566. 'hasWorkingFileLocking' => true,
  567. 'hasDBFileLocking' => true,
  568. 'suggestedOverwriteCliURL' => '',
  569. 'cronInfo' => [
  570. 'diffInSeconds' => 123,
  571. 'relativeTime' => '2 hours ago',
  572. 'backgroundJobsUrl' => 'https://example.org',
  573. ],
  574. 'cronErrors' => [],
  575. 'serverHasInternetConnectionProblems' => true,
  576. 'isMemcacheConfigured' => true,
  577. 'memcacheDocs' => 'http://docs.example.org/server/go.php?to=admin-performance',
  578. 'isRandomnessSecure' => self::invokePrivate($this->checkSetupController, 'isRandomnessSecure'),
  579. 'securityDocs' => 'https://docs.example.org/server/8.1/admin_manual/configuration_server/hardening.html',
  580. 'isUsedTlsLibOutdated' => '',
  581. 'phpSupported' => [
  582. 'eol' => true,
  583. 'version' => PHP_VERSION
  584. ],
  585. 'forwardedForHeadersWorking' => false,
  586. 'reverseProxyDocs' => 'reverse-proxy-doc-link',
  587. 'isCorrectMemcachedPHPModuleInstalled' => true,
  588. 'hasPassedCodeIntegrityCheck' => true,
  589. 'codeIntegrityCheckerDocumentation' => 'http://docs.example.org/server/go.php?to=admin-code-integrity',
  590. 'OpcacheSetupRecommendations' => ['recommendation1', 'recommendation2'],
  591. 'isSettimelimitAvailable' => true,
  592. 'hasFreeTypeSupport' => false,
  593. 'isSqliteUsed' => false,
  594. 'databaseConversionDocumentation' => 'http://docs.example.org/server/go.php?to=admin-db-conversion',
  595. 'missingIndexes' => [],
  596. 'missingPrimaryKeys' => [],
  597. 'missingColumns' => [],
  598. 'isMemoryLimitSufficient' => true,
  599. 'appDirsWithDifferentOwner' => [],
  600. 'isImagickEnabled' => false,
  601. 'areWebauthnExtensionsEnabled' => false,
  602. 'is64bit' => false,
  603. 'recommendedPHPModules' => [],
  604. 'pendingBigIntConversionColumns' => [],
  605. 'isMysqlUsedWithoutUTF8MB4' => false,
  606. 'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed' => true,
  607. 'reverseProxyGeneratedURL' => 'https://server/index.php',
  608. 'OCA\Settings\SetupChecks\PhpDefaultCharset' => ['pass' => true, 'description' => 'PHP configuration option default_charset should be UTF-8', 'severity' => 'warning'],
  609. 'OCA\Settings\SetupChecks\PhpOutputBuffering' => ['pass' => true, 'description' => 'PHP configuration option output_buffering must be disabled', 'severity' => 'error'],
  610. 'OCA\Settings\SetupChecks\LegacySSEKeyFormat' => ['pass' => true, 'description' => 'The old server-side-encryption format is enabled. We recommend disabling this.', 'severity' => 'warning', 'linkToDocumentation' => ''],
  611. 'OCA\Settings\SetupChecks\CheckUserCertificates' => ['pass' => false, 'description' => 'There are some user imported SSL certificates present, that are not used anymore with Nextcloud 21. They can be imported on the command line via "occ security:certificates:import" command. Their paths inside the data directory are shown below.', 'severity' => 'warning', 'elements' => ['a', 'b']],
  612. 'imageMagickLacksSVGSupport' => false,
  613. 'isDefaultPhoneRegionSet' => false,
  614. 'OCA\Settings\SetupChecks\SupportedDatabase' => ['pass' => true, 'description' => '', 'severity' => 'info'],
  615. 'isFairUseOfFreePushService' => false,
  616. 'temporaryDirectoryWritable' => false,
  617. \OCA\Settings\SetupChecks\LdapInvalidUuids::class => ['pass' => true, 'description' => 'Invalid UUIDs of LDAP users or groups have been found. Please review your "Override UUID detection" settings in the Expert part of the LDAP configuration and use "occ ldap:update-uuid" to update them.', 'severity' => 'warning'],
  618. \OCA\Settings\SetupChecks\NeedsSystemAddressBookSync::class => ['pass' => true, 'description' => 'The DAV system address book sync has not run yet as your instance has more than 1000 users or because an error occured. Please run it manually by calling occ dav:sync-system-addressbook.', 'severity' => 'warning'],
  619. 'isBruteforceThrottled' => false,
  620. 'bruteforceRemoteAddress' => '',
  621. ]
  622. );
  623. $this->assertEquals($expected, $this->checkSetupController->check());
  624. }
  625. public function testGetCurlVersion() {
  626. $checkSetupController = $this->getMockBuilder(CheckSetupController::class)
  627. ->setConstructorArgs([
  628. 'settings',
  629. $this->request,
  630. $this->config,
  631. $this->clientService,
  632. $this->urlGenerator,
  633. $this->l10n,
  634. $this->checker,
  635. $this->logger,
  636. $this->dispatcher,
  637. $this->db,
  638. $this->lockingProvider,
  639. $this->dateTimeFormatter,
  640. $this->memoryInfo,
  641. $this->secureRandom,
  642. $this->iniGetWrapper,
  643. $this->connection,
  644. $this->throttler,
  645. $this->tempManager,
  646. $this->notificationManager,
  647. $this->appManager,
  648. $this->serverContainer
  649. ])
  650. ->setMethods(null)->getMock();
  651. $this->assertArrayHasKey('ssl_version', $this->invokePrivate($checkSetupController, 'getCurlVersion'));
  652. }
  653. public function testIsUsedTlsLibOutdatedWithAnotherLibrary() {
  654. $this->config->expects($this->any())
  655. ->method('getSystemValue')
  656. ->willReturn(true);
  657. $this->checkSetupController
  658. ->expects($this->once())
  659. ->method('getCurlVersion')
  660. ->willReturn(['ssl_version' => 'SSLlib']);
  661. $this->assertSame('', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated'));
  662. }
  663. public function testIsUsedTlsLibOutdatedWithMisbehavingCurl() {
  664. $this->config->expects($this->any())
  665. ->method('getSystemValue')
  666. ->willReturn(true);
  667. $this->checkSetupController
  668. ->expects($this->once())
  669. ->method('getCurlVersion')
  670. ->willReturn([]);
  671. $this->assertSame('', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated'));
  672. }
  673. public function testIsUsedTlsLibOutdatedWithMatchingOpenSslVersion() {
  674. $this->config->expects($this->any())
  675. ->method('getSystemValue')
  676. ->willReturn(true);
  677. $this->checkSetupController
  678. ->expects($this->once())
  679. ->method('getCurlVersion')
  680. ->willReturn(['ssl_version' => 'OpenSSL/1.0.1d']);
  681. $this->assertSame('', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated'));
  682. }
  683. public function testIsUsedTlsLibOutdatedWithMatchingOpenSslVersion1() {
  684. $this->config->expects($this->any())
  685. ->method('getSystemValue')
  686. ->willReturn(true);
  687. $this->checkSetupController
  688. ->expects($this->once())
  689. ->method('getCurlVersion')
  690. ->willReturn(['ssl_version' => 'OpenSSL/1.0.2b']);
  691. $this->assertSame('', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated'));
  692. }
  693. /**
  694. * Setups a temp directory and some subdirectories.
  695. * Then calls the 'getAppDirsWithDifferentOwner' method.
  696. * The result is expected to be empty since
  697. * there are no directories with different owners than the current user.
  698. *
  699. * @return void
  700. */
  701. public function testAppDirectoryOwnersOk() {
  702. $tempDir = tempnam(sys_get_temp_dir(), 'apps') . 'dir';
  703. mkdir($tempDir);
  704. mkdir($tempDir . DIRECTORY_SEPARATOR . 'app1');
  705. mkdir($tempDir . DIRECTORY_SEPARATOR . 'app2');
  706. $this->dirsToRemove[] = $tempDir . DIRECTORY_SEPARATOR . 'app1';
  707. $this->dirsToRemove[] = $tempDir . DIRECTORY_SEPARATOR . 'app2';
  708. $this->dirsToRemove[] = $tempDir;
  709. OC::$APPSROOTS = [
  710. [
  711. 'path' => $tempDir,
  712. 'url' => '/apps',
  713. 'writable' => true,
  714. ],
  715. ];
  716. $this->assertSame(
  717. [],
  718. $this->invokePrivate($this->checkSetupController, 'getAppDirsWithDifferentOwner')
  719. );
  720. }
  721. /**
  722. * Calls the check for a none existing app root that is marked as not writable.
  723. * It's expected that no error happens since the check shouldn't apply.
  724. *
  725. * @return void
  726. */
  727. public function testAppDirectoryOwnersNotWritable() {
  728. $tempDir = tempnam(sys_get_temp_dir(), 'apps') . 'dir';
  729. OC::$APPSROOTS = [
  730. [
  731. 'path' => $tempDir,
  732. 'url' => '/apps',
  733. 'writable' => false,
  734. ],
  735. ];
  736. $this->assertSame(
  737. [],
  738. $this->invokePrivate($this->checkSetupController, 'getAppDirsWithDifferentOwner')
  739. );
  740. }
  741. public function testIsBuggyNss400() {
  742. $this->config->expects($this->any())
  743. ->method('getSystemValue')
  744. ->willReturn(true);
  745. $this->checkSetupController
  746. ->expects($this->once())
  747. ->method('getCurlVersion')
  748. ->willReturn(['ssl_version' => 'NSS/1.0.2b']);
  749. $client = $this->getMockBuilder('\OCP\Http\Client\IClient')
  750. ->disableOriginalConstructor()->getMock();
  751. $exception = $this->getMockBuilder('\GuzzleHttp\Exception\ClientException')
  752. ->disableOriginalConstructor()->getMock();
  753. $response = $this->getMockBuilder(ResponseInterface::class)
  754. ->disableOriginalConstructor()->getMock();
  755. $response->expects($this->once())
  756. ->method('getStatusCode')
  757. ->willReturn(400);
  758. $exception->expects($this->once())
  759. ->method('getResponse')
  760. ->willReturn($response);
  761. $client->expects($this->once())
  762. ->method('get')
  763. ->with('https://nextcloud.com/', [])
  764. ->will($this->throwException($exception));
  765. $this->clientService->expects($this->once())
  766. ->method('newClient')
  767. ->willReturn($client);
  768. $this->assertSame('cURL is using an outdated NSS version (NSS/1.0.2b). Please update your operating system or features such as installing and updating apps via the App Store or Federated Cloud Sharing will not work reliably.', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated'));
  769. }
  770. public function testIsBuggyNss200() {
  771. $this->config->expects($this->any())
  772. ->method('getSystemValue')
  773. ->willReturn(true);
  774. $this->checkSetupController
  775. ->expects($this->once())
  776. ->method('getCurlVersion')
  777. ->willReturn(['ssl_version' => 'NSS/1.0.2b']);
  778. $client = $this->getMockBuilder('\OCP\Http\Client\IClient')
  779. ->disableOriginalConstructor()->getMock();
  780. $exception = $this->getMockBuilder('\GuzzleHttp\Exception\ClientException')
  781. ->disableOriginalConstructor()->getMock();
  782. $response = $this->getMockBuilder(ResponseInterface::class)
  783. ->disableOriginalConstructor()->getMock();
  784. $response->expects($this->once())
  785. ->method('getStatusCode')
  786. ->willReturn(200);
  787. $exception->expects($this->once())
  788. ->method('getResponse')
  789. ->willReturn($response);
  790. $client->expects($this->once())
  791. ->method('get')
  792. ->with('https://nextcloud.com/', [])
  793. ->will($this->throwException($exception));
  794. $this->clientService->expects($this->once())
  795. ->method('newClient')
  796. ->willReturn($client);
  797. $this->assertSame('', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated'));
  798. }
  799. public function testIsUsedTlsLibOutdatedWithInternetDisabled() {
  800. $this->config
  801. ->expects($this->once())
  802. ->method('getSystemValue')
  803. ->with('has_internet_connection', true)
  804. ->willReturn(false);
  805. $this->assertSame('', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated'));
  806. }
  807. public function testIsUsedTlsLibOutdatedWithAppstoreDisabledAndServerToServerSharingEnabled() {
  808. $this->config
  809. ->expects($this->exactly(2))
  810. ->method('getSystemValue')
  811. ->willReturnMap([
  812. ['has_internet_connection', true, true],
  813. ['appstoreenabled', true, false],
  814. ]);
  815. $this->config
  816. ->expects($this->exactly(2))
  817. ->method('getAppValue')
  818. ->willReturnMap([
  819. ['files_sharing', 'outgoing_server2server_share_enabled', 'yes', 'no'],
  820. ['files_sharing', 'incoming_server2server_share_enabled', 'yes', 'yes'],
  821. ]);
  822. $this->checkSetupController
  823. ->expects($this->once())
  824. ->method('getCurlVersion')
  825. ->willReturn([]);
  826. $this->assertSame('', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated'));
  827. }
  828. public function testIsUsedTlsLibOutdatedWithAppstoreDisabledAndServerToServerSharingDisabled() {
  829. $this->config
  830. ->expects($this->exactly(2))
  831. ->method('getSystemValue')
  832. ->willReturnMap([
  833. ['has_internet_connection', true, true],
  834. ['appstoreenabled', true, false],
  835. ]);
  836. $this->config
  837. ->expects($this->exactly(2))
  838. ->method('getAppValue')
  839. ->willReturnMap([
  840. ['files_sharing', 'outgoing_server2server_share_enabled', 'yes', 'no'],
  841. ['files_sharing', 'incoming_server2server_share_enabled', 'yes', 'no'],
  842. ]);
  843. $this->checkSetupController
  844. ->expects($this->never())
  845. ->method('getCurlVersion')
  846. ->willReturn([]);
  847. $this->assertSame('', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated'));
  848. }
  849. public function testRescanFailedIntegrityCheck() {
  850. $this->checker
  851. ->expects($this->once())
  852. ->method('runInstanceVerification');
  853. $this->urlGenerator
  854. ->expects($this->once())
  855. ->method('linkToRoute')
  856. ->with('settings.AdminSettings.index')
  857. ->willReturn('/admin');
  858. $expected = new RedirectResponse('/admin');
  859. $this->assertEquals($expected, $this->checkSetupController->rescanFailedIntegrityCheck());
  860. }
  861. public function testGetFailedIntegrityCheckDisabled() {
  862. $this->checker
  863. ->expects($this->once())
  864. ->method('isCodeCheckEnforced')
  865. ->willReturn(false);
  866. $expected = new DataDisplayResponse('Integrity checker has been disabled. Integrity cannot be verified.');
  867. $this->assertEquals($expected, $this->checkSetupController->getFailedIntegrityCheckFiles());
  868. }
  869. public function testGetFailedIntegrityCheckFilesWithNoErrorsFound() {
  870. $this->checker
  871. ->expects($this->once())
  872. ->method('isCodeCheckEnforced')
  873. ->willReturn(true);
  874. $this->checker
  875. ->expects($this->once())
  876. ->method('getResults')
  877. ->willReturn([]);
  878. $expected = new DataDisplayResponse(
  879. 'No errors have been found.',
  880. Http::STATUS_OK,
  881. [
  882. 'Content-Type' => 'text/plain',
  883. ]
  884. );
  885. $this->assertEquals($expected, $this->checkSetupController->getFailedIntegrityCheckFiles());
  886. }
  887. public function testGetFailedIntegrityCheckFilesWithSomeErrorsFound() {
  888. $this->checker
  889. ->expects($this->once())
  890. ->method('isCodeCheckEnforced')
  891. ->willReturn(true);
  892. $this->checker
  893. ->expects($this->once())
  894. ->method('getResults')
  895. ->willReturn([ 'core' => [ 'EXTRA_FILE' => ['/testfile' => []], 'INVALID_HASH' => [ '/.idea/workspace.xml' => [ 'expected' => 'f1c5e2630d784bc9cb02d5a28f55d6f24d06dae2a0fee685f3c2521b050955d9d452769f61454c9ddfa9c308146ade10546cfa829794448eaffbc9a04a29d216', 'current' => 'ce08bf30bcbb879a18b49239a9bec6b8702f52452f88a9d32142cad8d2494d5735e6bfa0d8642b2762c62ca5be49f9bf4ec231d4a230559d4f3e2c471d3ea094', ], '/lib/private/integritycheck/checker.php' => [ 'expected' => 'c5a03bacae8dedf8b239997901ba1fffd2fe51271d13a00cc4b34b09cca5176397a89fc27381cbb1f72855fa18b69b6f87d7d5685c3b45aee373b09be54742ea', 'current' => '88a3a92c11db91dec1ac3be0e1c87f862c95ba6ffaaaa3f2c3b8f682187c66f07af3a3b557a868342ef4a271218fe1c1e300c478e6c156c5955ed53c40d06585', ], '/settings/controller/checksetupcontroller.php' => [ 'expected' => '3e1de26ce93c7bfe0ede7c19cb6c93cadc010340225b375607a7178812e9de163179b0dc33809f451e01f491d93f6f5aaca7929685d21594cccf8bda732327c4', 'current' => '09563164f9904a837f9ca0b5f626db56c838e5098e0ccc1d8b935f68fa03a25c5ec6f6b2d9e44a868e8b85764dafd1605522b4af8db0ae269d73432e9a01e63a', ], ], ], 'bookmarks' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'dav' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'encryption' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'external' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'federation' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_antivirus' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_drop' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_external' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_pdfviewer' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_sharing' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_trashbin' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_versions' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'files_videoviewer' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'firstrunwizard' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'gitsmart' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'logreader' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature could not get verified.', ], ], 'password_policy' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'provisioning_api' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'sketch' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'threatblock' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'two_factor_auth' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'user_ldap' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], 'user_shibboleth' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ], ], ]);
  896. $expected = new DataDisplayResponse(
  897. 'Technical information
  898. =====================
  899. The following list covers which files have failed the integrity check. Please read
  900. the previous linked documentation to learn more about the errors and how to fix
  901. them.
  902. Results
  903. =======
  904. - core
  905. - EXTRA_FILE
  906. - /testfile
  907. - INVALID_HASH
  908. - /.idea/workspace.xml
  909. - /lib/private/integritycheck/checker.php
  910. - /settings/controller/checksetupcontroller.php
  911. - bookmarks
  912. - EXCEPTION
  913. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  914. - Signature data not found.
  915. - dav
  916. - EXCEPTION
  917. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  918. - Signature data not found.
  919. - encryption
  920. - EXCEPTION
  921. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  922. - Signature data not found.
  923. - external
  924. - EXCEPTION
  925. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  926. - Signature data not found.
  927. - federation
  928. - EXCEPTION
  929. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  930. - Signature data not found.
  931. - files
  932. - EXCEPTION
  933. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  934. - Signature data not found.
  935. - files_antivirus
  936. - EXCEPTION
  937. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  938. - Signature data not found.
  939. - files_drop
  940. - EXCEPTION
  941. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  942. - Signature data not found.
  943. - files_external
  944. - EXCEPTION
  945. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  946. - Signature data not found.
  947. - files_pdfviewer
  948. - EXCEPTION
  949. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  950. - Signature data not found.
  951. - files_sharing
  952. - EXCEPTION
  953. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  954. - Signature data not found.
  955. - files_trashbin
  956. - EXCEPTION
  957. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  958. - Signature data not found.
  959. - files_versions
  960. - EXCEPTION
  961. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  962. - Signature data not found.
  963. - files_videoviewer
  964. - EXCEPTION
  965. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  966. - Signature data not found.
  967. - firstrunwizard
  968. - EXCEPTION
  969. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  970. - Signature data not found.
  971. - gitsmart
  972. - EXCEPTION
  973. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  974. - Signature data not found.
  975. - logreader
  976. - EXCEPTION
  977. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  978. - Signature could not get verified.
  979. - password_policy
  980. - EXCEPTION
  981. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  982. - Signature data not found.
  983. - provisioning_api
  984. - EXCEPTION
  985. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  986. - Signature data not found.
  987. - sketch
  988. - EXCEPTION
  989. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  990. - Signature data not found.
  991. - threatblock
  992. - EXCEPTION
  993. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  994. - Signature data not found.
  995. - two_factor_auth
  996. - EXCEPTION
  997. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  998. - Signature data not found.
  999. - user_ldap
  1000. - EXCEPTION
  1001. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  1002. - Signature data not found.
  1003. - user_shibboleth
  1004. - EXCEPTION
  1005. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  1006. - Signature data not found.
  1007. Raw output
  1008. ==========
  1009. Array
  1010. (
  1011. [core] => Array
  1012. (
  1013. [EXTRA_FILE] => Array
  1014. (
  1015. [/testfile] => Array
  1016. (
  1017. )
  1018. )
  1019. [INVALID_HASH] => Array
  1020. (
  1021. [/.idea/workspace.xml] => Array
  1022. (
  1023. [expected] => f1c5e2630d784bc9cb02d5a28f55d6f24d06dae2a0fee685f3c2521b050955d9d452769f61454c9ddfa9c308146ade10546cfa829794448eaffbc9a04a29d216
  1024. [current] => ce08bf30bcbb879a18b49239a9bec6b8702f52452f88a9d32142cad8d2494d5735e6bfa0d8642b2762c62ca5be49f9bf4ec231d4a230559d4f3e2c471d3ea094
  1025. )
  1026. [/lib/private/integritycheck/checker.php] => Array
  1027. (
  1028. [expected] => c5a03bacae8dedf8b239997901ba1fffd2fe51271d13a00cc4b34b09cca5176397a89fc27381cbb1f72855fa18b69b6f87d7d5685c3b45aee373b09be54742ea
  1029. [current] => 88a3a92c11db91dec1ac3be0e1c87f862c95ba6ffaaaa3f2c3b8f682187c66f07af3a3b557a868342ef4a271218fe1c1e300c478e6c156c5955ed53c40d06585
  1030. )
  1031. [/settings/controller/checksetupcontroller.php] => Array
  1032. (
  1033. [expected] => 3e1de26ce93c7bfe0ede7c19cb6c93cadc010340225b375607a7178812e9de163179b0dc33809f451e01f491d93f6f5aaca7929685d21594cccf8bda732327c4
  1034. [current] => 09563164f9904a837f9ca0b5f626db56c838e5098e0ccc1d8b935f68fa03a25c5ec6f6b2d9e44a868e8b85764dafd1605522b4af8db0ae269d73432e9a01e63a
  1035. )
  1036. )
  1037. )
  1038. [bookmarks] => Array
  1039. (
  1040. [EXCEPTION] => Array
  1041. (
  1042. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  1043. [message] => Signature data not found.
  1044. )
  1045. )
  1046. [dav] => Array
  1047. (
  1048. [EXCEPTION] => Array
  1049. (
  1050. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  1051. [message] => Signature data not found.
  1052. )
  1053. )
  1054. [encryption] => Array
  1055. (
  1056. [EXCEPTION] => Array
  1057. (
  1058. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  1059. [message] => Signature data not found.
  1060. )
  1061. )
  1062. [external] => Array
  1063. (
  1064. [EXCEPTION] => Array
  1065. (
  1066. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  1067. [message] => Signature data not found.
  1068. )
  1069. )
  1070. [federation] => Array
  1071. (
  1072. [EXCEPTION] => Array
  1073. (
  1074. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  1075. [message] => Signature data not found.
  1076. )
  1077. )
  1078. [files] => Array
  1079. (
  1080. [EXCEPTION] => Array
  1081. (
  1082. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  1083. [message] => Signature data not found.
  1084. )
  1085. )
  1086. [files_antivirus] => Array
  1087. (
  1088. [EXCEPTION] => Array
  1089. (
  1090. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  1091. [message] => Signature data not found.
  1092. )
  1093. )
  1094. [files_drop] => Array
  1095. (
  1096. [EXCEPTION] => Array
  1097. (
  1098. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  1099. [message] => Signature data not found.
  1100. )
  1101. )
  1102. [files_external] => Array
  1103. (
  1104. [EXCEPTION] => Array
  1105. (
  1106. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  1107. [message] => Signature data not found.
  1108. )
  1109. )
  1110. [files_pdfviewer] => Array
  1111. (
  1112. [EXCEPTION] => Array
  1113. (
  1114. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  1115. [message] => Signature data not found.
  1116. )
  1117. )
  1118. [files_sharing] => Array
  1119. (
  1120. [EXCEPTION] => Array
  1121. (
  1122. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  1123. [message] => Signature data not found.
  1124. )
  1125. )
  1126. [files_trashbin] => Array
  1127. (
  1128. [EXCEPTION] => Array
  1129. (
  1130. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  1131. [message] => Signature data not found.
  1132. )
  1133. )
  1134. [files_versions] => Array
  1135. (
  1136. [EXCEPTION] => Array
  1137. (
  1138. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  1139. [message] => Signature data not found.
  1140. )
  1141. )
  1142. [files_videoviewer] => Array
  1143. (
  1144. [EXCEPTION] => Array
  1145. (
  1146. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  1147. [message] => Signature data not found.
  1148. )
  1149. )
  1150. [firstrunwizard] => Array
  1151. (
  1152. [EXCEPTION] => Array
  1153. (
  1154. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  1155. [message] => Signature data not found.
  1156. )
  1157. )
  1158. [gitsmart] => Array
  1159. (
  1160. [EXCEPTION] => Array
  1161. (
  1162. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  1163. [message] => Signature data not found.
  1164. )
  1165. )
  1166. [logreader] => Array
  1167. (
  1168. [EXCEPTION] => Array
  1169. (
  1170. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  1171. [message] => Signature could not get verified.
  1172. )
  1173. )
  1174. [password_policy] => Array
  1175. (
  1176. [EXCEPTION] => Array
  1177. (
  1178. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  1179. [message] => Signature data not found.
  1180. )
  1181. )
  1182. [provisioning_api] => Array
  1183. (
  1184. [EXCEPTION] => Array
  1185. (
  1186. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  1187. [message] => Signature data not found.
  1188. )
  1189. )
  1190. [sketch] => Array
  1191. (
  1192. [EXCEPTION] => Array
  1193. (
  1194. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  1195. [message] => Signature data not found.
  1196. )
  1197. )
  1198. [threatblock] => Array
  1199. (
  1200. [EXCEPTION] => Array
  1201. (
  1202. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  1203. [message] => Signature data not found.
  1204. )
  1205. )
  1206. [two_factor_auth] => Array
  1207. (
  1208. [EXCEPTION] => Array
  1209. (
  1210. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  1211. [message] => Signature data not found.
  1212. )
  1213. )
  1214. [user_ldap] => Array
  1215. (
  1216. [EXCEPTION] => Array
  1217. (
  1218. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  1219. [message] => Signature data not found.
  1220. )
  1221. )
  1222. [user_shibboleth] => Array
  1223. (
  1224. [EXCEPTION] => Array
  1225. (
  1226. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  1227. [message] => Signature data not found.
  1228. )
  1229. )
  1230. )
  1231. ',
  1232. Http::STATUS_OK,
  1233. [
  1234. 'Content-Type' => 'text/plain',
  1235. ]
  1236. );
  1237. $this->assertEquals($expected, $this->checkSetupController->getFailedIntegrityCheckFiles());
  1238. }
  1239. public function dataForIsMysqlUsedWithoutUTF8MB4() {
  1240. return [
  1241. ['sqlite', false, false],
  1242. ['sqlite', true, false],
  1243. ['postgres', false, false],
  1244. ['postgres', true, false],
  1245. ['oci', false, false],
  1246. ['oci', true, false],
  1247. ['mysql', false, true],
  1248. ['mysql', true, false],
  1249. ];
  1250. }
  1251. /**
  1252. * @dataProvider dataForIsMysqlUsedWithoutUTF8MB4
  1253. */
  1254. public function testIsMysqlUsedWithoutUTF8MB4(string $db, bool $useUTF8MB4, bool $expected) {
  1255. $this->config->method('getSystemValue')
  1256. ->willReturnCallback(function ($key, $default) use ($db, $useUTF8MB4) {
  1257. if ($key === 'dbtype') {
  1258. return $db;
  1259. }
  1260. if ($key === 'mysql.utf8mb4') {
  1261. return $useUTF8MB4;
  1262. }
  1263. return $default;
  1264. });
  1265. $checkSetupController = new CheckSetupController(
  1266. 'settings',
  1267. $this->request,
  1268. $this->config,
  1269. $this->clientService,
  1270. $this->urlGenerator,
  1271. $this->l10n,
  1272. $this->checker,
  1273. $this->logger,
  1274. $this->dispatcher,
  1275. $this->db,
  1276. $this->lockingProvider,
  1277. $this->dateTimeFormatter,
  1278. $this->memoryInfo,
  1279. $this->secureRandom,
  1280. $this->iniGetWrapper,
  1281. $this->connection,
  1282. $this->throttler,
  1283. $this->tempManager,
  1284. $this->notificationManager,
  1285. $this->appManager,
  1286. $this->serverContainer
  1287. );
  1288. $this->assertSame($expected, $this->invokePrivate($checkSetupController, 'isMysqlUsedWithoutUTF8MB4'));
  1289. }
  1290. public function dataForIsEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed() {
  1291. return [
  1292. ['singlebucket', 'OC\\Files\\ObjectStore\\Swift', true],
  1293. ['multibucket', 'OC\\Files\\ObjectStore\\Swift', true],
  1294. ['singlebucket', 'OC\\Files\\ObjectStore\\Custom', true],
  1295. ['multibucket', 'OC\Files\\ObjectStore\\Custom', true],
  1296. ['singlebucket', 'OC\Files\ObjectStore\Swift', true],
  1297. ['multibucket', 'OC\Files\ObjectStore\Swift', true],
  1298. ['singlebucket', 'OC\Files\ObjectStore\Custom', true],
  1299. ['multibucket', 'OC\Files\ObjectStore\Custom', true],
  1300. ];
  1301. }
  1302. /**
  1303. * @dataProvider dataForIsEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed
  1304. */
  1305. public function testIsEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed(string $mode, string $className, bool $expected) {
  1306. $this->config->method('getSystemValue')
  1307. ->willReturnCallback(function ($key, $default) use ($mode, $className) {
  1308. if ($key === 'objectstore' && $mode === 'singlebucket') {
  1309. return ['class' => $className];
  1310. }
  1311. if ($key === 'objectstore_multibucket' && $mode === 'multibucket') {
  1312. return ['class' => $className];
  1313. }
  1314. return $default;
  1315. });
  1316. $checkSetupController = new CheckSetupController(
  1317. 'settings',
  1318. $this->request,
  1319. $this->config,
  1320. $this->clientService,
  1321. $this->urlGenerator,
  1322. $this->l10n,
  1323. $this->checker,
  1324. $this->logger,
  1325. $this->dispatcher,
  1326. $this->db,
  1327. $this->lockingProvider,
  1328. $this->dateTimeFormatter,
  1329. $this->memoryInfo,
  1330. $this->secureRandom,
  1331. $this->iniGetWrapper,
  1332. $this->connection,
  1333. $this->throttler,
  1334. $this->tempManager,
  1335. $this->notificationManager,
  1336. $this->appManager,
  1337. $this->serverContainer
  1338. );
  1339. $this->assertSame($expected, $this->invokePrivate($checkSetupController, 'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed'));
  1340. }
  1341. }