CheckSetupControllerTest.php 53 KB

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