CheckSetupControllerTest.php 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034
  1. <?php
  2. /**
  3. * @author Lukas Reschke <lukas@owncloud.com>
  4. *
  5. * @copyright Copyright (c) 2015, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace Tests\Settings\Controller;
  22. use OC\Settings\Controller\CheckSetupController;
  23. use OCP\AppFramework\Http;
  24. use OCP\AppFramework\Http\DataDisplayResponse;
  25. use OCP\AppFramework\Http\DataResponse;
  26. use OCP\AppFramework\Http\RedirectResponse;
  27. use OCP\Http\Client\IClientService;
  28. use OCP\IConfig;
  29. use OCP\IL10N;
  30. use OCP\ILogger;
  31. use OCP\IRequest;
  32. use OCP\IURLGenerator;
  33. use OC_Util;
  34. use Test\TestCase;
  35. use OC\IntegrityCheck\Checker;
  36. /**
  37. * Class CheckSetupControllerTest
  38. *
  39. * @package Tests\Settings\Controller
  40. */
  41. class CheckSetupControllerTest extends TestCase {
  42. /** @var CheckSetupController | \PHPUnit_Framework_MockObject_MockObject */
  43. private $checkSetupController;
  44. /** @var IRequest | \PHPUnit_Framework_MockObject_MockObject */
  45. private $request;
  46. /** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */
  47. private $config;
  48. /** @var IClientService | \PHPUnit_Framework_MockObject_MockObject*/
  49. private $clientService;
  50. /** @var IURLGenerator | \PHPUnit_Framework_MockObject_MockObject */
  51. private $urlGenerator;
  52. /** @var OC_Util */
  53. private $util;
  54. /** @var IL10N | \PHPUnit_Framework_MockObject_MockObject */
  55. private $l10n;
  56. /** @var ILogger */
  57. private $logger;
  58. /** @var Checker | \PHPUnit_Framework_MockObject_MockObject */
  59. private $checker;
  60. public function setUp() {
  61. parent::setUp();
  62. $this->request = $this->getMockBuilder('\OCP\IRequest')
  63. ->disableOriginalConstructor()->getMock();
  64. $this->config = $this->getMockBuilder('\OCP\IConfig')
  65. ->disableOriginalConstructor()->getMock();
  66. $this->config = $this->getMockBuilder('\OCP\IConfig')
  67. ->disableOriginalConstructor()->getMock();
  68. $this->clientService = $this->getMockBuilder('\OCP\Http\Client\IClientService')
  69. ->disableOriginalConstructor()->getMock();
  70. $this->util = $this->getMockBuilder('\OC_Util')
  71. ->disableOriginalConstructor()->getMock();
  72. $this->urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator')
  73. ->disableOriginalConstructor()->getMock();
  74. $this->l10n = $this->getMockBuilder('\OCP\IL10N')
  75. ->disableOriginalConstructor()->getMock();
  76. $this->l10n->expects($this->any())
  77. ->method('t')
  78. ->will($this->returnCallback(function($message, array $replace) {
  79. return vsprintf($message, $replace);
  80. }));
  81. $this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker')
  82. ->disableOriginalConstructor()->getMock();
  83. $this->logger = $this->getMockBuilder('\OCP\ILogger')->getMock();
  84. $this->checkSetupController = $this->getMockBuilder('\OC\Settings\Controller\CheckSetupController')
  85. ->setConstructorArgs([
  86. 'settings',
  87. $this->request,
  88. $this->config,
  89. $this->clientService,
  90. $this->urlGenerator,
  91. $this->util,
  92. $this->l10n,
  93. $this->checker,
  94. $this->logger
  95. ])
  96. ->setMethods(['getCurlVersion', 'isPhpOutdated'])->getMock();
  97. }
  98. public function testIsInternetConnectionWorkingDisabledViaConfig() {
  99. $this->config->expects($this->once())
  100. ->method('getSystemValue')
  101. ->with('has_internet_connection', true)
  102. ->will($this->returnValue(false));
  103. $this->assertFalse(
  104. self::invokePrivate(
  105. $this->checkSetupController,
  106. 'isInternetConnectionWorking'
  107. )
  108. );
  109. }
  110. public function testIsInternetConnectionWorkingCorrectly() {
  111. $this->config->expects($this->once())
  112. ->method('getSystemValue')
  113. ->with('has_internet_connection', true)
  114. ->will($this->returnValue(true));
  115. $client = $this->getMockBuilder('\OCP\Http\Client\IClient')
  116. ->disableOriginalConstructor()->getMock();
  117. $client->expects($this->any())
  118. ->method('get');
  119. $this->clientService->expects($this->once())
  120. ->method('newClient')
  121. ->will($this->returnValue($client));
  122. $this->assertTrue(
  123. self::invokePrivate(
  124. $this->checkSetupController,
  125. 'isInternetConnectionWorking'
  126. )
  127. );
  128. }
  129. public function testIsInternetConnectionFail() {
  130. $this->config->expects($this->once())
  131. ->method('getSystemValue')
  132. ->with('has_internet_connection', true)
  133. ->will($this->returnValue(true));
  134. $client = $this->getMockBuilder('\OCP\Http\Client\IClient')
  135. ->disableOriginalConstructor()->getMock();
  136. $client->expects($this->any())
  137. ->method('get')
  138. ->will($this->throwException(new \Exception()));
  139. $this->clientService->expects($this->exactly(3))
  140. ->method('newClient')
  141. ->will($this->returnValue($client));
  142. $this->assertFalse(
  143. self::invokePrivate(
  144. $this->checkSetupController,
  145. 'isInternetConnectionWorking'
  146. )
  147. );
  148. }
  149. public function testIsMemcacheConfiguredFalse() {
  150. $this->config->expects($this->once())
  151. ->method('getSystemValue')
  152. ->with('memcache.local', null)
  153. ->will($this->returnValue(null));
  154. $this->assertFalse(
  155. self::invokePrivate(
  156. $this->checkSetupController,
  157. 'isMemcacheConfigured'
  158. )
  159. );
  160. }
  161. public function testIsMemcacheConfiguredTrue() {
  162. $this->config->expects($this->once())
  163. ->method('getSystemValue')
  164. ->with('memcache.local', null)
  165. ->will($this->returnValue('SomeProvider'));
  166. $this->assertTrue(
  167. self::invokePrivate(
  168. $this->checkSetupController,
  169. 'isMemcacheConfigured'
  170. )
  171. );
  172. }
  173. public function testIsPhpSupportedFalse() {
  174. $this->checkSetupController
  175. ->expects($this->once())
  176. ->method('isPhpOutdated')
  177. ->willReturn(true);
  178. $this->assertEquals(
  179. ['eol' => true, 'version' => PHP_VERSION],
  180. self::invokePrivate($this->checkSetupController, 'isPhpSupported')
  181. );
  182. }
  183. public function testIsPhpSupportedTrue() {
  184. $this->checkSetupController
  185. ->expects($this->exactly(2))
  186. ->method('isPhpOutdated')
  187. ->willReturn(false);
  188. $this->assertEquals(
  189. ['eol' => false, 'version' => PHP_VERSION],
  190. self::invokePrivate($this->checkSetupController, 'isPhpSupported')
  191. );
  192. $this->assertEquals(
  193. ['eol' => false, 'version' => PHP_VERSION],
  194. self::invokePrivate($this->checkSetupController, 'isPhpSupported')
  195. );
  196. }
  197. public function testForwardedForHeadersWorkingFalse() {
  198. $this->config->expects($this->once())
  199. ->method('getSystemValue')
  200. ->with('trusted_proxies', [])
  201. ->willReturn(['1.2.3.4']);
  202. $this->request->expects($this->once())
  203. ->method('getRemoteAddress')
  204. ->willReturn('1.2.3.4');
  205. $this->assertFalse(
  206. self::invokePrivate(
  207. $this->checkSetupController,
  208. 'forwardedForHeadersWorking'
  209. )
  210. );
  211. }
  212. public function testForwardedForHeadersWorkingTrue() {
  213. $this->config->expects($this->once())
  214. ->method('getSystemValue')
  215. ->with('trusted_proxies', [])
  216. ->willReturn(['1.2.3.4']);
  217. $this->request->expects($this->once())
  218. ->method('getRemoteAddress')
  219. ->willReturn('4.3.2.1');
  220. $this->assertTrue(
  221. self::invokePrivate(
  222. $this->checkSetupController,
  223. 'forwardedForHeadersWorking'
  224. )
  225. );
  226. }
  227. public function testCheck() {
  228. $this->config->expects($this->at(0))
  229. ->method('getSystemValue')
  230. ->with('has_internet_connection', true)
  231. ->will($this->returnValue(true));
  232. $this->config->expects($this->at(1))
  233. ->method('getSystemValue')
  234. ->with('memcache.local', null)
  235. ->will($this->returnValue('SomeProvider'));
  236. $this->config->expects($this->at(2))
  237. ->method('getSystemValue')
  238. ->with('has_internet_connection', true)
  239. ->will($this->returnValue(false));
  240. $this->config->expects($this->at(3))
  241. ->method('getSystemValue')
  242. ->with('trusted_proxies', [])
  243. ->willReturn(['1.2.3.4']);
  244. $this->request->expects($this->once())
  245. ->method('getRemoteAddress')
  246. ->willReturn('4.3.2.1');
  247. $client = $this->getMockBuilder('\OCP\Http\Client\IClient')
  248. ->disableOriginalConstructor()->getMock();
  249. $client->expects($this->at(0))
  250. ->method('get')
  251. ->with('http://www.nextcloud.com/', [])
  252. ->will($this->throwException(new \Exception()));
  253. $client->expects($this->at(1))
  254. ->method('get')
  255. ->with('http://www.google.com/', [])
  256. ->will($this->throwException(new \Exception()));
  257. $client->expects($this->at(2))
  258. ->method('get')
  259. ->with('http://www.github.com/', [])
  260. ->will($this->throwException(new \Exception()));
  261. $this->clientService->expects($this->exactly(3))
  262. ->method('newClient')
  263. ->will($this->returnValue($client));
  264. $this->urlGenerator->expects($this->at(0))
  265. ->method('linkToDocs')
  266. ->with('admin-performance')
  267. ->willReturn('http://doc.owncloud.org/server/go.php?to=admin-performance');
  268. $this->urlGenerator->expects($this->at(1))
  269. ->method('linkToDocs')
  270. ->with('admin-security')
  271. ->willReturn('https://doc.owncloud.org/server/8.1/admin_manual/configuration_server/hardening.html');
  272. $this->checkSetupController
  273. ->expects($this->once())
  274. ->method('isPhpOutdated')
  275. ->willReturn(true);
  276. $this->urlGenerator->expects($this->at(2))
  277. ->method('linkToDocs')
  278. ->with('admin-reverse-proxy')
  279. ->willReturn('reverse-proxy-doc-link');
  280. $this->urlGenerator->expects($this->at(3))
  281. ->method('linkToDocs')
  282. ->with('admin-code-integrity')
  283. ->willReturn('http://doc.owncloud.org/server/go.php?to=admin-code-integrity');
  284. $this->urlGenerator->expects($this->at(4))
  285. ->method('linkToDocs')
  286. ->with('admin-php-opcache')
  287. ->willReturn('http://doc.owncloud.org/server/go.php?to=admin-php-opcache');
  288. $expected = new DataResponse(
  289. [
  290. 'serverHasInternetConnection' => false,
  291. 'isMemcacheConfigured' => true,
  292. 'memcacheDocs' => 'http://doc.owncloud.org/server/go.php?to=admin-performance',
  293. 'isUrandomAvailable' => self::invokePrivate($this->checkSetupController, 'isUrandomAvailable'),
  294. 'securityDocs' => 'https://doc.owncloud.org/server/8.1/admin_manual/configuration_server/hardening.html',
  295. 'isUsedTlsLibOutdated' => '',
  296. 'phpSupported' => [
  297. 'eol' => true,
  298. 'version' => PHP_VERSION
  299. ],
  300. 'forwardedForHeadersWorking' => true,
  301. 'reverseProxyDocs' => 'reverse-proxy-doc-link',
  302. 'isCorrectMemcachedPHPModuleInstalled' => true,
  303. 'hasPassedCodeIntegrityCheck' => null,
  304. 'codeIntegrityCheckerDocumentation' => 'http://doc.owncloud.org/server/go.php?to=admin-code-integrity',
  305. 'isOpcacheProperlySetup' => false,
  306. 'phpOpcacheDocumentation' => 'http://doc.owncloud.org/server/go.php?to=admin-php-opcache',
  307. 'isSettimelimitAvailable' => true,
  308. ]
  309. );
  310. $this->assertEquals($expected, $this->checkSetupController->check());
  311. }
  312. public function testGetCurlVersion() {
  313. $checkSetupController = $this->getMockBuilder('\OC\Settings\Controller\CheckSetupController')
  314. ->setConstructorArgs([
  315. 'settings',
  316. $this->request,
  317. $this->config,
  318. $this->clientService,
  319. $this->urlGenerator,
  320. $this->util,
  321. $this->l10n,
  322. $this->checker,
  323. $this->logger
  324. ])
  325. ->setMethods(null)->getMock();
  326. $this->assertArrayHasKey('ssl_version', $this->invokePrivate($checkSetupController, 'getCurlVersion'));
  327. }
  328. public function testIsUsedTlsLibOutdatedWithAnotherLibrary() {
  329. $this->config->expects($this->any())
  330. ->method('getSystemValue')
  331. ->will($this->returnValue(true));
  332. $this->checkSetupController
  333. ->expects($this->once())
  334. ->method('getCurlVersion')
  335. ->will($this->returnValue(['ssl_version' => 'SSLlib']));
  336. $this->assertSame('', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated'));
  337. }
  338. public function testIsUsedTlsLibOutdatedWithMisbehavingCurl() {
  339. $this->config->expects($this->any())
  340. ->method('getSystemValue')
  341. ->will($this->returnValue(true));
  342. $this->checkSetupController
  343. ->expects($this->once())
  344. ->method('getCurlVersion')
  345. ->will($this->returnValue([]));
  346. $this->assertSame('', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated'));
  347. }
  348. public function testIsUsedTlsLibOutdatedWithOlderOpenSsl() {
  349. $this->config->expects($this->any())
  350. ->method('getSystemValue')
  351. ->will($this->returnValue(true));
  352. $this->checkSetupController
  353. ->expects($this->once())
  354. ->method('getCurlVersion')
  355. ->will($this->returnValue(['ssl_version' => 'OpenSSL/1.0.1c']));
  356. $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'));
  357. }
  358. public function testIsUsedTlsLibOutdatedWithOlderOpenSslAndWithoutAppstore() {
  359. $this->config
  360. ->expects($this->at(0))
  361. ->method('getSystemValue')
  362. ->with('has_internet_connection', true)
  363. ->will($this->returnValue(true));
  364. $this->checkSetupController
  365. ->expects($this->once())
  366. ->method('getCurlVersion')
  367. ->will($this->returnValue(['ssl_version' => 'OpenSSL/1.0.1c']));
  368. $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'));
  369. }
  370. public function testIsUsedTlsLibOutdatedWithOlderOpenSsl1() {
  371. $this->config->expects($this->any())
  372. ->method('getSystemValue')
  373. ->will($this->returnValue(true));
  374. $this->checkSetupController
  375. ->expects($this->once())
  376. ->method('getCurlVersion')
  377. ->will($this->returnValue(['ssl_version' => 'OpenSSL/1.0.2a']));
  378. $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'));
  379. }
  380. public function testIsUsedTlsLibOutdatedWithMatchingOpenSslVersion() {
  381. $this->config->expects($this->any())
  382. ->method('getSystemValue')
  383. ->will($this->returnValue(true));
  384. $this->checkSetupController
  385. ->expects($this->once())
  386. ->method('getCurlVersion')
  387. ->will($this->returnValue(['ssl_version' => 'OpenSSL/1.0.1d']));
  388. $this->assertSame('', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated'));
  389. }
  390. public function testIsUsedTlsLibOutdatedWithMatchingOpenSslVersion1() {
  391. $this->config->expects($this->any())
  392. ->method('getSystemValue')
  393. ->will($this->returnValue(true));
  394. $this->checkSetupController
  395. ->expects($this->once())
  396. ->method('getCurlVersion')
  397. ->will($this->returnValue(['ssl_version' => 'OpenSSL/1.0.2b']));
  398. $this->assertSame('', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated'));
  399. }
  400. public function testIsBuggyNss400() {
  401. $this->config->expects($this->any())
  402. ->method('getSystemValue')
  403. ->will($this->returnValue(true));
  404. $this->checkSetupController
  405. ->expects($this->once())
  406. ->method('getCurlVersion')
  407. ->will($this->returnValue(['ssl_version' => 'NSS/1.0.2b']));
  408. $client = $this->getMockBuilder('\OCP\Http\Client\IClient')
  409. ->disableOriginalConstructor()->getMock();
  410. $exception = $this->getMockBuilder('\GuzzleHttp\Exception\ClientException')
  411. ->disableOriginalConstructor()->getMock();
  412. $response = $this->getMockBuilder('\GuzzleHttp\Message\ResponseInterface')
  413. ->disableOriginalConstructor()->getMock();
  414. $response->expects($this->once())
  415. ->method('getStatusCode')
  416. ->will($this->returnValue(400));
  417. $exception->expects($this->once())
  418. ->method('getResponse')
  419. ->will($this->returnValue($response));
  420. $client->expects($this->at(0))
  421. ->method('get')
  422. ->with('https://www.owncloud.org/', [])
  423. ->will($this->throwException($exception));
  424. $this->clientService->expects($this->once())
  425. ->method('newClient')
  426. ->will($this->returnValue($client));
  427. $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'));
  428. }
  429. public function testIsBuggyNss200() {
  430. $this->config->expects($this->any())
  431. ->method('getSystemValue')
  432. ->will($this->returnValue(true));
  433. $this->checkSetupController
  434. ->expects($this->once())
  435. ->method('getCurlVersion')
  436. ->will($this->returnValue(['ssl_version' => 'NSS/1.0.2b']));
  437. $client = $this->getMockBuilder('\OCP\Http\Client\IClient')
  438. ->disableOriginalConstructor()->getMock();
  439. $exception = $this->getMockBuilder('\GuzzleHttp\Exception\ClientException')
  440. ->disableOriginalConstructor()->getMock();
  441. $response = $this->getMockBuilder('\GuzzleHttp\Message\ResponseInterface')
  442. ->disableOriginalConstructor()->getMock();
  443. $response->expects($this->once())
  444. ->method('getStatusCode')
  445. ->will($this->returnValue(200));
  446. $exception->expects($this->once())
  447. ->method('getResponse')
  448. ->will($this->returnValue($response));
  449. $client->expects($this->at(0))
  450. ->method('get')
  451. ->with('https://www.owncloud.org/', [])
  452. ->will($this->throwException($exception));
  453. $this->clientService->expects($this->once())
  454. ->method('newClient')
  455. ->will($this->returnValue($client));
  456. $this->assertSame('', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated'));
  457. }
  458. public function testIsUsedTlsLibOutdatedWithInternetDisabled() {
  459. $this->config
  460. ->expects($this->at(0))
  461. ->method('getSystemValue')
  462. ->with('has_internet_connection', true)
  463. ->will($this->returnValue(false));
  464. $this->assertSame('', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated'));
  465. }
  466. public function testIsUsedTlsLibOutdatedWithAppstoreDisabledAndServerToServerSharingEnabled() {
  467. $this->config
  468. ->expects($this->at(0))
  469. ->method('getSystemValue')
  470. ->with('has_internet_connection', true)
  471. ->will($this->returnValue(true));
  472. $this->config
  473. ->expects($this->at(1))
  474. ->method('getSystemValue')
  475. ->with('appstoreenabled', true)
  476. ->will($this->returnValue(false));
  477. $this->config
  478. ->expects($this->at(2))
  479. ->method('getAppValue')
  480. ->with('files_sharing', 'outgoing_server2server_share_enabled', 'yes')
  481. ->will($this->returnValue('no'));
  482. $this->config
  483. ->expects($this->at(3))
  484. ->method('getAppValue')
  485. ->with('files_sharing', 'incoming_server2server_share_enabled', 'yes')
  486. ->will($this->returnValue('yes'));
  487. $this->checkSetupController
  488. ->expects($this->once())
  489. ->method('getCurlVersion')
  490. ->will($this->returnValue([]));
  491. $this->assertSame('', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated'));
  492. }
  493. public function testIsUsedTlsLibOutdatedWithAppstoreDisabledAndServerToServerSharingDisabled() {
  494. $this->config
  495. ->expects($this->at(0))
  496. ->method('getSystemValue')
  497. ->with('has_internet_connection', true)
  498. ->will($this->returnValue(true));
  499. $this->config
  500. ->expects($this->at(1))
  501. ->method('getSystemValue')
  502. ->with('appstoreenabled', true)
  503. ->will($this->returnValue(false));
  504. $this->config
  505. ->expects($this->at(2))
  506. ->method('getAppValue')
  507. ->with('files_sharing', 'outgoing_server2server_share_enabled', 'yes')
  508. ->will($this->returnValue('no'));
  509. $this->config
  510. ->expects($this->at(3))
  511. ->method('getAppValue')
  512. ->with('files_sharing', 'incoming_server2server_share_enabled', 'yes')
  513. ->will($this->returnValue('no'));
  514. $this->checkSetupController
  515. ->expects($this->never())
  516. ->method('getCurlVersion')
  517. ->will($this->returnValue([]));
  518. $this->assertSame('', $this->invokePrivate($this->checkSetupController, 'isUsedTlsLibOutdated'));
  519. }
  520. public function testRescanFailedIntegrityCheck() {
  521. $this->checker
  522. ->expects($this->once())
  523. ->method('runInstanceVerification');
  524. $this->urlGenerator
  525. ->expects($this->once())
  526. ->method('linkToRoute')
  527. ->with('settings.AdminSettings.index')
  528. ->will($this->returnValue('/admin'));
  529. $expected = new RedirectResponse('/admin');
  530. $this->assertEquals($expected, $this->checkSetupController->rescanFailedIntegrityCheck());
  531. }
  532. public function testGetFailedIntegrityCheckDisabled() {
  533. $this->checker
  534. ->expects($this->once())
  535. ->method('isCodeCheckEnforced')
  536. ->willReturn(false);
  537. $expected = new DataDisplayResponse('Integrity checker has been disabled. Integrity cannot be verified.');
  538. $this->assertEquals($expected, $this->checkSetupController->getFailedIntegrityCheckFiles());
  539. }
  540. public function testGetFailedIntegrityCheckFilesWithNoErrorsFound() {
  541. $this->checker
  542. ->expects($this->once())
  543. ->method('isCodeCheckEnforced')
  544. ->willReturn(true);
  545. $this->checker
  546. ->expects($this->once())
  547. ->method('getResults')
  548. ->will($this->returnValue([]));
  549. $expected = new DataDisplayResponse(
  550. 'No errors have been found.',
  551. Http::STATUS_OK,
  552. [
  553. 'Content-Type' => 'text/plain',
  554. ]
  555. );
  556. $this->assertEquals($expected, $this->checkSetupController->getFailedIntegrityCheckFiles());
  557. }
  558. public function testGetFailedIntegrityCheckFilesWithSomeErrorsFound() {
  559. $this->checker
  560. ->expects($this->once())
  561. ->method('isCodeCheckEnforced')
  562. ->willReturn(true);
  563. $this->checker
  564. ->expects($this->once())
  565. ->method('getResults')
  566. ->will($this->returnValue(array ( 'core' => array ( 'EXTRA_FILE' => array('/testfile' => array()), 'INVALID_HASH' => array ( '/.idea/workspace.xml' => array ( 'expected' => 'f1c5e2630d784bc9cb02d5a28f55d6f24d06dae2a0fee685f3c2521b050955d9d452769f61454c9ddfa9c308146ade10546cfa829794448eaffbc9a04a29d216', 'current' => 'ce08bf30bcbb879a18b49239a9bec6b8702f52452f88a9d32142cad8d2494d5735e6bfa0d8642b2762c62ca5be49f9bf4ec231d4a230559d4f3e2c471d3ea094', ), '/lib/private/integritycheck/checker.php' => array ( 'expected' => 'c5a03bacae8dedf8b239997901ba1fffd2fe51271d13a00cc4b34b09cca5176397a89fc27381cbb1f72855fa18b69b6f87d7d5685c3b45aee373b09be54742ea', 'current' => '88a3a92c11db91dec1ac3be0e1c87f862c95ba6ffaaaa3f2c3b8f682187c66f07af3a3b557a868342ef4a271218fe1c1e300c478e6c156c5955ed53c40d06585', ), '/settings/controller/checksetupcontroller.php' => array ( 'expected' => '3e1de26ce93c7bfe0ede7c19cb6c93cadc010340225b375607a7178812e9de163179b0dc33809f451e01f491d93f6f5aaca7929685d21594cccf8bda732327c4', 'current' => '09563164f9904a837f9ca0b5f626db56c838e5098e0ccc1d8b935f68fa03a25c5ec6f6b2d9e44a868e8b85764dafd1605522b4af8db0ae269d73432e9a01e63a', ), ), ), 'bookmarks' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'dav' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'encryption' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'external' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'federation' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'files' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'files_antivirus' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'files_drop' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'files_external' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'files_pdfviewer' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'files_sharing' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'files_trashbin' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'files_versions' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'files_videoviewer' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'firstrunwizard' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'gitsmart' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'logreader' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature could not get verified.', ), ), 'password_policy' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'provisioning_api' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'sketch' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'threatblock' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'two_factor_auth' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'user_ldap' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), 'user_shibboleth' => array ( 'EXCEPTION' => array ( 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException', 'message' => 'Signature data not found.', ), ), )));
  567. $expected = new DataDisplayResponse(
  568. 'Technical information
  569. =====================
  570. The following list covers which files have failed the integrity check. Please read
  571. the previous linked documentation to learn more about the errors and how to fix
  572. them.
  573. Results
  574. =======
  575. - core
  576. - EXTRA_FILE
  577. - /testfile
  578. - INVALID_HASH
  579. - /.idea/workspace.xml
  580. - /lib/private/integritycheck/checker.php
  581. - /settings/controller/checksetupcontroller.php
  582. - bookmarks
  583. - EXCEPTION
  584. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  585. - Signature data not found.
  586. - dav
  587. - EXCEPTION
  588. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  589. - Signature data not found.
  590. - encryption
  591. - EXCEPTION
  592. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  593. - Signature data not found.
  594. - external
  595. - EXCEPTION
  596. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  597. - Signature data not found.
  598. - federation
  599. - EXCEPTION
  600. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  601. - Signature data not found.
  602. - files
  603. - EXCEPTION
  604. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  605. - Signature data not found.
  606. - files_antivirus
  607. - EXCEPTION
  608. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  609. - Signature data not found.
  610. - files_drop
  611. - EXCEPTION
  612. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  613. - Signature data not found.
  614. - files_external
  615. - EXCEPTION
  616. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  617. - Signature data not found.
  618. - files_pdfviewer
  619. - EXCEPTION
  620. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  621. - Signature data not found.
  622. - files_sharing
  623. - EXCEPTION
  624. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  625. - Signature data not found.
  626. - files_trashbin
  627. - EXCEPTION
  628. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  629. - Signature data not found.
  630. - files_versions
  631. - EXCEPTION
  632. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  633. - Signature data not found.
  634. - files_videoviewer
  635. - EXCEPTION
  636. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  637. - Signature data not found.
  638. - firstrunwizard
  639. - EXCEPTION
  640. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  641. - Signature data not found.
  642. - gitsmart
  643. - EXCEPTION
  644. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  645. - Signature data not found.
  646. - logreader
  647. - EXCEPTION
  648. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  649. - Signature could not get verified.
  650. - password_policy
  651. - EXCEPTION
  652. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  653. - Signature data not found.
  654. - provisioning_api
  655. - EXCEPTION
  656. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  657. - Signature data not found.
  658. - sketch
  659. - EXCEPTION
  660. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  661. - Signature data not found.
  662. - threatblock
  663. - EXCEPTION
  664. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  665. - Signature data not found.
  666. - two_factor_auth
  667. - EXCEPTION
  668. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  669. - Signature data not found.
  670. - user_ldap
  671. - EXCEPTION
  672. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  673. - Signature data not found.
  674. - user_shibboleth
  675. - EXCEPTION
  676. - OC\IntegrityCheck\Exceptions\InvalidSignatureException
  677. - Signature data not found.
  678. Raw output
  679. ==========
  680. Array
  681. (
  682. [core] => Array
  683. (
  684. [EXTRA_FILE] => Array
  685. (
  686. [/testfile] => Array
  687. (
  688. )
  689. )
  690. [INVALID_HASH] => Array
  691. (
  692. [/.idea/workspace.xml] => Array
  693. (
  694. [expected] => f1c5e2630d784bc9cb02d5a28f55d6f24d06dae2a0fee685f3c2521b050955d9d452769f61454c9ddfa9c308146ade10546cfa829794448eaffbc9a04a29d216
  695. [current] => ce08bf30bcbb879a18b49239a9bec6b8702f52452f88a9d32142cad8d2494d5735e6bfa0d8642b2762c62ca5be49f9bf4ec231d4a230559d4f3e2c471d3ea094
  696. )
  697. [/lib/private/integritycheck/checker.php] => Array
  698. (
  699. [expected] => c5a03bacae8dedf8b239997901ba1fffd2fe51271d13a00cc4b34b09cca5176397a89fc27381cbb1f72855fa18b69b6f87d7d5685c3b45aee373b09be54742ea
  700. [current] => 88a3a92c11db91dec1ac3be0e1c87f862c95ba6ffaaaa3f2c3b8f682187c66f07af3a3b557a868342ef4a271218fe1c1e300c478e6c156c5955ed53c40d06585
  701. )
  702. [/settings/controller/checksetupcontroller.php] => Array
  703. (
  704. [expected] => 3e1de26ce93c7bfe0ede7c19cb6c93cadc010340225b375607a7178812e9de163179b0dc33809f451e01f491d93f6f5aaca7929685d21594cccf8bda732327c4
  705. [current] => 09563164f9904a837f9ca0b5f626db56c838e5098e0ccc1d8b935f68fa03a25c5ec6f6b2d9e44a868e8b85764dafd1605522b4af8db0ae269d73432e9a01e63a
  706. )
  707. )
  708. )
  709. [bookmarks] => Array
  710. (
  711. [EXCEPTION] => Array
  712. (
  713. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  714. [message] => Signature data not found.
  715. )
  716. )
  717. [dav] => Array
  718. (
  719. [EXCEPTION] => Array
  720. (
  721. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  722. [message] => Signature data not found.
  723. )
  724. )
  725. [encryption] => Array
  726. (
  727. [EXCEPTION] => Array
  728. (
  729. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  730. [message] => Signature data not found.
  731. )
  732. )
  733. [external] => Array
  734. (
  735. [EXCEPTION] => Array
  736. (
  737. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  738. [message] => Signature data not found.
  739. )
  740. )
  741. [federation] => Array
  742. (
  743. [EXCEPTION] => Array
  744. (
  745. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  746. [message] => Signature data not found.
  747. )
  748. )
  749. [files] => Array
  750. (
  751. [EXCEPTION] => Array
  752. (
  753. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  754. [message] => Signature data not found.
  755. )
  756. )
  757. [files_antivirus] => Array
  758. (
  759. [EXCEPTION] => Array
  760. (
  761. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  762. [message] => Signature data not found.
  763. )
  764. )
  765. [files_drop] => Array
  766. (
  767. [EXCEPTION] => Array
  768. (
  769. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  770. [message] => Signature data not found.
  771. )
  772. )
  773. [files_external] => Array
  774. (
  775. [EXCEPTION] => Array
  776. (
  777. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  778. [message] => Signature data not found.
  779. )
  780. )
  781. [files_pdfviewer] => Array
  782. (
  783. [EXCEPTION] => Array
  784. (
  785. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  786. [message] => Signature data not found.
  787. )
  788. )
  789. [files_sharing] => Array
  790. (
  791. [EXCEPTION] => Array
  792. (
  793. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  794. [message] => Signature data not found.
  795. )
  796. )
  797. [files_trashbin] => Array
  798. (
  799. [EXCEPTION] => Array
  800. (
  801. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  802. [message] => Signature data not found.
  803. )
  804. )
  805. [files_versions] => Array
  806. (
  807. [EXCEPTION] => Array
  808. (
  809. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  810. [message] => Signature data not found.
  811. )
  812. )
  813. [files_videoviewer] => Array
  814. (
  815. [EXCEPTION] => Array
  816. (
  817. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  818. [message] => Signature data not found.
  819. )
  820. )
  821. [firstrunwizard] => Array
  822. (
  823. [EXCEPTION] => Array
  824. (
  825. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  826. [message] => Signature data not found.
  827. )
  828. )
  829. [gitsmart] => Array
  830. (
  831. [EXCEPTION] => Array
  832. (
  833. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  834. [message] => Signature data not found.
  835. )
  836. )
  837. [logreader] => Array
  838. (
  839. [EXCEPTION] => Array
  840. (
  841. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  842. [message] => Signature could not get verified.
  843. )
  844. )
  845. [password_policy] => Array
  846. (
  847. [EXCEPTION] => Array
  848. (
  849. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  850. [message] => Signature data not found.
  851. )
  852. )
  853. [provisioning_api] => Array
  854. (
  855. [EXCEPTION] => Array
  856. (
  857. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  858. [message] => Signature data not found.
  859. )
  860. )
  861. [sketch] => Array
  862. (
  863. [EXCEPTION] => Array
  864. (
  865. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  866. [message] => Signature data not found.
  867. )
  868. )
  869. [threatblock] => Array
  870. (
  871. [EXCEPTION] => Array
  872. (
  873. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  874. [message] => Signature data not found.
  875. )
  876. )
  877. [two_factor_auth] => Array
  878. (
  879. [EXCEPTION] => Array
  880. (
  881. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  882. [message] => Signature data not found.
  883. )
  884. )
  885. [user_ldap] => Array
  886. (
  887. [EXCEPTION] => Array
  888. (
  889. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  890. [message] => Signature data not found.
  891. )
  892. )
  893. [user_shibboleth] => Array
  894. (
  895. [EXCEPTION] => Array
  896. (
  897. [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
  898. [message] => Signature data not found.
  899. )
  900. )
  901. )
  902. ',
  903. Http::STATUS_OK,
  904. [
  905. 'Content-Type' => 'text/plain',
  906. ]
  907. );
  908. $this->assertEquals($expected, $this->checkSetupController->getFailedIntegrityCheckFiles());
  909. }
  910. }