1
0

CheckSetupControllerTest.php 52 KB

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