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 50KB

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