CheckSetupControllerTest.php 52 KB

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