InstallerTest.php 25 KB

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