CheckSetupControllerTest.php 52 KB

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