InstallerTest.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  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\App\IAppManager;
  13. use OCP\Http\Client\IClient;
  14. use OCP\Http\Client\IClientService;
  15. use OCP\IConfig;
  16. use OCP\ITempManager;
  17. use Psr\Log\LoggerInterface;
  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 LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
  34. private $logger;
  35. /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
  36. private $config;
  37. protected function setUp(): void {
  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(LoggerInterface::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->get(LoggerInterface::class),
  52. $config,
  53. false
  54. );
  55. $installer->removeApp(self::$appid);
  56. }
  57. protected function getInstaller() {
  58. return new Installer(
  59. $this->appFetcher,
  60. $this->clientService,
  61. $this->tempManager,
  62. $this->logger,
  63. $this->config,
  64. false
  65. );
  66. }
  67. protected function tearDown(): void {
  68. $installer = new Installer(
  69. \OC::$server->getAppFetcher(),
  70. \OC::$server->getHTTPClientService(),
  71. \OC::$server->getTempManager(),
  72. \OC::$server->get(LoggerInterface::class),
  73. \OC::$server->getConfig(),
  74. false
  75. );
  76. $installer->removeApp(self::$appid);
  77. \OC::$server->getConfig()->setSystemValue('appstoreenabled', $this->appstore);
  78. parent::tearDown();
  79. }
  80. public function testInstallApp() {
  81. // Read the current version of the app to check for bug #2572
  82. \OCP\Server::get(IAppManager::class)->getAppVersion('testapp', true);
  83. // Extract app
  84. $pathOfTestApp = __DIR__ . '/../data/testapp.zip';
  85. $tar = new ZIP($pathOfTestApp);
  86. $tar->extract(\OC_App::getInstallPath());
  87. // Install app
  88. $installer = new Installer(
  89. \OC::$server->getAppFetcher(),
  90. \OC::$server->getHTTPClientService(),
  91. \OC::$server->getTempManager(),
  92. \OC::$server->get(LoggerInterface::class),
  93. \OC::$server->getConfig(),
  94. false
  95. );
  96. $this->assertNull(\OC::$server->getConfig()->getAppValue('testapp', 'enabled', null), 'Check that the app is not listed before installation');
  97. $this->assertSame('testapp', $installer->installApp(self::$appid));
  98. $this->assertSame('no', \OC::$server->getConfig()->getAppValue('testapp', 'enabled', null), 'Check that the app is listed after installation');
  99. $this->assertSame('0.9', \OC::$server->getConfig()->getAppValue('testapp', 'installed_version'));
  100. $installer->removeApp(self::$appid);
  101. }
  102. public function updateArrayProvider() {
  103. return [
  104. // Update available
  105. [
  106. [
  107. [
  108. 'id' => 'files',
  109. 'releases' => [
  110. [
  111. 'version' => '1111.0'
  112. ],
  113. ],
  114. ],
  115. ],
  116. '1111.0',
  117. ],
  118. // No update available
  119. [
  120. [
  121. [
  122. 'id' => 'files',
  123. 'releases' => [
  124. [
  125. 'version' => '1.0'
  126. ],
  127. ],
  128. ],
  129. ],
  130. false,
  131. ],
  132. ];
  133. }
  134. /**
  135. * @dataProvider updateArrayProvider
  136. * @param array $appArray
  137. * @param string|bool $updateAvailable
  138. */
  139. public function testIsUpdateAvailable(array $appArray, $updateAvailable) {
  140. $this->appFetcher
  141. ->expects($this->once())
  142. ->method('get')
  143. ->willReturn($appArray);
  144. $installer = $this->getInstaller();
  145. $this->assertSame($updateAvailable, $installer->isUpdateAvailable('files'));
  146. $this->assertSame($updateAvailable, $installer->isUpdateAvailable('files'), 'Cached result should be returned and fetcher should be only called once');
  147. }
  148. public function testDownloadAppWithRevokedCertificate() {
  149. $this->expectException(\Exception::class);
  150. $this->expectExceptionMessage('Certificate "4112" has been revoked');
  151. $appArray = [
  152. [
  153. 'id' => 'news',
  154. 'certificate' => '-----BEGIN CERTIFICATE-----
  155. MIIEAjCCAuoCAhAQMA0GCSqGSIb3DQEBCwUAMHsxCzAJBgNVBAYTAkRFMRswGQYD
  156. VQQIDBJCYWRlbi1XdWVydHRlbWJlcmcxFzAVBgNVBAoMDk5leHRjbG91ZCBHbWJI
  157. MTYwNAYDVQQDDC1OZXh0Y2xvdWQgQ29kZSBTaWduaW5nIEludGVybWVkaWF0ZSBB
  158. dXRob3JpdHkwHhcNMTYxMDAzMTMyNDM3WhcNMjcwMTA5MTMyNDM3WjASMRAwDgYD
  159. VQQDDAdwYXNzbWFuMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEApEt+
  160. KZGs+WqdZkHZflzqk+ophYWB8qB47XCzy+xdTGPFM84/9wXltRPbcQQWJJl5aOx0
  161. FPbsyTGhIt/IYZ2Vl0XrDRJjsaxzPcrofrwpJ2tqforXjGohl6mZUBA0ESzFiPzT
  162. SAZe8E14+Jk8rbF/ecrkqcWf2cTMV3Qfu9YvJo8WVs4lHc95r1F+Nalh/OLkHkzb
  163. fYPno2Z5cco6U7BXunFQG2gqy3wWQwmlhDxh5fwrCoFzPWm7WhwSyK+eMoSDz+Vp
  164. 3kmtyijsqnda0zA9bfNzgW26czbJaObbnkdtDC2nfoAWXndlS/5YRI8yHd9miB5C
  165. u1OC8LUWToDGNa9+FOxBSj7Nk6iyjbVfRXcTqThdkVZdOOPaBRMsL9R4UYywCbhA
  166. yGNiQ0ahfXD8MZSb08rlQg8tAtcUZW1sYQcbtMGnu8OyC5J7N1efzv5mys4+9hBS
  167. 5ECeyCuQTuOkF4H/XS2BMSFZWF2xh7wzhMLca+5yauDW4i8baFEv74QTeY1DADgI
  168. Lz29NJ6z9xYzEnPesjNrwIcJwIjV52EkdLTi+EIf83UjXLQdwDbLxu76qxqP7K0I
  169. oMmwbl7UNA0wzq7nmgRhvqhow5RoCaSJjTz0EYQVSa1xelwiKeJiSKj2G9Mgt5Ms
  170. Miuy3C3VAGvQJ2ocILPGOt54oVeNRFLpnCo1e3sCAwEAATANBgkqhkiG9w0BAQsF
  171. AAOCAQEAkGYtg21rGpUVT/AokGUfI0PeyYAkcXKy2yuBAzfRk+uIXnRR0vK+OMpx
  172. shBoYGR3JEGUHZcMTRh8wjAZ0wuyYlQONtJbFFF3bCfODXxCsw0Vm8/Ms+KCmE4Z
  173. SyQafWEQf1sdqNw4VS4DYS2mlpDgAl+U9UY6HQKuT3+GFIxCsQSdS0GTaiYVKPVE
  174. p/eKou739h+5dM4FEhIYZX+7PWlHmX6wPCFAjgNu3kiRGmF6LKmCNNXTySATEP86
  175. tczQMzLtVdTg5z8XMi//6TkAPxRPjYi8Vef/s2mLo7KystTmofxI/HZePSieJ9tj
  176. gLgK8d8sKL60JMmKHN3boHrsThKBVA==
  177. -----END CERTIFICATE-----',
  178. ],
  179. ];
  180. $this->appFetcher
  181. ->expects($this->once())
  182. ->method('get')
  183. ->willReturn($appArray);
  184. $installer = $this->getInstaller();
  185. $installer->downloadApp('news');
  186. }
  187. public function testDownloadAppWithNotNextcloudCertificate() {
  188. $this->expectException(\Exception::class);
  189. $this->expectExceptionMessage('App with id news has a certificate not issued by a trusted Code Signing Authority');
  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. public function testDownloadAppWithDifferentCN() {
  227. $this->expectException(\Exception::class);
  228. $this->expectExceptionMessage('App with id news has a cert issued to passman');
  229. $appArray = [
  230. [
  231. 'id' => 'news',
  232. 'certificate' => '-----BEGIN CERTIFICATE-----
  233. MIIEAjCCAuoCAhDUMA0GCSqGSIb3DQEBCwUAMHsxCzAJBgNVBAYTAkRFMRswGQYD
  234. VQQIDBJCYWRlbi1XdWVydHRlbWJlcmcxFzAVBgNVBAoMDk5leHRjbG91ZCBHbWJI
  235. MTYwNAYDVQQDDC1OZXh0Y2xvdWQgQ29kZSBTaWduaW5nIEludGVybWVkaWF0ZSBB
  236. dXRob3JpdHkwHhcNMTkwMTMwMTMwMjA5WhcNMjkwNTA3MTMwMjA5WjASMRAwDgYD
  237. VQQDDAdwYXNzbWFuMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAwT1/
  238. hO/RSUkj0T9a879LPjy4c5V7FBDffEh6H/n1aiOEzofr8vqP3wJ4ZLwIvpZIZNFC
  239. CY4HjBTIgk+QOlAv2oV2w/8XxkSQ708H3m99GFNRQg9EztjiIeKn7y1HhFOeiVaF
  240. Eq6R1Tnre8cjzv6/yf1f1EFpPY3ptCefUjdLfpU/YrPhFxGLS+n5hyr8b6EszqKm
  241. 6NhGI09sd1Wb1y8o+dtQIQr24gWeo3l3QGLxjcJQqHCxE38rGdTNd04qDEm69BMD
  242. Kjk4/JmUBBOn0svg9IAks+4nDnpr3IABfcnKYlmAucVEMNMYfA6kXXWEALsE2yo9
  243. 8Y7GeV8En5Ztn4w3Pt2HMNpJV2m7MWWocSbF+ocp8oJ0cIEcthBubiE2kJhdPi5a
  244. Yo5Bwh54hx53an+XfiDn+bfidvNz5TsJtmZykB84gLcdBQyMHrZcDcD6g74KdW3X
  245. du/AnNUlJujhIU0fsw3UUPB845Q8XjbsIK5WhgaQeXJum8HXnXWkEfh6mE4j9l2Z
  246. 6FJVe8fQlF5lspn6z3qYsWlYRalD3N9Qxy3vpRgCAYTPc3D+fbVP9KJw1cWux1+O
  247. 0X/hNWMDOTenhgyQS+mqhRvdWq71mFjP/RXjOSfED3ipFamPofCz9QC7EERtvZPE
  248. Pr8tBnbxnyTbAOQrN9N2mA9UJbOhk2l5kCSkDpMCAwEAATANBgkqhkiG9w0BAQsF
  249. AAOCAQEAdVaizjIBQLGFo3uzOVAjh5IoFt/DBiSjVYOOt4HacWDDkRKOmQp3AJaA
  250. Zecbd+tF7OsIqrBzbbfK7wp1+y1pLrPNFQghhk7gVxBP9LscLQ1JmDK2vHv9rLAg
  251. d/gv90gf3HVeRQWntAhGTqtiSZkafcXJIRCM4GygoPy2zxeWeCTt85yEbQnuGZ4Z
  252. qtWS/yyJR5ZQEwYG7jFWRxaZicuUdWBhlUMafRUxzjxBhsQplGKSI66eFQ5VtB7L
  253. u/spPSSVhaun5BA1FlphB2TkgnzlCmxJa63nFY045e/Jq+IKMcqqZl/092gbI2EQ
  254. 5EpZaQ1l6H5DBXwrz58a8WTPC2Mu8g==
  255. -----END CERTIFICATE-----',
  256. ],
  257. ];
  258. $this->appFetcher
  259. ->expects($this->once())
  260. ->method('get')
  261. ->willReturn($appArray);
  262. $installer = $this->getInstaller();
  263. $installer->downloadApp('news');
  264. }
  265. public function testDownloadAppWithInvalidSignature() {
  266. $this->expectException(\Exception::class);
  267. $this->expectExceptionMessage('App with id passman has invalid signature');
  268. $appArray = [
  269. [
  270. 'id' => 'passman',
  271. 'certificate' => '-----BEGIN CERTIFICATE-----
  272. MIIEAjCCAuoCAhDUMA0GCSqGSIb3DQEBCwUAMHsxCzAJBgNVBAYTAkRFMRswGQYD
  273. VQQIDBJCYWRlbi1XdWVydHRlbWJlcmcxFzAVBgNVBAoMDk5leHRjbG91ZCBHbWJI
  274. MTYwNAYDVQQDDC1OZXh0Y2xvdWQgQ29kZSBTaWduaW5nIEludGVybWVkaWF0ZSBB
  275. dXRob3JpdHkwHhcNMTkwMTMwMTMwMjA5WhcNMjkwNTA3MTMwMjA5WjASMRAwDgYD
  276. VQQDDAdwYXNzbWFuMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAwT1/
  277. hO/RSUkj0T9a879LPjy4c5V7FBDffEh6H/n1aiOEzofr8vqP3wJ4ZLwIvpZIZNFC
  278. CY4HjBTIgk+QOlAv2oV2w/8XxkSQ708H3m99GFNRQg9EztjiIeKn7y1HhFOeiVaF
  279. Eq6R1Tnre8cjzv6/yf1f1EFpPY3ptCefUjdLfpU/YrPhFxGLS+n5hyr8b6EszqKm
  280. 6NhGI09sd1Wb1y8o+dtQIQr24gWeo3l3QGLxjcJQqHCxE38rGdTNd04qDEm69BMD
  281. Kjk4/JmUBBOn0svg9IAks+4nDnpr3IABfcnKYlmAucVEMNMYfA6kXXWEALsE2yo9
  282. 8Y7GeV8En5Ztn4w3Pt2HMNpJV2m7MWWocSbF+ocp8oJ0cIEcthBubiE2kJhdPi5a
  283. Yo5Bwh54hx53an+XfiDn+bfidvNz5TsJtmZykB84gLcdBQyMHrZcDcD6g74KdW3X
  284. du/AnNUlJujhIU0fsw3UUPB845Q8XjbsIK5WhgaQeXJum8HXnXWkEfh6mE4j9l2Z
  285. 6FJVe8fQlF5lspn6z3qYsWlYRalD3N9Qxy3vpRgCAYTPc3D+fbVP9KJw1cWux1+O
  286. 0X/hNWMDOTenhgyQS+mqhRvdWq71mFjP/RXjOSfED3ipFamPofCz9QC7EERtvZPE
  287. Pr8tBnbxnyTbAOQrN9N2mA9UJbOhk2l5kCSkDpMCAwEAATANBgkqhkiG9w0BAQsF
  288. AAOCAQEAdVaizjIBQLGFo3uzOVAjh5IoFt/DBiSjVYOOt4HacWDDkRKOmQp3AJaA
  289. Zecbd+tF7OsIqrBzbbfK7wp1+y1pLrPNFQghhk7gVxBP9LscLQ1JmDK2vHv9rLAg
  290. d/gv90gf3HVeRQWntAhGTqtiSZkafcXJIRCM4GygoPy2zxeWeCTt85yEbQnuGZ4Z
  291. qtWS/yyJR5ZQEwYG7jFWRxaZicuUdWBhlUMafRUxzjxBhsQplGKSI66eFQ5VtB7L
  292. u/spPSSVhaun5BA1FlphB2TkgnzlCmxJa63nFY045e/Jq+IKMcqqZl/092gbI2EQ
  293. 5EpZaQ1l6H5DBXwrz58a8WTPC2Mu8g==
  294. -----END CERTIFICATE-----',
  295. 'releases' => [
  296. [
  297. 'download' => 'https://example.com',
  298. 'signature' => 'MySignature',
  299. ],
  300. [
  301. 'download' => 'https://nextcloud.com',
  302. ],
  303. ],
  304. ],
  305. ];
  306. $this->appFetcher
  307. ->expects($this->once())
  308. ->method('get')
  309. ->willReturn($appArray);
  310. $realTmpFile = \OC::$server->getTempManager()->getTemporaryFile('.tar.gz');
  311. copy(__DIR__ . '/../data/testapp.tar.gz', $realTmpFile);
  312. $this->tempManager
  313. ->expects($this->once())
  314. ->method('getTemporaryFile')
  315. ->with('.tar.gz')
  316. ->willReturn($realTmpFile);
  317. $client = $this->createMock(IClient::class);
  318. $client
  319. ->expects($this->once())
  320. ->method('get')
  321. ->with('https://example.com', ['sink' => $realTmpFile, 'timeout' => 120]);
  322. $this->clientService
  323. ->expects($this->once())
  324. ->method('newClient')
  325. ->willReturn($client);
  326. $installer = $this->getInstaller();
  327. $installer->downloadApp('passman');
  328. }
  329. public function testDownloadAppWithMoreThanOneFolderDownloaded() {
  330. $this->expectException(\Exception::class);
  331. $this->expectExceptionMessage('Extracted app testapp has more than 1 folder');
  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->once())
  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->once())
  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', ['sink' => $realTmpFile, 'timeout' => 120]);
  402. $this->clientService
  403. ->expects($this->once())
  404. ->method('newClient')
  405. ->willReturn($client);
  406. $installer = $this->getInstaller();
  407. $installer->downloadApp('testapp');
  408. }
  409. public function testDownloadAppWithMismatchingIdentifier() {
  410. $this->expectException(\Exception::class);
  411. $this->expectExceptionMessage('App for id testapp has a wrong app ID in info.xml: testapp1');
  412. $appArray = [
  413. [
  414. 'id' => 'testapp',
  415. 'certificate' => '-----BEGIN CERTIFICATE-----
  416. MIIEAjCCAuoCAhAbMA0GCSqGSIb3DQEBCwUAMHsxCzAJBgNVBAYTAkRFMRswGQYD
  417. VQQIDBJCYWRlbi1XdWVydHRlbWJlcmcxFzAVBgNVBAoMDk5leHRjbG91ZCBHbWJI
  418. MTYwNAYDVQQDDC1OZXh0Y2xvdWQgQ29kZSBTaWduaW5nIEludGVybWVkaWF0ZSBB
  419. dXRob3JpdHkwHhcNMTYxMDMxMTgxNTI2WhcNMjcwMjA2MTgxNTI2WjASMRAwDgYD
  420. VQQDEwd0ZXN0YXBwMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAqa0x
  421. FcVa0YcO/ABqSNdbf7Bzp2PBBJzVM9gI4/HzzBKU/NY9/RibBBpNjAIWEFAbTI4j
  422. ilFSoxHDQ8HrboFOeKCrOIdp9ATQ8SnYVNIQ12Ym3LA/XxcG0gG0H7DeS9C0uACe
  423. svN8fwD1wnKnLLU9GBzO77jwYkneed85wwKG4waHd3965gxQWq0N5gnYS0TTn7Yr
  424. l1veRiw+ryefXvfWI0cN1WBZJ/4XAkwVlpG1HP60AunIpcwn9bfG4XCka+7x26E4
  425. 6Hw0Ot7D7j0yzVzimJDPB2h2buEtPVd6m+oNPueVvKGta+p6cEEaHlFVh2Pa9DI+
  426. me3nb6aXE2kABWXav3BmK18A5Rg4ZY4VFYvmHmxkOhT/ulGZRqy6TccL/optqs52
  427. KQ6P0e5dfmhLeoCvJObD+ZYKv+kJCRFtX1Hve/R4IHG6XSFKUfrRjyor9b6TX2L/
  428. l2vV0mFjmy4g3l05vWHg1Edtq7M29S/xNA3/hF29NjBq6NoMbLGcBtFced1iK07Z
  429. yHLjXRZRfURP671Svqqg8pjxuDqkJ2vIj/Vpod4kF2jeiZYXcfmNKhEhxpkccSe0
  430. dI6p76Ne7XSUpf8yCPiSnWZLadqKZdEulcB4SlrZO2+/pycgqrqihofDrvDeWeeg
  431. gQyvbZZKl4ylRNj6IRKnosKLVXNqMHQxLmxLHeUCAwEAATANBgkqhkiG9w0BAQsF
  432. AAOCAQEALkKQwa40HfuP4Q6ShwBFJbXLyodIAXCT014kBVjReDKNl5oHtMXRjPxj
  433. nj9doKu+3bLNuLCv9uU3H5+t/GFogReV3Av3z/fCqJ6wHv/KX+lacj31dWXZGD8G
  434. z+RYibrxKkPN0V6q1mSvkg3hJOOE+/4FPIdc8PNlgratv3WS4dT8QwGSUavHW2Kx
  435. 89nIdnwtLEFpgML/bTG0dm8BH57xER8LCYixW1VmpV6A4IsoKVsnB7KUCRTK3iUJ
  436. Zh8Xg8UMNrOtXc1Wx1Wmjaa4ZE9dY6/KkU2ny2UWyDHKU/9VE8QQ4HN93gxU4+H7
  437. cUg0V1uAxqUvKytKkMfcyPWsz/AINA==
  438. -----END CERTIFICATE-----',
  439. 'releases' => [
  440. [
  441. 'download' => 'https://example.com',
  442. 'signature' => 'h8H3tUy2dDlwrV/hY/ZxqYqe8Vue+IINluLtAt1HxX2cjz3vdoVHJRINRkMYYcdz
  443. VlndvHyKdqJHDAACphR8tVV6EFrPermn7gEgWk7a51LbUM7sAN7RV7ijEooUo+TQ
  444. jNW9Ch48Wg3jvebMwWNr5t5U4MEXTP5f0YX/kxvkJoUrG3a3spt7ziEuHaq8IPvt
  445. Jj/JSDFhvRNpom7yNNcI1Ijoq8yC11sg7RJBNfrHdGPHPZVz2SyBiY9OcvgGSpUU
  446. bfvzhIZDCl/RRi5fs39jLLupAP69Ez6+jylNXEMsNwM0YL5+egSXFtkCvgOw8UBg
  447. ZqNZZojcS22acuvHRnoa6PDDhwHdCH+zpifXSOhSQvue5n6q+FVX6aeD1LnCQkYB
  448. D2wvNyZWwdADJtvDj03DKhm21g+TPy63XC94q4IqvjQ94pV8U+qrBBfkQ62NGjaC
  449. oOU6y5sEmQeAdVRpWVo0Hewmjp4Adoj5JRwuqCVEynTC6DXHs3HvHxYlmib1F05a
  450. GqEhdDmOHsxNaeJ08Hlptq5yLv3+0wEdtriVjgAZNVduHG1F1FkhPIrDHaB6pd67
  451. 0AFvO/pZgMSHDRHD+safBgaLb5dBZ895Qvudbq3RQevVnO+YZQYZkpmjoF/+TQ7/
  452. YwDVP+QmNRzx72jtqAN/Kc3CvQ9nkgYhU65B95aX0xA=',
  453. ],
  454. [
  455. 'download' => 'https://nextcloud.com',
  456. ],
  457. ],
  458. ],
  459. ];
  460. $this->appFetcher
  461. ->expects($this->once())
  462. ->method('get')
  463. ->willReturn($appArray);
  464. $realTmpFile = \OC::$server->getTempManager()->getTemporaryFile('.tar.gz');
  465. copy(__DIR__ . '/../data/testapp1.tar.gz', $realTmpFile);
  466. $this->tempManager
  467. ->expects($this->once())
  468. ->method('getTemporaryFile')
  469. ->with('.tar.gz')
  470. ->willReturn($realTmpFile);
  471. $realTmpFolder = \OC::$server->getTempManager()->getTemporaryFolder();
  472. $this->tempManager
  473. ->expects($this->once())
  474. ->method('getTemporaryFolder')
  475. ->willReturn($realTmpFolder);
  476. $client = $this->createMock(IClient::class);
  477. $client
  478. ->expects($this->once())
  479. ->method('get')
  480. ->with('https://example.com', ['sink' => $realTmpFile, 'timeout' => 120]);
  481. $this->clientService
  482. ->expects($this->once())
  483. ->method('newClient')
  484. ->willReturn($client);
  485. $installer = $this->getInstaller();
  486. $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->once())
  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->once())
  545. ->method('getTemporaryFile')
  546. ->with('.tar.gz')
  547. ->willReturn($realTmpFile);
  548. $realTmpFolder = \OC::$server->getTempManager()->getTemporaryFolder();
  549. $this->tempManager
  550. ->expects($this->once())
  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', ['sink' => $realTmpFile, 'timeout' => 120]);
  558. $this->clientService
  559. ->expects($this->once())
  560. ->method('newClient')
  561. ->willReturn($client);
  562. $installer = $this->getInstaller();
  563. $installer->downloadApp('testapp');
  564. $this->assertTrue(file_exists(__DIR__ . '/../../apps/testapp/appinfo/info.xml'));
  565. $this->assertEquals('0.9', \OC_App::getAppVersionByPath(__DIR__ . '/../../apps/testapp/'));
  566. }
  567. public function testDownloadAppWithDowngrade() {
  568. // Use previous test to download the application in version 0.9
  569. $this->testDownloadAppSuccessful();
  570. // Reset mocks
  571. $this->appFetcher = $this->createMock(AppFetcher::class);
  572. $this->clientService = $this->createMock(IClientService::class);
  573. $this->tempManager = $this->createMock(ITempManager::class);
  574. $this->expectException(\Exception::class);
  575. $this->expectExceptionMessage('App for id testapp has version 0.9 and tried to update to lower version 0.8');
  576. $appArray = [
  577. [
  578. 'id' => 'testapp',
  579. 'certificate' => '-----BEGIN CERTIFICATE-----
  580. MIIEAjCCAuoCAhAbMA0GCSqGSIb3DQEBCwUAMHsxCzAJBgNVBAYTAkRFMRswGQYD
  581. VQQIDBJCYWRlbi1XdWVydHRlbWJlcmcxFzAVBgNVBAoMDk5leHRjbG91ZCBHbWJI
  582. MTYwNAYDVQQDDC1OZXh0Y2xvdWQgQ29kZSBTaWduaW5nIEludGVybWVkaWF0ZSBB
  583. dXRob3JpdHkwHhcNMTYxMDMxMTgxNTI2WhcNMjcwMjA2MTgxNTI2WjASMRAwDgYD
  584. VQQDEwd0ZXN0YXBwMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAqa0x
  585. FcVa0YcO/ABqSNdbf7Bzp2PBBJzVM9gI4/HzzBKU/NY9/RibBBpNjAIWEFAbTI4j
  586. ilFSoxHDQ8HrboFOeKCrOIdp9ATQ8SnYVNIQ12Ym3LA/XxcG0gG0H7DeS9C0uACe
  587. svN8fwD1wnKnLLU9GBzO77jwYkneed85wwKG4waHd3965gxQWq0N5gnYS0TTn7Yr
  588. l1veRiw+ryefXvfWI0cN1WBZJ/4XAkwVlpG1HP60AunIpcwn9bfG4XCka+7x26E4
  589. 6Hw0Ot7D7j0yzVzimJDPB2h2buEtPVd6m+oNPueVvKGta+p6cEEaHlFVh2Pa9DI+
  590. me3nb6aXE2kABWXav3BmK18A5Rg4ZY4VFYvmHmxkOhT/ulGZRqy6TccL/optqs52
  591. KQ6P0e5dfmhLeoCvJObD+ZYKv+kJCRFtX1Hve/R4IHG6XSFKUfrRjyor9b6TX2L/
  592. l2vV0mFjmy4g3l05vWHg1Edtq7M29S/xNA3/hF29NjBq6NoMbLGcBtFced1iK07Z
  593. yHLjXRZRfURP671Svqqg8pjxuDqkJ2vIj/Vpod4kF2jeiZYXcfmNKhEhxpkccSe0
  594. dI6p76Ne7XSUpf8yCPiSnWZLadqKZdEulcB4SlrZO2+/pycgqrqihofDrvDeWeeg
  595. gQyvbZZKl4ylRNj6IRKnosKLVXNqMHQxLmxLHeUCAwEAATANBgkqhkiG9w0BAQsF
  596. AAOCAQEALkKQwa40HfuP4Q6ShwBFJbXLyodIAXCT014kBVjReDKNl5oHtMXRjPxj
  597. nj9doKu+3bLNuLCv9uU3H5+t/GFogReV3Av3z/fCqJ6wHv/KX+lacj31dWXZGD8G
  598. z+RYibrxKkPN0V6q1mSvkg3hJOOE+/4FPIdc8PNlgratv3WS4dT8QwGSUavHW2Kx
  599. 89nIdnwtLEFpgML/bTG0dm8BH57xER8LCYixW1VmpV6A4IsoKVsnB7KUCRTK3iUJ
  600. Zh8Xg8UMNrOtXc1Wx1Wmjaa4ZE9dY6/KkU2ny2UWyDHKU/9VE8QQ4HN93gxU4+H7
  601. cUg0V1uAxqUvKytKkMfcyPWsz/AINA==
  602. -----END CERTIFICATE-----',
  603. 'releases' => [
  604. [
  605. 'download' => 'https://example.com',
  606. 'signature' => 'KMSao4cKdMIYxeT8Bm4lrmSeIQnk7YzJZh+Vz+4LVSBwF+OMmcujryQuWLXmbPfg
  607. 4hGI9zS025469VNjUoCprn01H8NBq3O1cXz+ewG1oxYWMMQFZDkOtUQ+XZ27b91t
  608. y0l45H6C8j0sTeSrUb/LCjrdm+buUygkhC2RZxCI6tLi4rYWj0MiqDz98XkbB3te
  609. pW3ZND6mG6Jxn1fnd35paqZ/+URMftoLQ4K+6vJoBVGnug9nk1RpGLouICI0zCrz
  610. YPTsBHo0s2mPvQQ/ASacWYmSe5R6r5JCzNeGMpViGCqCYPbwuebgqK079s2zvSF9
  611. mSLAm2Tk6gCM29N8Vdfr6ppCvIbuNzlLU/dGdYHAILgxEsm/odZjt1Fhs4lOo3A5
  612. 9ToaNl5+qOEkggwfE/QqceHAY2soW9V5d9izhTCDgXmxpPpPXkwPPTz04ZUpi1Yc
  613. OdZZOswbEcc2jUC5T7a7Tnp0uBOkdqat6jB4oMGwU1ldYLCGRyy546cPPTXJw5kH
  614. 9WfeKJ/mavrSLVa7QqZ4RCcMigmijT1kdqbaEh05IZNrzs6VDcS2EIrbDX8SGXUk
  615. uDDkPXZEXqNDEjyONfDXVRLiqDa52Gg+I4vW/l/4ZOFgAWdZkqPPuZFaqzZpsJXm
  616. JXhrdaWDZ8fzpUjugrtC3qslsqL0dzgU37anS3HwrT8=',
  617. ],
  618. [
  619. 'download' => 'https://nextcloud.com',
  620. ],
  621. ],
  622. ],
  623. ];
  624. $this->appFetcher
  625. ->expects($this->once())
  626. ->method('get')
  627. ->willReturn($appArray);
  628. $realTmpFile = \OC::$server->getTempManager()->getTemporaryFile('.tar.gz');
  629. copy(__DIR__ . '/../data/testapp.0.8.tar.gz', $realTmpFile);
  630. $this->tempManager
  631. ->expects($this->once())
  632. ->method('getTemporaryFile')
  633. ->with('.tar.gz')
  634. ->willReturn($realTmpFile);
  635. $realTmpFolder = \OC::$server->getTempManager()->getTemporaryFolder();
  636. $this->tempManager
  637. ->expects($this->once())
  638. ->method('getTemporaryFolder')
  639. ->willReturn($realTmpFolder);
  640. $client = $this->createMock(IClient::class);
  641. $client
  642. ->expects($this->once())
  643. ->method('get')
  644. ->with('https://example.com', ['sink' => $realTmpFile, 'timeout' => 120]);
  645. $this->clientService
  646. ->expects($this->once())
  647. ->method('newClient')
  648. ->willReturn($client);
  649. $this->assertTrue(file_exists(__DIR__ . '/../../apps/testapp/appinfo/info.xml'));
  650. $this->assertEquals('0.9', \OC_App::getAppVersionByPath(__DIR__ . '/../../apps/testapp/'));
  651. $installer = $this->getInstaller();
  652. $installer->downloadApp('testapp');
  653. $this->assertTrue(file_exists(__DIR__ . '/../../apps/testapp/appinfo/info.xml'));
  654. $this->assertEquals('0.8', \OC_App::getAppVersionByPath(__DIR__ . '/../../apps/testapp/'));
  655. }
  656. }