CheckSetupControllerTest.php 53 KB

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