1
0

InstallerTest.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. <?php
  2. /**
  3. * Copyright (c) 2014 Georg Ehrke <georg@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace Test;
  9. use OC\App\AppStore\Bundles\Bundle;
  10. use OC\App\AppStore\Fetcher\AppFetcher;
  11. use OC\Archive\ZIP;
  12. use OC\Installer;
  13. use OCP\Http\Client\IClient;
  14. use OCP\Http\Client\IClientService;
  15. use OCP\IConfig;
  16. use OCP\ILogger;
  17. use OCP\ITempManager;
  18. /**
  19. * Class InstallerTest
  20. *
  21. * @package Test
  22. * @group DB
  23. */
  24. class InstallerTest extends TestCase {
  25. private static $appid = 'testapp';
  26. private $appstore;
  27. /** @var AppFetcher|\PHPUnit_Framework_MockObject_MockObject */
  28. private $appFetcher;
  29. /** @var IClientService|\PHPUnit_Framework_MockObject_MockObject */
  30. private $clientService;
  31. /** @var ITempManager|\PHPUnit_Framework_MockObject_MockObject */
  32. private $tempManager;
  33. /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
  34. private $logger;
  35. /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
  36. private $config;
  37. protected function setUp() {
  38. parent::setUp();
  39. $this->appFetcher = $this->createMock(AppFetcher::class);
  40. $this->clientService = $this->createMock(IClientService::class);
  41. $this->tempManager = $this->createMock(ITempManager::class);
  42. $this->logger = $this->createMock(ILogger::class);
  43. $this->config = $this->createMock(IConfig::class);
  44. $config = \OC::$server->getConfig();
  45. $this->appstore = $config->setSystemValue('appstoreenabled', true);
  46. $config->setSystemValue('appstoreenabled', true);
  47. $installer = new Installer(
  48. \OC::$server->getAppFetcher(),
  49. \OC::$server->getHTTPClientService(),
  50. \OC::$server->getTempManager(),
  51. \OC::$server->getLogger(),
  52. $config
  53. );
  54. $installer->removeApp(self::$appid);
  55. }
  56. protected function getInstaller() {
  57. return new Installer(
  58. $this->appFetcher,
  59. $this->clientService,
  60. $this->tempManager,
  61. $this->logger,
  62. $this->config
  63. );
  64. }
  65. protected function tearDown() {
  66. $installer = new Installer(
  67. \OC::$server->getAppFetcher(),
  68. \OC::$server->getHTTPClientService(),
  69. \OC::$server->getTempManager(),
  70. \OC::$server->getLogger(),
  71. \OC::$server->getConfig()
  72. );
  73. $installer->removeApp(self::$appid);
  74. \OC::$server->getConfig()->setSystemValue('appstoreenabled', $this->appstore);
  75. parent::tearDown();
  76. }
  77. public function testInstallApp() {
  78. // Read the current version of the app to check for bug #2572
  79. \OC_App::getAppVersion('testapp');
  80. // Extract app
  81. $pathOfTestApp = __DIR__ . '/../data/testapp.zip';
  82. $tar = new ZIP($pathOfTestApp);
  83. $tar->extract(\OC_App::getInstallPath());
  84. // Install app
  85. $installer = new Installer(
  86. \OC::$server->getAppFetcher(),
  87. \OC::$server->getHTTPClientService(),
  88. \OC::$server->getTempManager(),
  89. \OC::$server->getLogger(),
  90. \OC::$server->getConfig()
  91. );
  92. $this->assertNull(\OC::$server->getConfig()->getAppValue('testapp', 'enabled', null), 'Check that the app is not listed before installation');
  93. $this->assertSame('testapp', $installer->installApp(self::$appid));
  94. $this->assertSame('no', \OC::$server->getConfig()->getAppValue('testapp', 'enabled', null), 'Check that the app is listed after installation');
  95. $this->assertSame('0.9', \OC::$server->getConfig()->getAppValue('testapp', 'installed_version'));
  96. $installer->removeApp(self::$appid);
  97. }
  98. public function updateArrayProvider() {
  99. return [
  100. // Update available
  101. [
  102. [
  103. [
  104. 'id' => 'files',
  105. 'releases' => [
  106. [
  107. 'version' => '1111.0'
  108. ],
  109. ],
  110. ],
  111. ],
  112. '1111.0',
  113. ],
  114. // No update available
  115. [
  116. [
  117. [
  118. 'id' => 'files',
  119. 'releases' => [
  120. [
  121. 'version' => '1.0'
  122. ],
  123. ],
  124. ],
  125. ],
  126. false,
  127. ],
  128. ];
  129. }
  130. /**
  131. * @dataProvider updateArrayProvider
  132. * @param array $appArray
  133. * @param string|bool $updateAvailable
  134. */
  135. public function testIsUpdateAvailable(array $appArray, $updateAvailable) {
  136. $this->appFetcher
  137. ->expects($this->once())
  138. ->method('get')
  139. ->willReturn($appArray);
  140. $installer = $this->getInstaller();
  141. $this->assertSame($updateAvailable, $installer->isUpdateAvailable('files'));
  142. $this->assertSame($updateAvailable, $installer->isUpdateAvailable('files'), 'Cached result should be returned and fetcher should be only called once');
  143. }
  144. /**
  145. * @expectedException \Exception
  146. * @expectedExceptionMessage Certificate "4112" has been revoked
  147. */
  148. public function testDownloadAppWithRevokedCertificate() {
  149. $appArray = [
  150. [
  151. 'id' => 'news',
  152. 'certificate' => '-----BEGIN CERTIFICATE-----
  153. MIIEAjCCAuoCAhAQMA0GCSqGSIb3DQEBCwUAMHsxCzAJBgNVBAYTAkRFMRswGQYD
  154. VQQIDBJCYWRlbi1XdWVydHRlbWJlcmcxFzAVBgNVBAoMDk5leHRjbG91ZCBHbWJI
  155. MTYwNAYDVQQDDC1OZXh0Y2xvdWQgQ29kZSBTaWduaW5nIEludGVybWVkaWF0ZSBB
  156. dXRob3JpdHkwHhcNMTYxMDAzMTMyNDM3WhcNMjcwMTA5MTMyNDM3WjASMRAwDgYD
  157. VQQDDAdwYXNzbWFuMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEApEt+
  158. KZGs+WqdZkHZflzqk+ophYWB8qB47XCzy+xdTGPFM84/9wXltRPbcQQWJJl5aOx0
  159. FPbsyTGhIt/IYZ2Vl0XrDRJjsaxzPcrofrwpJ2tqforXjGohl6mZUBA0ESzFiPzT
  160. SAZe8E14+Jk8rbF/ecrkqcWf2cTMV3Qfu9YvJo8WVs4lHc95r1F+Nalh/OLkHkzb
  161. fYPno2Z5cco6U7BXunFQG2gqy3wWQwmlhDxh5fwrCoFzPWm7WhwSyK+eMoSDz+Vp
  162. 3kmtyijsqnda0zA9bfNzgW26czbJaObbnkdtDC2nfoAWXndlS/5YRI8yHd9miB5C
  163. u1OC8LUWToDGNa9+FOxBSj7Nk6iyjbVfRXcTqThdkVZdOOPaBRMsL9R4UYywCbhA
  164. yGNiQ0ahfXD8MZSb08rlQg8tAtcUZW1sYQcbtMGnu8OyC5J7N1efzv5mys4+9hBS
  165. 5ECeyCuQTuOkF4H/XS2BMSFZWF2xh7wzhMLca+5yauDW4i8baFEv74QTeY1DADgI
  166. Lz29NJ6z9xYzEnPesjNrwIcJwIjV52EkdLTi+EIf83UjXLQdwDbLxu76qxqP7K0I
  167. oMmwbl7UNA0wzq7nmgRhvqhow5RoCaSJjTz0EYQVSa1xelwiKeJiSKj2G9Mgt5Ms
  168. Miuy3C3VAGvQJ2ocILPGOt54oVeNRFLpnCo1e3sCAwEAATANBgkqhkiG9w0BAQsF
  169. AAOCAQEAkGYtg21rGpUVT/AokGUfI0PeyYAkcXKy2yuBAzfRk+uIXnRR0vK+OMpx
  170. shBoYGR3JEGUHZcMTRh8wjAZ0wuyYlQONtJbFFF3bCfODXxCsw0Vm8/Ms+KCmE4Z
  171. SyQafWEQf1sdqNw4VS4DYS2mlpDgAl+U9UY6HQKuT3+GFIxCsQSdS0GTaiYVKPVE
  172. p/eKou739h+5dM4FEhIYZX+7PWlHmX6wPCFAjgNu3kiRGmF6LKmCNNXTySATEP86
  173. tczQMzLtVdTg5z8XMi//6TkAPxRPjYi8Vef/s2mLo7KystTmofxI/HZePSieJ9tj
  174. gLgK8d8sKL60JMmKHN3boHrsThKBVA==
  175. -----END CERTIFICATE-----',
  176. ],
  177. ];
  178. $this->appFetcher
  179. ->expects($this->once())
  180. ->method('get')
  181. ->willReturn($appArray);
  182. $installer = $this->getInstaller();
  183. $installer->downloadApp('news');
  184. }
  185. /**
  186. * @expectedException \Exception
  187. * @expectedExceptionMessage App with id news has a certificate not issued by a trusted Code Signing Authority
  188. */
  189. public function testDownloadAppWithNotNextcloudCertificate() {
  190. $appArray = [
  191. [
  192. 'id' => 'news',
  193. 'certificate' => '-----BEGIN CERTIFICATE-----
  194. MIID8TCCAdkCAhAAMA0GCSqGSIb3DQEBCwUAMG0xCzAJBgNVBAYTAlVTMQ8wDQYD
  195. VQQIDAZCb3N0b24xFjAUBgNVBAoMDW93bkNsb3VkIEluYy4xNTAzBgNVBAMMLG93
  196. bkNsb3VkIENvZGUgU2lnbmluZyBJbnRlcm1lZGlhdGUgQXV0aG9yaXR5MB4XDTE2
  197. MDIwMzE3NTE0OVoXDTI2MDEzMTE3NTE0OVowDzENMAsGA1UEAwwEY29yZTCCASIw
  198. DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAPHdSljnHI+ueQd27UyWPO9n4Lqt
  199. bK0kdekiC3si7Mee7uXXJaGuqXJozHEZYB1LIFLdCU/itCxEk9hyLcyNzeT+nRT/
  200. zDuOYdbLgCj7/A5bX+u3jc29UlCYybSFchfMdvn7a0njCna4dE+73b4yEj16tS2h
  201. S1EUygSzgicWlJqMD3Z9Qc+zLEpdhq9oDdDB8HURi2NW4KzIraVncSH+zF1QduOh
  202. nERDnF8x48D3FLdTxGA0W/Kg4gYsq4NRvU6g3DJNdp4YfqRSFMmLFDCgzDuhan7D
  203. wgRlI9NAeHbnyoUPtrDBUceI7shIbC/i87xk9ptqV0AyFonkJtK6lWwZjNkCAwEA
  204. ATANBgkqhkiG9w0BAQsFAAOCAgEAAMgymqZE1YaHYlRGwvTE7gGDY3gmFOMaxQL4
  205. E5m0CnkBz4BdIPRsQFFdOv3l/MIWkw5ED3vUB925VpQZYFSiEuv5NbnlPaHZlIMI
  206. n8AV/sTP5jue3LhtAN4EM63xNBhudAT6wVsvGwOuQOx9Xv+ptO8Po7sTuNYP0CMH
  207. EOQN+/q8tYlSm2VW+dAlaJ+zVZwZldhVjL+lSH4E9ktWn3PmgNQeKfcnJISUbus6
  208. ZtsYDF/X96/Z2ZQvMXOKksgvU6XlvIxllcyebC9Bxe/h0D63GCO2tqN5CWQzIIqn
  209. apUynPX8BlLaaExqYGERwlUi/yOGaUVPUjEPVehviOQYgAqxlrkJk1dWeCrwUori
  210. CXpi+IUYkidfgiJ9F88M3ElpwqIaXp7G3/4oHBuE2u6M+L+1/vqPJeTCAWUxxpJE
  211. yYmM+db6D4TySFpQPENNzPS8bpR6T8w2hRumkldC42HrnyJJbpjOieTXhXzjdPvZ
  212. IEP9JGtkhB2du6nBF2MNAq2TqRXpcfQrQEbnQ13aV9bl+roTwwO+SOWK/wgvdOMI
  213. STQ0Xk0sTGlmQjPYPkibVceaWMR3sX4cNt5c33YhJys5jxHoAh42km4nN9tfykR5
  214. crl5lBlKjXh2GP0+omSO3x1jX4+iQPCW2TWoyKkUdLu/hGHG2w8RrTeme+kATECH
  215. YSu356M=
  216. -----END CERTIFICATE-----',
  217. ],
  218. ];
  219. $this->appFetcher
  220. ->expects($this->once())
  221. ->method('get')
  222. ->willReturn($appArray);
  223. $installer = $this->getInstaller();
  224. $installer->downloadApp('news');
  225. }
  226. /**
  227. * @expectedException \Exception
  228. * @expectedExceptionMessage App with id news has a cert issued to passman
  229. */
  230. public function testDownloadAppWithDifferentCN() {
  231. $appArray = [
  232. [
  233. 'id' => 'news',
  234. 'certificate' => '-----BEGIN CERTIFICATE-----
  235. MIIEAjCCAuoCAhAYMA0GCSqGSIb3DQEBCwUAMHsxCzAJBgNVBAYTAkRFMRswGQYD
  236. VQQIDBJCYWRlbi1XdWVydHRlbWJlcmcxFzAVBgNVBAoMDk5leHRjbG91ZCBHbWJI
  237. MTYwNAYDVQQDDC1OZXh0Y2xvdWQgQ29kZSBTaWduaW5nIEludGVybWVkaWF0ZSBB
  238. dXRob3JpdHkwHhcNMTYxMDE5MTkzNTEyWhcNMjcwMTI1MTkzNTEyWjASMRAwDgYD
  239. VQQDDAdwYXNzbWFuMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA1Jw1
  240. 8F0DefogaLaBudGbhK2zcFIBSzxhh7dRWguZKHGE+rG00BOvFLIAo37Bfmy9WKLc
  241. 3BFYvuFBowaVdaFOLxQJod0sOTmVMXhwoY5e3Xx+P+nsAw1/0gI10/LD1Vgl6i1u
  242. gMocmnbEYhKwr0NbdiQiMI9UB9Ge/51wt4WtAxwK7yJFl3+5qzvJgfX75Wt+8L1e
  243. Wk0LpVW23tUueJovjYZJXyAtohNaV3gwiST+QmKljCd4gwGX9abqfc76/lWtS+hI
  244. rKptuICc55ffH30rqVhAgCMouF/Ml5Qru8tDen5dSNtmAXz89OlDNisP+9HL4WDZ
  245. wvgps0mm/OYAUAQln24uXPDmAX/H2P5xIDHAa8avsqdgmHiqnLr4GYD8JYeb8GmB
  246. zZ38hEMjCr2F1k1h9T1+SyfRiDPDqqv1mBtcvNVc1JmZvSikMxhtQbU0C4/o2SBG
  247. RPCirknfPeKu8wBi6gvH4/SK0XTyuM8H58b9AKxzoo/wLbQ668+faLYyMSzCvsZD
  248. eeZkiO85y87Ax57WRY93arccCMaUeks/cTriNw3JrvdDyb2SeQOX9JUp0orUlC64
  249. AzK2xhXCpmkprVBGizT5g3brrknX6VDX1gXFAmH/daCRJAIHPX0S/ol0z9w/hCEl
  250. CpbiJPEphGtxqz4SfMv6IrIfneuDDKbF+w5MV/sCAwEAATANBgkqhkiG9w0BAQsF
  251. AAOCAQEAUKj+/GpnMn+0/u9SPHTNmX3U3Y/ldmud0CsU5ELzMf/3YPbC/qWziRik
  252. ewM2WyG8cwT9ayt9DxWGfu/zLv+ddyl8Wje1e/FIkRKXK0WW6OMz3e8Y45ONzpmu
  253. 8ME75IpnMuZEqE/WayRg27dQT5QNnEe/uNLd4m9BfsQcHIx3OfHCu5Of6/BclgsJ
  254. VWp31zY8kcT0QN1GQxfB3eXnMyELneKCP3OH9DBhr4FUFb0vRHc8/1rdADFvSsdX
  255. hNm8iRq+s2n0F6OGBofYT8ZyCnDUSQAoKMTIHcz+dDGyP4BfPY5w0ZGUfuaYATvm
  256. cR92p/PYCFXkAKP3OO0RPlf6dXNKTw==
  257. -----END CERTIFICATE-----',
  258. ],
  259. ];
  260. $this->appFetcher
  261. ->expects($this->once())
  262. ->method('get')
  263. ->willReturn($appArray);
  264. $installer = $this->getInstaller();
  265. $installer->downloadApp('news');
  266. }
  267. /**
  268. * @expectedException \Exception
  269. * @expectedExceptionMessage App with id passman has invalid signature
  270. */
  271. public function testDownloadAppWithInvalidSignature() {
  272. $appArray = [
  273. [
  274. 'id' => 'passman',
  275. 'certificate' => '-----BEGIN CERTIFICATE-----
  276. MIIEAjCCAuoCAhAYMA0GCSqGSIb3DQEBCwUAMHsxCzAJBgNVBAYTAkRFMRswGQYD
  277. VQQIDBJCYWRlbi1XdWVydHRlbWJlcmcxFzAVBgNVBAoMDk5leHRjbG91ZCBHbWJI
  278. MTYwNAYDVQQDDC1OZXh0Y2xvdWQgQ29kZSBTaWduaW5nIEludGVybWVkaWF0ZSBB
  279. dXRob3JpdHkwHhcNMTYxMDE5MTkzNTEyWhcNMjcwMTI1MTkzNTEyWjASMRAwDgYD
  280. VQQDDAdwYXNzbWFuMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA1Jw1
  281. 8F0DefogaLaBudGbhK2zcFIBSzxhh7dRWguZKHGE+rG00BOvFLIAo37Bfmy9WKLc
  282. 3BFYvuFBowaVdaFOLxQJod0sOTmVMXhwoY5e3Xx+P+nsAw1/0gI10/LD1Vgl6i1u
  283. gMocmnbEYhKwr0NbdiQiMI9UB9Ge/51wt4WtAxwK7yJFl3+5qzvJgfX75Wt+8L1e
  284. Wk0LpVW23tUueJovjYZJXyAtohNaV3gwiST+QmKljCd4gwGX9abqfc76/lWtS+hI
  285. rKptuICc55ffH30rqVhAgCMouF/Ml5Qru8tDen5dSNtmAXz89OlDNisP+9HL4WDZ
  286. wvgps0mm/OYAUAQln24uXPDmAX/H2P5xIDHAa8avsqdgmHiqnLr4GYD8JYeb8GmB
  287. zZ38hEMjCr2F1k1h9T1+SyfRiDPDqqv1mBtcvNVc1JmZvSikMxhtQbU0C4/o2SBG
  288. RPCirknfPeKu8wBi6gvH4/SK0XTyuM8H58b9AKxzoo/wLbQ668+faLYyMSzCvsZD
  289. eeZkiO85y87Ax57WRY93arccCMaUeks/cTriNw3JrvdDyb2SeQOX9JUp0orUlC64
  290. AzK2xhXCpmkprVBGizT5g3brrknX6VDX1gXFAmH/daCRJAIHPX0S/ol0z9w/hCEl
  291. CpbiJPEphGtxqz4SfMv6IrIfneuDDKbF+w5MV/sCAwEAATANBgkqhkiG9w0BAQsF
  292. AAOCAQEAUKj+/GpnMn+0/u9SPHTNmX3U3Y/ldmud0CsU5ELzMf/3YPbC/qWziRik
  293. ewM2WyG8cwT9ayt9DxWGfu/zLv+ddyl8Wje1e/FIkRKXK0WW6OMz3e8Y45ONzpmu
  294. 8ME75IpnMuZEqE/WayRg27dQT5QNnEe/uNLd4m9BfsQcHIx3OfHCu5Of6/BclgsJ
  295. VWp31zY8kcT0QN1GQxfB3eXnMyELneKCP3OH9DBhr4FUFb0vRHc8/1rdADFvSsdX
  296. hNm8iRq+s2n0F6OGBofYT8ZyCnDUSQAoKMTIHcz+dDGyP4BfPY5w0ZGUfuaYATvm
  297. cR92p/PYCFXkAKP3OO0RPlf6dXNKTw==
  298. -----END CERTIFICATE-----',
  299. 'releases' => [
  300. [
  301. 'download' => 'https://example.com',
  302. 'signature' => 'MySignature',
  303. ],
  304. [
  305. 'download' => 'https://nextcloud.com',
  306. ],
  307. ],
  308. ],
  309. ];
  310. $this->appFetcher
  311. ->expects($this->once())
  312. ->method('get')
  313. ->willReturn($appArray);
  314. $realTmpFile = \OC::$server->getTempManager()->getTemporaryFile('.tar.gz');
  315. copy(__DIR__ . '/../data/testapp.tar.gz', $realTmpFile);
  316. $this->tempManager
  317. ->expects($this->at(0))
  318. ->method('getTemporaryFile')
  319. ->with('.tar.gz')
  320. ->willReturn($realTmpFile);
  321. $client = $this->createMock(IClient::class);
  322. $client
  323. ->expects($this->once())
  324. ->method('get')
  325. ->with('https://example.com', ['save_to' => $realTmpFile]);
  326. $this->clientService
  327. ->expects($this->once())
  328. ->method('newClient')
  329. ->willReturn($client);
  330. $installer = $this->getInstaller();
  331. $installer->downloadApp('passman');
  332. }
  333. /**
  334. * @expectedException \Exception
  335. * @expectedExceptionMessage Extracted app testapp has more than 1 folder
  336. */
  337. public function testDownloadAppWithMoreThanOneFolderDownloaded() {
  338. $appArray = [
  339. [
  340. 'id' => 'testapp',
  341. 'certificate' => '-----BEGIN CERTIFICATE-----
  342. MIIEAjCCAuoCAhAbMA0GCSqGSIb3DQEBCwUAMHsxCzAJBgNVBAYTAkRFMRswGQYD
  343. VQQIDBJCYWRlbi1XdWVydHRlbWJlcmcxFzAVBgNVBAoMDk5leHRjbG91ZCBHbWJI
  344. MTYwNAYDVQQDDC1OZXh0Y2xvdWQgQ29kZSBTaWduaW5nIEludGVybWVkaWF0ZSBB
  345. dXRob3JpdHkwHhcNMTYxMDMxMTgxNTI2WhcNMjcwMjA2MTgxNTI2WjASMRAwDgYD
  346. VQQDEwd0ZXN0YXBwMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAqa0x
  347. FcVa0YcO/ABqSNdbf7Bzp2PBBJzVM9gI4/HzzBKU/NY9/RibBBpNjAIWEFAbTI4j
  348. ilFSoxHDQ8HrboFOeKCrOIdp9ATQ8SnYVNIQ12Ym3LA/XxcG0gG0H7DeS9C0uACe
  349. svN8fwD1wnKnLLU9GBzO77jwYkneed85wwKG4waHd3965gxQWq0N5gnYS0TTn7Yr
  350. l1veRiw+ryefXvfWI0cN1WBZJ/4XAkwVlpG1HP60AunIpcwn9bfG4XCka+7x26E4
  351. 6Hw0Ot7D7j0yzVzimJDPB2h2buEtPVd6m+oNPueVvKGta+p6cEEaHlFVh2Pa9DI+
  352. me3nb6aXE2kABWXav3BmK18A5Rg4ZY4VFYvmHmxkOhT/ulGZRqy6TccL/optqs52
  353. KQ6P0e5dfmhLeoCvJObD+ZYKv+kJCRFtX1Hve/R4IHG6XSFKUfrRjyor9b6TX2L/
  354. l2vV0mFjmy4g3l05vWHg1Edtq7M29S/xNA3/hF29NjBq6NoMbLGcBtFced1iK07Z
  355. yHLjXRZRfURP671Svqqg8pjxuDqkJ2vIj/Vpod4kF2jeiZYXcfmNKhEhxpkccSe0
  356. dI6p76Ne7XSUpf8yCPiSnWZLadqKZdEulcB4SlrZO2+/pycgqrqihofDrvDeWeeg
  357. gQyvbZZKl4ylRNj6IRKnosKLVXNqMHQxLmxLHeUCAwEAATANBgkqhkiG9w0BAQsF
  358. AAOCAQEALkKQwa40HfuP4Q6ShwBFJbXLyodIAXCT014kBVjReDKNl5oHtMXRjPxj
  359. nj9doKu+3bLNuLCv9uU3H5+t/GFogReV3Av3z/fCqJ6wHv/KX+lacj31dWXZGD8G
  360. z+RYibrxKkPN0V6q1mSvkg3hJOOE+/4FPIdc8PNlgratv3WS4dT8QwGSUavHW2Kx
  361. 89nIdnwtLEFpgML/bTG0dm8BH57xER8LCYixW1VmpV6A4IsoKVsnB7KUCRTK3iUJ
  362. Zh8Xg8UMNrOtXc1Wx1Wmjaa4ZE9dY6/KkU2ny2UWyDHKU/9VE8QQ4HN93gxU4+H7
  363. cUg0V1uAxqUvKytKkMfcyPWsz/AINA==
  364. -----END CERTIFICATE-----',
  365. 'releases' => [
  366. [
  367. 'download' => 'https://example.com',
  368. 'signature' => 'h8H3tUy2dDlwrV/hY/ZxqYqe8Vue+IINluLtAt1HxX2cjz3vdoVHJRINRkMYYcdz
  369. VlndvHyKdqJHDAACphR8tVV6EFrPermn7gEgWk7a51LbUM7sAN7RV7ijEooUo+TQ
  370. jNW9Ch48Wg3jvebMwWNr5t5U4MEXTP5f0YX/kxvkJoUrG3a3spt7ziEuHaq8IPvt
  371. Jj/JSDFhvRNpom7yNNcI1Ijoq8yC11sg7RJBNfrHdGPHPZVz2SyBiY9OcvgGSpUU
  372. bfvzhIZDCl/RRi5fs39jLLupAP69Ez6+jylNXEMsNwM0YL5+egSXFtkCvgOw8UBg
  373. ZqNZZojcS22acuvHRnoa6PDDhwHdCH+zpifXSOhSQvue5n6q+FVX6aeD1LnCQkYB
  374. D2wvNyZWwdADJtvDj03DKhm21g+TPy63XC94q4IqvjQ94pV8U+qrBBfkQ62NGjaC
  375. oOU6y5sEmQeAdVRpWVo0Hewmjp4Adoj5JRwuqCVEynTC6DXHs3HvHxYlmib1F05a
  376. GqEhdDmOHsxNaeJ08Hlptq5yLv3+0wEdtriVjgAZNVduHG1F1FkhPIrDHaB6pd67
  377. 0AFvO/pZgMSHDRHD+safBgaLb5dBZ895Qvudbq3RQevVnO+YZQYZkpmjoF/+TQ7/
  378. YwDVP+QmNRzx72jtqAN/Kc3CvQ9nkgYhU65B95aX0xA=',
  379. ],
  380. [
  381. 'download' => 'https://nextcloud.com',
  382. ],
  383. ],
  384. ],
  385. ];
  386. $this->appFetcher
  387. ->expects($this->once())
  388. ->method('get')
  389. ->willReturn($appArray);
  390. $realTmpFile = \OC::$server->getTempManager()->getTemporaryFile('.tar.gz');
  391. copy(__DIR__ . '/../data/testapp1.tar.gz', $realTmpFile);
  392. $this->tempManager
  393. ->expects($this->at(0))
  394. ->method('getTemporaryFile')
  395. ->with('.tar.gz')
  396. ->willReturn($realTmpFile);
  397. $realTmpFolder = \OC::$server->getTempManager()->getTemporaryFolder();
  398. mkdir($realTmpFolder . '/testfolder');
  399. $this->tempManager
  400. ->expects($this->at(1))
  401. ->method('getTemporaryFolder')
  402. ->willReturn($realTmpFolder);
  403. $client = $this->createMock(IClient::class);
  404. $client
  405. ->expects($this->once())
  406. ->method('get')
  407. ->with('https://example.com', ['save_to' => $realTmpFile]);
  408. $this->clientService
  409. ->expects($this->once())
  410. ->method('newClient')
  411. ->willReturn($client);
  412. $installer = $this->getInstaller();
  413. $installer->downloadApp('testapp');
  414. }
  415. /**
  416. * @expectedException \Exception
  417. * @expectedExceptionMessage App for id testapp has a wrong app ID in info.xml: testapp1
  418. */
  419. public function testDownloadAppWithMismatchingIdentifier() {
  420. $appArray = [
  421. [
  422. 'id' => 'testapp',
  423. 'certificate' => '-----BEGIN CERTIFICATE-----
  424. MIIEAjCCAuoCAhAbMA0GCSqGSIb3DQEBCwUAMHsxCzAJBgNVBAYTAkRFMRswGQYD
  425. VQQIDBJCYWRlbi1XdWVydHRlbWJlcmcxFzAVBgNVBAoMDk5leHRjbG91ZCBHbWJI
  426. MTYwNAYDVQQDDC1OZXh0Y2xvdWQgQ29kZSBTaWduaW5nIEludGVybWVkaWF0ZSBB
  427. dXRob3JpdHkwHhcNMTYxMDMxMTgxNTI2WhcNMjcwMjA2MTgxNTI2WjASMRAwDgYD
  428. VQQDEwd0ZXN0YXBwMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAqa0x
  429. FcVa0YcO/ABqSNdbf7Bzp2PBBJzVM9gI4/HzzBKU/NY9/RibBBpNjAIWEFAbTI4j
  430. ilFSoxHDQ8HrboFOeKCrOIdp9ATQ8SnYVNIQ12Ym3LA/XxcG0gG0H7DeS9C0uACe
  431. svN8fwD1wnKnLLU9GBzO77jwYkneed85wwKG4waHd3965gxQWq0N5gnYS0TTn7Yr
  432. l1veRiw+ryefXvfWI0cN1WBZJ/4XAkwVlpG1HP60AunIpcwn9bfG4XCka+7x26E4
  433. 6Hw0Ot7D7j0yzVzimJDPB2h2buEtPVd6m+oNPueVvKGta+p6cEEaHlFVh2Pa9DI+
  434. me3nb6aXE2kABWXav3BmK18A5Rg4ZY4VFYvmHmxkOhT/ulGZRqy6TccL/optqs52
  435. KQ6P0e5dfmhLeoCvJObD+ZYKv+kJCRFtX1Hve/R4IHG6XSFKUfrRjyor9b6TX2L/
  436. l2vV0mFjmy4g3l05vWHg1Edtq7M29S/xNA3/hF29NjBq6NoMbLGcBtFced1iK07Z
  437. yHLjXRZRfURP671Svqqg8pjxuDqkJ2vIj/Vpod4kF2jeiZYXcfmNKhEhxpkccSe0
  438. dI6p76Ne7XSUpf8yCPiSnWZLadqKZdEulcB4SlrZO2+/pycgqrqihofDrvDeWeeg
  439. gQyvbZZKl4ylRNj6IRKnosKLVXNqMHQxLmxLHeUCAwEAATANBgkqhkiG9w0BAQsF
  440. AAOCAQEALkKQwa40HfuP4Q6ShwBFJbXLyodIAXCT014kBVjReDKNl5oHtMXRjPxj
  441. nj9doKu+3bLNuLCv9uU3H5+t/GFogReV3Av3z/fCqJ6wHv/KX+lacj31dWXZGD8G
  442. z+RYibrxKkPN0V6q1mSvkg3hJOOE+/4FPIdc8PNlgratv3WS4dT8QwGSUavHW2Kx
  443. 89nIdnwtLEFpgML/bTG0dm8BH57xER8LCYixW1VmpV6A4IsoKVsnB7KUCRTK3iUJ
  444. Zh8Xg8UMNrOtXc1Wx1Wmjaa4ZE9dY6/KkU2ny2UWyDHKU/9VE8QQ4HN93gxU4+H7
  445. cUg0V1uAxqUvKytKkMfcyPWsz/AINA==
  446. -----END CERTIFICATE-----',
  447. 'releases' => [
  448. [
  449. 'download' => 'https://example.com',
  450. 'signature' => 'h8H3tUy2dDlwrV/hY/ZxqYqe8Vue+IINluLtAt1HxX2cjz3vdoVHJRINRkMYYcdz
  451. VlndvHyKdqJHDAACphR8tVV6EFrPermn7gEgWk7a51LbUM7sAN7RV7ijEooUo+TQ
  452. jNW9Ch48Wg3jvebMwWNr5t5U4MEXTP5f0YX/kxvkJoUrG3a3spt7ziEuHaq8IPvt
  453. Jj/JSDFhvRNpom7yNNcI1Ijoq8yC11sg7RJBNfrHdGPHPZVz2SyBiY9OcvgGSpUU
  454. bfvzhIZDCl/RRi5fs39jLLupAP69Ez6+jylNXEMsNwM0YL5+egSXFtkCvgOw8UBg
  455. ZqNZZojcS22acuvHRnoa6PDDhwHdCH+zpifXSOhSQvue5n6q+FVX6aeD1LnCQkYB
  456. D2wvNyZWwdADJtvDj03DKhm21g+TPy63XC94q4IqvjQ94pV8U+qrBBfkQ62NGjaC
  457. oOU6y5sEmQeAdVRpWVo0Hewmjp4Adoj5JRwuqCVEynTC6DXHs3HvHxYlmib1F05a
  458. GqEhdDmOHsxNaeJ08Hlptq5yLv3+0wEdtriVjgAZNVduHG1F1FkhPIrDHaB6pd67
  459. 0AFvO/pZgMSHDRHD+safBgaLb5dBZ895Qvudbq3RQevVnO+YZQYZkpmjoF/+TQ7/
  460. YwDVP+QmNRzx72jtqAN/Kc3CvQ9nkgYhU65B95aX0xA=',
  461. ],
  462. [
  463. 'download' => 'https://nextcloud.com',
  464. ],
  465. ],
  466. ],
  467. ];
  468. $this->appFetcher
  469. ->expects($this->once())
  470. ->method('get')
  471. ->willReturn($appArray);
  472. $realTmpFile = \OC::$server->getTempManager()->getTemporaryFile('.tar.gz');
  473. copy(__DIR__ . '/../data/testapp1.tar.gz', $realTmpFile);
  474. $this->tempManager
  475. ->expects($this->at(0))
  476. ->method('getTemporaryFile')
  477. ->with('.tar.gz')
  478. ->willReturn($realTmpFile);
  479. $realTmpFolder = \OC::$server->getTempManager()->getTemporaryFolder();
  480. $this->tempManager
  481. ->expects($this->at(1))
  482. ->method('getTemporaryFolder')
  483. ->willReturn($realTmpFolder);
  484. $client = $this->createMock(IClient::class);
  485. $client
  486. ->expects($this->once())
  487. ->method('get')
  488. ->with('https://example.com', ['save_to' => $realTmpFile]);
  489. $this->clientService
  490. ->expects($this->once())
  491. ->method('newClient')
  492. ->willReturn($client);
  493. $installer = $this->getInstaller();
  494. $installer->downloadApp('testapp');
  495. }
  496. public function testDownloadAppSuccessful() {
  497. $appArray = [
  498. [
  499. 'id' => 'testapp',
  500. 'certificate' => '-----BEGIN CERTIFICATE-----
  501. MIIEAjCCAuoCAhAbMA0GCSqGSIb3DQEBCwUAMHsxCzAJBgNVBAYTAkRFMRswGQYD
  502. VQQIDBJCYWRlbi1XdWVydHRlbWJlcmcxFzAVBgNVBAoMDk5leHRjbG91ZCBHbWJI
  503. MTYwNAYDVQQDDC1OZXh0Y2xvdWQgQ29kZSBTaWduaW5nIEludGVybWVkaWF0ZSBB
  504. dXRob3JpdHkwHhcNMTYxMDMxMTgxNTI2WhcNMjcwMjA2MTgxNTI2WjASMRAwDgYD
  505. VQQDEwd0ZXN0YXBwMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAqa0x
  506. FcVa0YcO/ABqSNdbf7Bzp2PBBJzVM9gI4/HzzBKU/NY9/RibBBpNjAIWEFAbTI4j
  507. ilFSoxHDQ8HrboFOeKCrOIdp9ATQ8SnYVNIQ12Ym3LA/XxcG0gG0H7DeS9C0uACe
  508. svN8fwD1wnKnLLU9GBzO77jwYkneed85wwKG4waHd3965gxQWq0N5gnYS0TTn7Yr
  509. l1veRiw+ryefXvfWI0cN1WBZJ/4XAkwVlpG1HP60AunIpcwn9bfG4XCka+7x26E4
  510. 6Hw0Ot7D7j0yzVzimJDPB2h2buEtPVd6m+oNPueVvKGta+p6cEEaHlFVh2Pa9DI+
  511. me3nb6aXE2kABWXav3BmK18A5Rg4ZY4VFYvmHmxkOhT/ulGZRqy6TccL/optqs52
  512. KQ6P0e5dfmhLeoCvJObD+ZYKv+kJCRFtX1Hve/R4IHG6XSFKUfrRjyor9b6TX2L/
  513. l2vV0mFjmy4g3l05vWHg1Edtq7M29S/xNA3/hF29NjBq6NoMbLGcBtFced1iK07Z
  514. yHLjXRZRfURP671Svqqg8pjxuDqkJ2vIj/Vpod4kF2jeiZYXcfmNKhEhxpkccSe0
  515. dI6p76Ne7XSUpf8yCPiSnWZLadqKZdEulcB4SlrZO2+/pycgqrqihofDrvDeWeeg
  516. gQyvbZZKl4ylRNj6IRKnosKLVXNqMHQxLmxLHeUCAwEAATANBgkqhkiG9w0BAQsF
  517. AAOCAQEALkKQwa40HfuP4Q6ShwBFJbXLyodIAXCT014kBVjReDKNl5oHtMXRjPxj
  518. nj9doKu+3bLNuLCv9uU3H5+t/GFogReV3Av3z/fCqJ6wHv/KX+lacj31dWXZGD8G
  519. z+RYibrxKkPN0V6q1mSvkg3hJOOE+/4FPIdc8PNlgratv3WS4dT8QwGSUavHW2Kx
  520. 89nIdnwtLEFpgML/bTG0dm8BH57xER8LCYixW1VmpV6A4IsoKVsnB7KUCRTK3iUJ
  521. Zh8Xg8UMNrOtXc1Wx1Wmjaa4ZE9dY6/KkU2ny2UWyDHKU/9VE8QQ4HN93gxU4+H7
  522. cUg0V1uAxqUvKytKkMfcyPWsz/AINA==
  523. -----END CERTIFICATE-----',
  524. 'releases' => [
  525. [
  526. 'download' => 'https://example.com',
  527. 'signature' => 'O5UWFRnSx4mSdEX83Uh9u7KW+Gl1OWU4uaFg6aYY19zc+lWP4rKCbAUH7Jo1Bohf
  528. qxQbhXs4cMqGmoL8dW4zeFUqSJCRk52LA+ciLezjPFv275q+BxEgyWOylLnbhBaz
  529. +v6lXLaeG0J/ry8wEdg+rwP8FCYPsvKlXSVbFjgubvCR/owKJJf5iL0B93noBwBN
  530. jfbcxi7Kh16HAKy6f/gVZ6hf/4Uo7iEFMCPEHjidope+ejUpqbd8XhQg5/yh7TQ7
  531. VKR7pkdDG2eFr5c3CpaECdNg5ZIGRbQNJHBXHT/wliorWpYJtwtNAQJ4xC635gLP
  532. 4klkKN4XtSj8bJUaJC6aaksLFgRSeKXaYAHai/XP6BkeyNzlSbsmyZk8cZbySx8F
  533. gVOzPok1c94UGT57FjeW5eqRjtmzbYivQdP89Ouz6et7PY69yOCqiRFQanrqzwoX
  534. MPLX6f5V9tCJtlH6ztmEcDROfvuVc0U3rEhqx2hphoyo+MZrPFpdcJL8KkIdMKbY
  535. 7yQWrsV7QvAzygAOFsC0TlSNJbmMCljouUk9di4CUZ+xsQ6n6TZtE7gsdljlKjPS
  536. 3Ys+e3V1HUaVzv8SaSmKwjRoQxQxHWLtXpJS2Yq+i+gq7LuC+aStzxAzV/h2plDW
  537. 358picx/PobNDi71Q97+/CAOq+4wDOwhKwls7lwudIs=',
  538. ],
  539. [
  540. 'download' => 'https://nextcloud.com',
  541. ],
  542. ],
  543. ],
  544. ];
  545. $this->appFetcher
  546. ->expects($this->at(0))
  547. ->method('get')
  548. ->willReturn($appArray);
  549. $realTmpFile = \OC::$server->getTempManager()->getTemporaryFile('.tar.gz');
  550. copy(__DIR__ . '/../data/testapp.tar.gz', $realTmpFile);
  551. $this->tempManager
  552. ->expects($this->at(0))
  553. ->method('getTemporaryFile')
  554. ->with('.tar.gz')
  555. ->willReturn($realTmpFile);
  556. $realTmpFolder = \OC::$server->getTempManager()->getTemporaryFolder();
  557. $this->tempManager
  558. ->expects($this->at(1))
  559. ->method('getTemporaryFolder')
  560. ->willReturn($realTmpFolder);
  561. $client = $this->createMock(IClient::class);
  562. $client
  563. ->expects($this->once())
  564. ->method('get')
  565. ->with('https://example.com', ['save_to' => $realTmpFile]);
  566. $this->clientService
  567. ->expects($this->at(0))
  568. ->method('newClient')
  569. ->willReturn($client);
  570. $installer = $this->getInstaller();
  571. $installer->downloadApp('testapp');
  572. $this->assertTrue(file_exists(__DIR__ . '/../../apps/testapp/appinfo/info.xml'));
  573. $this->assertEquals('0.9', \OC_App::getAppVersionByPath(__DIR__ . '/../../apps/testapp/'));
  574. }
  575. /**
  576. * @expectedException \Exception
  577. * @expectedExceptionMessage App for id testapp has version 0.9 and tried to update to lower version 0.8
  578. */
  579. public function testDownloadAppWithDowngrade() {
  580. $appArray = [
  581. [
  582. 'id' => 'testapp',
  583. 'certificate' => '-----BEGIN CERTIFICATE-----
  584. MIIEAjCCAuoCAhAbMA0GCSqGSIb3DQEBCwUAMHsxCzAJBgNVBAYTAkRFMRswGQYD
  585. VQQIDBJCYWRlbi1XdWVydHRlbWJlcmcxFzAVBgNVBAoMDk5leHRjbG91ZCBHbWJI
  586. MTYwNAYDVQQDDC1OZXh0Y2xvdWQgQ29kZSBTaWduaW5nIEludGVybWVkaWF0ZSBB
  587. dXRob3JpdHkwHhcNMTYxMDMxMTgxNTI2WhcNMjcwMjA2MTgxNTI2WjASMRAwDgYD
  588. VQQDEwd0ZXN0YXBwMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAqa0x
  589. FcVa0YcO/ABqSNdbf7Bzp2PBBJzVM9gI4/HzzBKU/NY9/RibBBpNjAIWEFAbTI4j
  590. ilFSoxHDQ8HrboFOeKCrOIdp9ATQ8SnYVNIQ12Ym3LA/XxcG0gG0H7DeS9C0uACe
  591. svN8fwD1wnKnLLU9GBzO77jwYkneed85wwKG4waHd3965gxQWq0N5gnYS0TTn7Yr
  592. l1veRiw+ryefXvfWI0cN1WBZJ/4XAkwVlpG1HP60AunIpcwn9bfG4XCka+7x26E4
  593. 6Hw0Ot7D7j0yzVzimJDPB2h2buEtPVd6m+oNPueVvKGta+p6cEEaHlFVh2Pa9DI+
  594. me3nb6aXE2kABWXav3BmK18A5Rg4ZY4VFYvmHmxkOhT/ulGZRqy6TccL/optqs52
  595. KQ6P0e5dfmhLeoCvJObD+ZYKv+kJCRFtX1Hve/R4IHG6XSFKUfrRjyor9b6TX2L/
  596. l2vV0mFjmy4g3l05vWHg1Edtq7M29S/xNA3/hF29NjBq6NoMbLGcBtFced1iK07Z
  597. yHLjXRZRfURP671Svqqg8pjxuDqkJ2vIj/Vpod4kF2jeiZYXcfmNKhEhxpkccSe0
  598. dI6p76Ne7XSUpf8yCPiSnWZLadqKZdEulcB4SlrZO2+/pycgqrqihofDrvDeWeeg
  599. gQyvbZZKl4ylRNj6IRKnosKLVXNqMHQxLmxLHeUCAwEAATANBgkqhkiG9w0BAQsF
  600. AAOCAQEALkKQwa40HfuP4Q6ShwBFJbXLyodIAXCT014kBVjReDKNl5oHtMXRjPxj
  601. nj9doKu+3bLNuLCv9uU3H5+t/GFogReV3Av3z/fCqJ6wHv/KX+lacj31dWXZGD8G
  602. z+RYibrxKkPN0V6q1mSvkg3hJOOE+/4FPIdc8PNlgratv3WS4dT8QwGSUavHW2Kx
  603. 89nIdnwtLEFpgML/bTG0dm8BH57xER8LCYixW1VmpV6A4IsoKVsnB7KUCRTK3iUJ
  604. Zh8Xg8UMNrOtXc1Wx1Wmjaa4ZE9dY6/KkU2ny2UWyDHKU/9VE8QQ4HN93gxU4+H7
  605. cUg0V1uAxqUvKytKkMfcyPWsz/AINA==
  606. -----END CERTIFICATE-----',
  607. 'releases' => [
  608. [
  609. 'download' => 'https://example.com',
  610. 'signature' => 'KMSao4cKdMIYxeT8Bm4lrmSeIQnk7YzJZh+Vz+4LVSBwF+OMmcujryQuWLXmbPfg
  611. 4hGI9zS025469VNjUoCprn01H8NBq3O1cXz+ewG1oxYWMMQFZDkOtUQ+XZ27b91t
  612. y0l45H6C8j0sTeSrUb/LCjrdm+buUygkhC2RZxCI6tLi4rYWj0MiqDz98XkbB3te
  613. pW3ZND6mG6Jxn1fnd35paqZ/+URMftoLQ4K+6vJoBVGnug9nk1RpGLouICI0zCrz
  614. YPTsBHo0s2mPvQQ/ASacWYmSe5R6r5JCzNeGMpViGCqCYPbwuebgqK079s2zvSF9
  615. mSLAm2Tk6gCM29N8Vdfr6ppCvIbuNzlLU/dGdYHAILgxEsm/odZjt1Fhs4lOo3A5
  616. 9ToaNl5+qOEkggwfE/QqceHAY2soW9V5d9izhTCDgXmxpPpPXkwPPTz04ZUpi1Yc
  617. OdZZOswbEcc2jUC5T7a7Tnp0uBOkdqat6jB4oMGwU1ldYLCGRyy546cPPTXJw5kH
  618. 9WfeKJ/mavrSLVa7QqZ4RCcMigmijT1kdqbaEh05IZNrzs6VDcS2EIrbDX8SGXUk
  619. uDDkPXZEXqNDEjyONfDXVRLiqDa52Gg+I4vW/l/4ZOFgAWdZkqPPuZFaqzZpsJXm
  620. JXhrdaWDZ8fzpUjugrtC3qslsqL0dzgU37anS3HwrT8=',
  621. ],
  622. [
  623. 'download' => 'https://nextcloud.com',
  624. ],
  625. ],
  626. ],
  627. ];
  628. $this->appFetcher
  629. ->expects($this->at(1))
  630. ->method('get')
  631. ->willReturn($appArray);
  632. $realTmpFile = \OC::$server->getTempManager()->getTemporaryFile('.tar.gz');
  633. copy(__DIR__ . '/../data/testapp.0.8.tar.gz', $realTmpFile);
  634. $this->tempManager
  635. ->expects($this->at(2))
  636. ->method('getTemporaryFile')
  637. ->with('.tar.gz')
  638. ->willReturn($realTmpFile);
  639. $realTmpFolder = \OC::$server->getTempManager()->getTemporaryFolder();
  640. $this->tempManager
  641. ->expects($this->at(3))
  642. ->method('getTemporaryFolder')
  643. ->willReturn($realTmpFolder);
  644. $client = $this->createMock(IClient::class);
  645. $client
  646. ->expects($this->once())
  647. ->method('get')
  648. ->with('https://example.com', ['save_to' => $realTmpFile]);
  649. $this->clientService
  650. ->expects($this->at(1))
  651. ->method('newClient')
  652. ->willReturn($client);
  653. $this->testDownloadAppSuccessful();
  654. $this->assertTrue(file_exists(__DIR__ . '/../../apps/testapp/appinfo/info.xml'));
  655. $this->assertEquals('0.9', \OC_App::getAppVersionByPath(__DIR__ . '/../../apps/testapp/'));
  656. $installer = $this->getInstaller();
  657. $installer->downloadApp('testapp');
  658. $this->assertTrue(file_exists(__DIR__ . '/../../apps/testapp/appinfo/info.xml'));
  659. $this->assertEquals('0.8', \OC_App::getAppVersionByPath(__DIR__ . '/../../apps/testapp/'));
  660. }
  661. }