You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CheckSetupControllerTest.php 51KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482
  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 Kyle Fazzari <kyrofa@ubuntu.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 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 OC;
  37. use OC\DB\Connection;
  38. use OC\IntegrityCheck\Checker;
  39. use OC\MemoryInfo;
  40. use OC\Security\SecureRandom;
  41. use OCA\Settings\Controller\CheckSetupController;
  42. use OCP\AppFramework\Http;
  43. use OCP\AppFramework\Http\DataDisplayResponse;
  44. use OCP\AppFramework\Http\DataResponse;
  45. use OCP\AppFramework\Http\RedirectResponse;
  46. use OCP\Http\Client\IClientService;
  47. use OCP\IConfig;
  48. use OCP\IDateTimeFormatter;
  49. use OCP\IL10N;
  50. use OCP\ILogger;
  51. use OCP\IRequest;
  52. use OCP\IURLGenerator;
  53. use OCP\Lock\ILockingProvider;
  54. use PHPUnit\Framework\MockObject\MockObject;
  55. use Psr\Http\Message\ResponseInterface;
  56. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  57. use Test\TestCase;
  58. /**
  59. * Class CheckSetupControllerTest
  60. *
  61. * @backupStaticAttributes
  62. * @package Tests\Settings\Controller
  63. */
  64. class CheckSetupControllerTest extends TestCase {
  65. /** @var CheckSetupController | \PHPUnit\Framework\MockObject\MockObject */
  66. private $checkSetupController;
  67. /** @var IRequest | \PHPUnit\Framework\MockObject\MockObject */
  68. private $request;
  69. /** @var IConfig | \PHPUnit\Framework\MockObject\MockObject */
  70. private $config;
  71. /** @var IClientService | \PHPUnit\Framework\MockObject\MockObject*/
  72. private $clientService;
  73. /** @var IURLGenerator | \PHPUnit\Framework\MockObject\MockObject */
  74. private $urlGenerator;
  75. /** @var IL10N | \PHPUnit\Framework\MockObject\MockObject */
  76. private $l10n;
  77. /** @var ILogger */
  78. private $logger;
  79. /** @var Checker|\PHPUnit\Framework\MockObject\MockObject */
  80. private $checker;
  81. /** @var EventDispatcherInterface|\PHPUnit\Framework\MockObject\MockObject */
  82. private $dispatcher;
  83. /** @var Connection|\PHPUnit\Framework\MockObject\MockObject */
  84. private $db;
  85. /** @var ILockingProvider|\PHPUnit\Framework\MockObject\MockObject */
  86. private $lockingProvider;
  87. /** @var IDateTimeFormatter|\PHPUnit\Framework\MockObject\MockObject */
  88. private $dateTimeFormatter;
  89. /** @var MemoryInfo|MockObject */
  90. private $memoryInfo;
  91. /** @var SecureRandom|\PHPUnit\Framework\MockObject\MockObject */
  92. private $secureRandom;
  93. /** @var IniGetWrapper|\PHPUnit\Framework\MockObject\MockObject */
  94. private $iniGetWrapper;
  95. /**
  96. * Holds a list of directories created during tests.
  97. *
  98. * @var array
  99. */
  100. private $dirsToRemove = [];
  101. protected function setUp(): void {
  102. parent::setUp();
  103. $this->request = $this->getMockBuilder(IRequest::class)
  104. ->disableOriginalConstructor()->getMock();
  105. $this->config = $this->getMockBuilder(IConfig::class)
  106. ->disableOriginalConstructor()->getMock();
  107. $this->clientService = $this->getMockBuilder(IClientService::class)
  108. ->disableOriginalConstructor()->getMock();
  109. $this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)
  110. ->disableOriginalConstructor()->getMock();
  111. $this->l10n = $this->getMockBuilder(IL10N::class)
  112. ->disableOriginalConstructor()->getMock();
  113. $this->l10n->expects($this->any())
  114. ->method('t')
  115. ->willReturnCallback(function ($message, array $replace) {
  116. return vsprintf($message, $replace);
  117. });
  118. $this->dispatcher = $this->getMockBuilder(EventDispatcherInterface::class)
  119. ->disableOriginalConstructor()->getMock();
  120. $this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker')
  121. ->disableOriginalConstructor()->getMock();
  122. $this->logger = $this->getMockBuilder(ILogger::class)->getMock();
  123. $this->db = $this->getMockBuilder(Connection::class)
  124. ->disableOriginalConstructor()->getMock();
  125. $this->lockingProvider = $this->getMockBuilder(ILockingProvider::class)->getMock();
  126. $this->dateTimeFormatter = $this->getMockBuilder(IDateTimeFormatter::class)->getMock();
  127. $this->memoryInfo = $this->getMockBuilder(MemoryInfo::class)
  128. ->setMethods(['isMemoryLimitSufficient',])
  129. ->getMock();
  130. $this->secureRandom = $this->getMockBuilder(SecureRandom::class)->getMock();
  131. $this->iniGetWrapper = $this->getMockBuilder(IniGetWrapper::class)->getMock();
  132. $this->checkSetupController = $this->getMockBuilder(CheckSetupController::class)
  133. ->setConstructorArgs([
  134. 'settings',
  135. $this->request,
  136. $this->config,
  137. $this->clientService,
  138. $this->urlGenerator,
  139. $this->l10n,
  140. $this->checker,
  141. $this->logger,
  142. $this->dispatcher,
  143. $this->db,
  144. $this->lockingProvider,
  145. $this->dateTimeFormatter,
  146. $this->memoryInfo,
  147. $this->secureRandom,
  148. $this->iniGetWrapper,
  149. ])
  150. ->setMethods([
  151. 'isReadOnlyConfig',
  152. 'hasValidTransactionIsolationLevel',
  153. 'hasFileinfoInstalled',
  154. 'hasWorkingFileLocking',
  155. 'getLastCronInfo',
  156. 'getSuggestedOverwriteCliURL',
  157. 'getCurlVersion',
  158. 'isPhpOutdated',
  159. 'isOpcacheProperlySetup',
  160. 'hasFreeTypeSupport',
  161. 'hasMissingIndexes',
  162. 'isSqliteUsed',
  163. 'isPHPMailerUsed',
  164. 'hasOpcacheLoaded',
  165. 'getAppDirsWithDifferentOwner',
  166. 'hasRecommendedPHPModules',
  167. 'hasBigIntConversionPendingColumns',
  168. 'isMysqlUsedWithoutUTF8MB4',
  169. 'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed',
  170. ])->getMock();
  171. }
  172. /**
  173. * Removes directories created during tests.
  174. *
  175. * @after
  176. * @return void
  177. */
  178. public function removeTestDirectories() {
  179. foreach ($this->dirsToRemove as $dirToRemove) {
  180. rmdir($dirToRemove);
  181. }
  182. $this->dirsToRemove = [];
  183. }
  184. public function testIsInternetConnectionWorkingDisabledViaConfig() {
  185. $this->config->expects($this->once())
  186. ->method('getSystemValue')
  187. ->with('has_internet_connection', true)
  188. ->willReturn(false);
  189. $this->assertFalse(
  190. self::invokePrivate(
  191. $this->checkSetupController,
  192. 'hasInternetConnectivityProblems'
  193. )
  194. );
  195. }
  196. public function testIsInternetConnectionWorkingCorrectly() {
  197. $this->config->expects($this->at(0))
  198. ->method('getSystemValue')
  199. ->with('has_internet_connection', true)
  200. ->willReturn(true);
  201. $this->config->expects($this->at(1))
  202. ->method('getSystemValue')
  203. ->with('connectivity_check_domains', ['www.nextcloud.com', 'www.startpage.com', 'www.eff.org', 'www.edri.org'])
  204. ->willReturn(['www.nextcloud.com', 'www.startpage.com', 'www.eff.org', 'www.edri.org']);
  205. $client = $this->getMockBuilder('\OCP\Http\Client\IClient')
  206. ->disableOriginalConstructor()->getMock();
  207. $client->expects($this->any())
  208. ->method('get');
  209. $this->clientService->expects($this->once())
  210. ->method('newClient')
  211. ->willReturn($client);
  212. $this->assertFalse(
  213. self::invokePrivate(
  214. $this->checkSetupController,
  215. 'hasInternetConnectivityProblems'
  216. )
  217. );
  218. }
  219. public function testIsInternetConnectionFail() {
  220. $this->config->expects($this->at(0))
  221. ->method('getSystemValue')
  222. ->with('has_internet_connection', true)
  223. ->willReturn(true);
  224. $this->config->expects($this->at(1))
  225. ->method('getSystemValue')
  226. ->with('connectivity_check_domains', ['www.nextcloud.com', 'www.startpage.com', 'www.eff.org', 'www.edri.org'])
  227. ->willReturn(['www.nextcloud.com', 'www.startpage.com', 'www.eff.org', 'www.edri.org']);
  228. $client = $this->getMockBuilder('\OCP\Http\Client\IClient')
  229. ->disableOriginalConstructor()->getMock();
  230. $client->expects($this->any())
  231. ->method('get')
  232. ->will($this->throwException(new \Exception()));
  233. $this->clientService->expects($this->exactly(4))
  234. ->method('newClient')
  235. ->willReturn($client);
  236. $this->assertTrue(
  237. self::invokePrivate(
  238. $this->checkSetupController,
  239. 'hasInternetConnectivityProblems'
  240. )
  241. );
  242. }
  243. public function testIsMemcacheConfiguredFalse() {
  244. $this->config->expects($this->once())
  245. ->method('getSystemValue')
  246. ->with('memcache.local', null)
  247. ->willReturn(null);
  248. $this->assertFalse(
  249. self::invokePrivate(
  250. $this->checkSetupController,
  251. 'isMemcacheConfigured'
  252. )
  253. );
  254. }
  255. public function testIsMemcacheConfiguredTrue() {
  256. $this->config->expects($this->once())
  257. ->method('getSystemValue')
  258. ->with('memcache.local', null)
  259. ->willReturn('SomeProvider');
  260. $this->assertTrue(
  261. self::invokePrivate(
  262. $this->checkSetupController,
  263. 'isMemcacheConfigured'
  264. )
  265. );
  266. }
  267. public function testIsPhpSupportedFalse() {
  268. $this->checkSetupController
  269. ->expects($this->once())
  270. ->method('isPhpOutdated')
  271. ->willReturn(true);
  272. $this->assertEquals(
  273. ['eol' => true, 'version' => PHP_VERSION],
  274. self::invokePrivate($this->checkSetupController, 'isPhpSupported')
  275. );
  276. }
  277. public function testIsPhpSupportedTrue() {
  278. $this->checkSetupController
  279. ->expects($this->exactly(2))
  280. ->method('isPhpOutdated')
  281. ->willReturn(false);
  282. $this->assertEquals(
  283. ['eol' => false, 'version' => PHP_VERSION],
  284. self::invokePrivate($this->checkSetupController, 'isPhpSupported')
  285. );
  286. $this->assertEquals(
  287. ['eol' => false, 'version' => PHP_VERSION],
  288. self::invokePrivate($this->checkSetupController, 'isPhpSupported')
  289. );
  290. }
  291. /**
  292. * @dataProvider dataForwardedForHeadersWorking
  293. *
  294. * @param array $trustedProxies
  295. * @param string $remoteAddrNotForwarded
  296. * @param string $remoteAddr
  297. * @param bool $result
  298. */
  299. public function testForwardedForHeadersWorking(array $trustedProxies, string $remoteAddrNotForwarded, string $remoteAddr, bool $result) {
  300. $this->config->expects($this->once())
  301. ->method('getSystemValue')
  302. ->with('trusted_proxies', [])
  303. ->willReturn($trustedProxies);
  304. $this->request->expects($this->atLeastOnce())
  305. ->method('getHeader')
  306. ->willReturnMap([
  307. ['REMOTE_ADDR', $remoteAddrNotForwarded],
  308. ['X-Forwarded-Host', '']
  309. ]);
  310. $this->request->expects($this->any())
  311. ->method('getRemoteAddress')
  312. ->willReturn($remoteAddr);
  313. $this->assertEquals(
  314. $result,
  315. self::invokePrivate($this->checkSetupController, 'forwardedForHeadersWorking')
  316. );
  317. }
  318. public function dataForwardedForHeadersWorking() {
  319. return [
  320. // description => trusted proxies, getHeader('REMOTE_ADDR'), getRemoteAddr, expected result
  321. 'no trusted proxies' => [[], '2.2.2.2', '2.2.2.2', true],
  322. 'trusted proxy, remote addr not trusted proxy' => [['1.1.1.1'], '2.2.2.2', '2.2.2.2', true],
  323. 'trusted proxy, remote addr is trusted proxy, x-forwarded-for working' => [['1.1.1.1'], '1.1.1.1', '2.2.2.2', true],
  324. '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],
  325. ];
  326. }
  327. public function testForwardedHostPresentButTrustedProxiesEmpty() {
  328. $this->config->expects($this->once())
  329. ->method('getSystemValue')
  330. ->with('trusted_proxies', [])
  331. ->willReturn([]);
  332. $this->request->expects($this->atLeastOnce())
  333. ->method('getHeader')
  334. ->willReturnMap([
  335. ['REMOTE_ADDR', '1.1.1.1'],
  336. ['X-Forwarded-Host', 'nextcloud.test']
  337. ]);
  338. $this->request->expects($this->any())
  339. ->method('getRemoteAddress')
  340. ->willReturn('1.1.1.1');
  341. $this->assertEquals(
  342. false,
  343. self::invokePrivate($this->checkSetupController, 'forwardedForHeadersWorking')
  344. );
  345. }
  346. public function testCheck() {
  347. $this->config->expects($this->at(0))
  348. ->method('getAppValue')
  349. ->with('core', 'cronErrors')
  350. ->willReturn('');
  351. $this->config->expects($this->at(2))
  352. ->method('getSystemValue')
  353. ->with('connectivity_check_domains', ['www.nextcloud.com', 'www.startpage.com', 'www.eff.org', 'www.edri.org'])
  354. ->willReturn(['www.nextcloud.com', 'www.startpage.com', 'www.eff.org', 'www.edri.org']);
  355. $this->config->expects($this->at(3))
  356. ->method('getSystemValue')
  357. ->with('memcache.local', null)
  358. ->willReturn('SomeProvider');
  359. $this->config->expects($this->at(4))
  360. ->method('getSystemValue')
  361. ->with('has_internet_connection', true)
  362. ->willReturn(true);
  363. $this->config->expects($this->at(5))
  364. ->method('getSystemValue')
  365. ->with('appstoreenabled', true)
  366. ->willReturn(false);
  367. $this->request->expects($this->atLeastOnce())
  368. ->method('getHeader')
  369. ->willReturnMap([
  370. ['REMOTE_ADDR', '4.3.2.1'],
  371. ['X-Forwarded-Host', '']
  372. ]);
  373. $client = $this->getMockBuilder('\OCP\Http\Client\IClient')
  374. ->disableOriginalConstructor()->getMock();
  375. $client->expects($this->at(0))
  376. ->method('get')
  377. ->with('http://www.nextcloud.com/', [])
  378. ->will($this->throwException(new \Exception()));
  379. $client->expects($this->at(1))
  380. ->method('get')
  381. ->with('http://www.startpage.com/', [])
  382. ->will($this->throwException(new \Exception()));
  383. $client->expects($this->at(2))
  384. ->method('get')
  385. ->with('http://www.eff.org/', [])
  386. ->will($this->throwException(new \Exception()));
  387. $client->expects($this->at(3))
  388. ->method('get')
  389. ->with('http://www.edri.org/', [])
  390. ->will($this->throwException(new \Exception()));
  391. $this->clientService->expects($this->exactly(4))
  392. ->method('newClient')
  393. ->willReturn($client);
  394. $this->checkSetupController
  395. ->expects($this->once())
  396. ->method('isPhpOutdated')
  397. ->willReturn(true);
  398. $this->checkSetupController
  399. ->expects($this->once())
  400. ->method('isOpcacheProperlySetup')
  401. ->willReturn(false);
  402. $this->checkSetupController
  403. ->method('hasFreeTypeSupport')
  404. ->willReturn(false);
  405. $this->checkSetupController
  406. ->method('hasMissingIndexes')
  407. ->willReturn([]);
  408. $this->checkSetupController
  409. ->method('isSqliteUsed')
  410. ->willReturn(false);
  411. $this->checkSetupController
  412. ->expects($this->once())
  413. ->method('isReadOnlyConfig')
  414. ->willReturn(false);
  415. $this->checkSetupController
  416. ->expects($this->once())
  417. ->method('hasValidTransactionIsolationLevel')
  418. ->willReturn(true);
  419. $this->checkSetupController
  420. ->expects($this->once())
  421. ->method('hasFileinfoInstalled')
  422. ->willReturn(true);
  423. $this->checkSetupController
  424. ->expects($this->once())
  425. ->method('hasOpcacheLoaded')
  426. ->willReturn(true);
  427. $this->checkSetupController
  428. ->expects($this->once())
  429. ->method('hasWorkingFileLocking')
  430. ->willReturn(true);
  431. $this->checkSetupController
  432. ->expects($this->once())
  433. ->method('getSuggestedOverwriteCliURL')
  434. ->willReturn('');
  435. $this->checkSetupController
  436. ->expects($this->once())
  437. ->method('getLastCronInfo')
  438. ->willReturn([
  439. 'diffInSeconds' => 123,
  440. 'relativeTime' => '2 hours ago',
  441. 'backgroundJobsUrl' => 'https://example.org',
  442. ]);
  443. $this->checkSetupController
  444. ->expects($this->once())
  445. ->method('isPHPMailerUsed')
  446. ->willReturn(false);
  447. $this->checker
  448. ->expects($this->once())
  449. ->method('hasPassedCheck')
  450. ->willReturn(true);
  451. $this->memoryInfo
  452. ->method('isMemoryLimitSufficient')
  453. ->willReturn(true);
  454. $this->checkSetupController
  455. ->expects($this->once())
  456. ->method('getAppDirsWithDifferentOwner')
  457. ->willReturn([]);
  458. $this->checkSetupController
  459. ->expects($this->once())
  460. ->method('hasRecommendedPHPModules')
  461. ->willReturn([]);
  462. $this->checkSetupController
  463. ->expects($this->once())
  464. ->method('hasBigIntConversionPendingColumns')
  465. ->willReturn([]);
  466. $this->checkSetupController
  467. ->expects($this->once())
  468. ->method('isMysqlUsedWithoutUTF8MB4')
  469. ->willReturn(false);
  470. $this->checkSetupController
  471. ->expects($this->once())
  472. ->method('isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed')
  473. ->willReturn(true);
  474. $this->urlGenerator->method('linkToDocs')
  475. ->willReturnCallback(function (string $key): string {
  476. if ($key === 'admin-performance') {
  477. return 'http://docs.example.org/server/go.php?to=admin-performance';
  478. }
  479. if ($key === 'admin-security') {
  480. return 'https://docs.example.org/server/8.1/admin_manual/configuration_server/hardening.html';
  481. }
  482. if ($key === 'admin-reverse-proxy') {
  483. return 'reverse-proxy-doc-link';
  484. }
  485. if ($key === 'admin-code-integrity') {
  486. return 'http://docs.example.org/server/go.php?to=admin-code-integrity';
  487. }
  488. if ($key === 'admin-php-opcache') {
  489. return 'http://docs.example.org/server/go.php?to=admin-php-opcache';
  490. }
  491. if ($key === 'admin-db-conversion') {
  492. return 'http://docs.example.org/server/go.php?to=admin-db-conversion';
  493. }
  494. return '';
  495. });
  496. $this->urlGenerator->method('getAbsoluteURL')
  497. ->willReturnCallback(function (string $url): string {
  498. if ($url === 'index.php/settings/admin') {
  499. return 'https://server/index.php/settings/admin';
  500. }
  501. if ($url === 'index.php') {
  502. return 'https://server/index.php';
  503. }
  504. return '';
  505. });
  506. $expected = new DataResponse(
  507. [
  508. 'isGetenvServerWorking' => true,
  509. 'isReadOnlyConfig' => false,
  510. 'hasValidTransactionIsolationLevel' => true,
  511. 'hasFileinfoInstalled' => true,
  512. 'hasWorkingFileLocking' => true,
  513. 'suggestedOverwriteCliURL' => '',
  514. 'cronInfo' => [
  515. 'diffInSeconds' => 123,
  516. 'relativeTime' => '2 hours ago',
  517. 'backgroundJobsUrl' => 'https://example.org',
  518. ],
  519. 'cronErrors' => [],
  520. 'serverHasInternetConnectionProblems' => true,
  521. 'isMemcacheConfigured' => true,
  522. 'memcacheDocs' => 'http://docs.example.org/server/go.php?to=admin-performance',
  523. 'isRandomnessSecure' => self::invokePrivate($this->checkSetupController, 'isRandomnessSecure'),
  524. 'securityDocs' => 'https://docs.example.org/server/8.1/admin_manual/configuration_server/hardening.html',
  525. 'isUsedTlsLibOutdated' => '',
  526. 'phpSupported' => [
  527. 'eol' => true,
  528. 'version' => PHP_VERSION
  529. ],
  530. 'forwardedForHeadersWorking' => true,
  531. 'reverseProxyDocs' => 'reverse-proxy-doc-link',
  532. 'isCorrectMemcachedPHPModuleInstalled' => true,
  533. 'hasPassedCodeIntegrityCheck' => true,
  534. 'codeIntegrityCheckerDocumentation' => 'http://docs.example.org/server/go.php?to=admin-code-integrity',
  535. 'isOpcacheProperlySetup' => false,
  536. 'hasOpcacheLoaded' => true,
  537. 'phpOpcacheDocumentation' => 'http://docs.example.org/server/go.php?to=admin-php-opcache',
  538. 'isSettimelimitAvailable' => true,
  539. 'hasFreeTypeSupport' => false,
  540. 'isSqliteUsed' => false,
  541. 'databaseConversionDocumentation' => 'http://docs.example.org/server/go.php?to=admin-db-conversion',
  542. 'missingIndexes' => [],
  543. 'missingColumns' => [],
  544. 'isPHPMailerUsed' => false,
  545. 'mailSettingsDocumentation' => 'https://server/index.php/settings/admin',
  546. 'isMemoryLimitSufficient' => true,
  547. 'appDirsWithDifferentOwner' => [],
  548. 'recommendedPHPModules' => [],
  549. 'pendingBigIntConversionColumns' => [],
  550. 'isMysqlUsedWithoutUTF8MB4' => false,
  551. 'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed' => true,
  552. 'reverseProxyGeneratedURL' => 'https://server/index.php',
  553. 'OCA\Settings\SetupChecks\PhpDefaultCharset' => ['pass' => true, 'description' => 'PHP configuration option default_charset should be UTF-8', 'severity' => 'warning'],
  554. 'OCA\Settings\SetupChecks\PhpOutputBuffering' => ['pass' => true, 'description' => 'PHP configuration option output_buffering must be disabled', 'severity' => 'error'],
  555. 'OCA\Settings\SetupChecks\LegacySSEKeyFormat' => ['pass' => true, 'description' => 'The old server-side-encryption format is enabled. We recommend disabling this.', 'severity' => 'warning', 'linkToDocumentation' => ''],
  556. ]
  557. );
  558. $this->assertEquals($expected, $this->checkSetupController->check());
  559. }
  560. public function testIsPHPMailerUsed() {
  561. $checkSetupController = $this->getMockBuilder(CheckSetupController::class)
  562. ->setConstructorArgs([
  563. 'settings',
  564. $this->request,
  565. $this->config,
  566. $this->clientService,
  567. $this->urlGenerator,
  568. $this->l10n,
  569. $this->checker,
  570. $this->logger,
  571. $this->dispatcher,
  572. $this->db,
  573. $this->lockingProvider,
  574. $this->dateTimeFormatter,
  575. $this->memoryInfo,
  576. $this->secureRandom,
  577. $this->iniGetWrapper,
  578. ])
  579. ->setMethods(null)->getMock();
  580. $this->config->expects($this->at(0))
  581. ->method('getSystemValue')
  582. ->with('mail_smtpmode', 'smtp')
  583. ->willReturn('php');
  584. $this->config->expects($this->at(1))
  585. ->method('getSystemValue')
  586. ->with('mail_smtpmode', 'smtp')
  587. ->willReturn('not-php');
  588. $this->assertTrue($this->invokePrivate($checkSetupController, 'isPHPMailerUsed'));
  589. $this->assertFalse($this->invokePrivate($checkSetupController, 'isPHPMailerUsed'));
  590. }
  591. public function testGetCurlVersion() {
  592. $checkSetupController = $this->getMockBuilder(CheckSetupController::class)
  593. ->setConstructorArgs([
  594. 'settings',
  595. $this->request,
  596. $this->config,
  597. $this->clientService,
  598. $this->urlGenerator,
  599. $this->l10n,
  600. $this->checker,
  601. $this->logger,
  602. $this->dispatcher,
  603. $this->db,
  604. $this->lockingProvider,
  605. $this->dateTimeFormatter,
  606. $this->memoryInfo,
  607. $this->secureRandom,
  608. $this->iniGetWrapper,
  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. );
  1286. $this->assertSame($expected, $this->invokePrivate($checkSetupController, 'isMysqlUsedWithoutUTF8MB4'));
  1287. }
  1288. public function dataForIsEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed() {
  1289. return [
  1290. ['singlebucket', 'OC\\Files\\ObjectStore\\Swift', true],
  1291. ['multibucket', 'OC\\Files\\ObjectStore\\Swift', true],
  1292. ['singlebucket', 'OC\\Files\\ObjectStore\\Custom', true],
  1293. ['multibucket', 'OC\Files\\ObjectStore\\Custom', true],
  1294. ['singlebucket', 'OC\Files\ObjectStore\Swift', true],
  1295. ['multibucket', 'OC\Files\ObjectStore\Swift', true],
  1296. ['singlebucket', 'OC\Files\ObjectStore\Custom', true],
  1297. ['multibucket', 'OC\Files\ObjectStore\Custom', true],
  1298. ];
  1299. }
  1300. /**
  1301. * @dataProvider dataForIsEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed
  1302. */
  1303. public function testIsEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed(string $mode, string $className, bool $expected) {
  1304. $this->config->method('getSystemValue')
  1305. ->willReturnCallback(function ($key, $default) use ($mode, $className) {
  1306. if ($key === 'objectstore' && $mode === 'singlebucket') {
  1307. return ['class' => $className];
  1308. }
  1309. if ($key === 'objectstore_multibucket' && $mode === 'multibucket') {
  1310. return ['class' => $className];
  1311. }
  1312. return $default;
  1313. });
  1314. $checkSetupController = new CheckSetupController(
  1315. 'settings',
  1316. $this->request,
  1317. $this->config,
  1318. $this->clientService,
  1319. $this->urlGenerator,
  1320. $this->l10n,
  1321. $this->checker,
  1322. $this->logger,
  1323. $this->dispatcher,
  1324. $this->db,
  1325. $this->lockingProvider,
  1326. $this->dateTimeFormatter,
  1327. $this->memoryInfo,
  1328. $this->secureRandom,
  1329. $this->iniGetWrapper
  1330. );
  1331. $this->assertSame($expected, $this->invokePrivate($checkSetupController, 'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed'));
  1332. }
  1333. }