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

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