InstallerTest.php 26 KB

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