Merge pull request #1940 from nextcloud/new-appstore

Use new appstore API
This commit is contained in:
Michael Grosser 2016-11-02 17:00:24 +00:00 committed by GitHub
commit e81d04cd8d
46 changed files with 2223 additions and 2551 deletions

View file

@ -71,7 +71,8 @@ class UpdaterTest extends TestCase {
*/
function testDeleteParentFolder() {
$status = \OC_App::isEnabled('files_trashbin');
\OC_App::enable('files_trashbin');
(new \OC_App())->enable('files_trashbin');
\OCA\Files_Trashbin\Trashbin::registerHooks();

View file

@ -37,25 +37,20 @@ use OCP\IRequest;
class AppsController extends OCSController {
/** @var \OCP\App\IAppManager */
private $appManager;
/** @var OCSClient */
private $ocsClient;
/**
* @param string $appName
* @param IRequest $request
* @param IAppManager $appManager
* @param OCSClient $ocsClient
*/
public function __construct(
$appName,
IRequest $request,
IAppManager $appManager,
OCSClient $ocsClient
IAppManager $appManager
) {
parent::__construct($appName, $request);
$this->appManager = $appManager;
$this->ocsClient = $ocsClient;
}
/**
@ -64,7 +59,7 @@ class AppsController extends OCSController {
* @throws OCSException
*/
public function getApps($filter = null) {
$apps = OC_App::listAllApps(false, true, $this->ocsClient);
$apps = (new OC_App())->listAllApps();
$list = [];
foreach($apps as $app) {
$list[] = $app['id'];

View file

@ -48,8 +48,6 @@ class AppsControllerTest extends \OCA\Provisioning_API\Tests\TestCase {
private $api;
/** @var IUserSession */
private $userSession;
/** @var OCSClient|\PHPUnit_Framework_MockObject_MockObject */
private $ocsClient;
protected function setUp() {
parent::setUp();
@ -57,9 +55,6 @@ class AppsControllerTest extends \OCA\Provisioning_API\Tests\TestCase {
$this->appManager = \OC::$server->getAppManager();
$this->groupManager = \OC::$server->getGroupManager();
$this->userSession = \OC::$server->getUserSession();
$this->ocsClient = $this->getMockBuilder('OC\OCSClient')
->disableOriginalConstructor()
->getMock();
$request = $this->getMockBuilder('OCP\IRequest')
->disableOriginalConstructor()
@ -68,8 +63,7 @@ class AppsControllerTest extends \OCA\Provisioning_API\Tests\TestCase {
$this->api = new AppsController(
'provisioning_api',
$request,
$this->appManager,
$this->ocsClient
$this->appManager
);
}
@ -88,10 +82,6 @@ class AppsControllerTest extends \OCA\Provisioning_API\Tests\TestCase {
}
public function testGetApps() {
$this->ocsClient
->expects($this->any())
->method($this->anything())
->will($this->returnValue(null));
$user = $this->generateUsers();
$this->groupManager->get('admin')->addUser($user);
$this->userSession->setUser($user);
@ -99,7 +89,7 @@ class AppsControllerTest extends \OCA\Provisioning_API\Tests\TestCase {
$result = $this->api->getApps();
$data = $result->getData();
$this->assertEquals(count(\OC_App::listAllApps(false, true, $this->ocsClient)), count($data['apps']));
$this->assertEquals(count((new \OC_App())->listAllApps()), count($data['apps']));
}
public function testGetAppsEnabled() {
@ -109,13 +99,9 @@ class AppsControllerTest extends \OCA\Provisioning_API\Tests\TestCase {
}
public function testGetAppsDisabled() {
$this->ocsClient
->expects($this->any())
->method($this->anything())
->will($this->returnValue(null));
$result = $this->api->getApps('disabled');
$data = $result->getData();
$apps = \OC_App::listAllApps(false, true, $this->ocsClient);
$apps = (new \OC_App)->listAllApps();
$list = array();
foreach($apps as $app) {
$list[] = $app['id'];

View file

@ -22,7 +22,6 @@
namespace OCA\UpdateNotification\Notification;
use OC\BackgroundJob\TimedJob;
use OC\Installer;
use OC\Updater\VersionCheck;
@ -215,6 +214,6 @@ class BackgroundJob extends TimedJob {
* @return string|false
*/
protected function isUpdateAvailable($app) {
return Installer::isUpdateAvailable($app);
return Installer::isUpdateAvailable($app, \OC::$server->getAppFetcher());
}
}

View file

@ -673,20 +673,6 @@ $CONFIG = array(
*/
'appstoreenabled' => true,
/**
* The URL of the appstore to use.
*/
'appstoreurl' => 'https://api.owncloud.com/v1',
/**
* Whether to show experimental apps in the appstore interface
*
* Experimental apps are not checked for security issues and are new or known
* to be unstable and under heavy development. Installing these can cause data
* loss or security breaches.
*/
'appstore.experimental.enabled' => false,
/**
* Use the ``apps_paths`` parameter to set the location of the Apps directory,
* which should be scanned for available apps, and where user-specific apps

View file

@ -75,11 +75,12 @@ class Enable extends Command implements CompletionAwareInterface {
}
$groups = $input->getOption('groups');
$appClass = new \OC_App();
if (empty($groups)) {
\OC_App::enable($appId);
$appClass->enable($appId);
$output->writeln($appId . ' enabled');
} else {
\OC_App::enable($appId, $groups);
$appClass->enable($appId, $groups);
$output->writeln($appId . ' enabled for groups: ' . implode(', ', $groups));
}
return 0;

View file

@ -279,6 +279,11 @@ return array(
'OC\\AppFramework\\Utility\\TimeFactory' => $baseDir . '/lib/private/AppFramework/Utility/TimeFactory.php',
'OC\\AppHelper' => $baseDir . '/lib/private/AppHelper.php',
'OC\\App\\AppManager' => $baseDir . '/lib/private/App/AppManager.php',
'OC\\App\\AppStore\\Fetcher\\AppFetcher' => $baseDir . '/lib/private/App/AppStore/Fetcher/AppFetcher.php',
'OC\\App\\AppStore\\Fetcher\\CategoryFetcher' => $baseDir . '/lib/private/App/AppStore/Fetcher/CategoryFetcher.php',
'OC\\App\\AppStore\\Fetcher\\Fetcher' => $baseDir . '/lib/private/App/AppStore/Fetcher/Fetcher.php',
'OC\\App\\AppStore\\Version\\Version' => $baseDir . '/lib/private/App/AppStore/Version/Version.php',
'OC\\App\\AppStore\\Version\\VersionParser' => $baseDir . '/lib/private/App/AppStore/Version/VersionParser.php',
'OC\\App\\CodeChecker\\AbstractCheck' => $baseDir . '/lib/private/App/CodeChecker/AbstractCheck.php',
'OC\\App\\CodeChecker\\CodeChecker' => $baseDir . '/lib/private/App/CodeChecker/CodeChecker.php',
'OC\\App\\CodeChecker\\DeprecationCheck' => $baseDir . '/lib/private/App/CodeChecker/DeprecationCheck.php',
@ -602,7 +607,6 @@ return array(
'OC\\Notification\\Action' => $baseDir . '/lib/private/Notification/Action.php',
'OC\\Notification\\Manager' => $baseDir . '/lib/private/Notification/Manager.php',
'OC\\Notification\\Notification' => $baseDir . '/lib/private/Notification/Notification.php',
'OC\\OCSClient' => $baseDir . '/lib/private/OCSClient.php',
'OC\\OCS\\CoreCapabilities' => $baseDir . '/lib/private/OCS/CoreCapabilities.php',
'OC\\OCS\\Exception' => $baseDir . '/lib/private/OCS/Exception.php',
'OC\\OCS\\Person' => $baseDir . '/lib/private/OCS/Person.php',

View file

@ -309,6 +309,11 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\AppFramework\\Utility\\TimeFactory' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Utility/TimeFactory.php',
'OC\\AppHelper' => __DIR__ . '/../../..' . '/lib/private/AppHelper.php',
'OC\\App\\AppManager' => __DIR__ . '/../../..' . '/lib/private/App/AppManager.php',
'OC\\App\\AppStore\\Fetcher\\AppFetcher' => __DIR__ . '/../../..' . '/lib/private/App/AppStore/Fetcher/AppFetcher.php',
'OC\\App\\AppStore\\Fetcher\\CategoryFetcher' => __DIR__ . '/../../..' . '/lib/private/App/AppStore/Fetcher/CategoryFetcher.php',
'OC\\App\\AppStore\\Fetcher\\Fetcher' => __DIR__ . '/../../..' . '/lib/private/App/AppStore/Fetcher/Fetcher.php',
'OC\\App\\AppStore\\Version\\Version' => __DIR__ . '/../../..' . '/lib/private/App/AppStore/Version/Version.php',
'OC\\App\\AppStore\\Version\\VersionParser' => __DIR__ . '/../../..' . '/lib/private/App/AppStore/Version/VersionParser.php',
'OC\\App\\CodeChecker\\AbstractCheck' => __DIR__ . '/../../..' . '/lib/private/App/CodeChecker/AbstractCheck.php',
'OC\\App\\CodeChecker\\CodeChecker' => __DIR__ . '/../../..' . '/lib/private/App/CodeChecker/CodeChecker.php',
'OC\\App\\CodeChecker\\DeprecationCheck' => __DIR__ . '/../../..' . '/lib/private/App/CodeChecker/DeprecationCheck.php',
@ -632,7 +637,6 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Notification\\Action' => __DIR__ . '/../../..' . '/lib/private/Notification/Action.php',
'OC\\Notification\\Manager' => __DIR__ . '/../../..' . '/lib/private/Notification/Manager.php',
'OC\\Notification\\Notification' => __DIR__ . '/../../..' . '/lib/private/Notification/Notification.php',
'OC\\OCSClient' => __DIR__ . '/../../..' . '/lib/private/OCSClient.php',
'OC\\OCS\\CoreCapabilities' => __DIR__ . '/../../..' . '/lib/private/OCS/CoreCapabilities.php',
'OC\\OCS\\Exception' => __DIR__ . '/../../..' . '/lib/private/OCS/Exception.php',
'OC\\OCS\\Person' => __DIR__ . '/../../..' . '/lib/private/OCS/Person.php',

View file

@ -0,0 +1,56 @@
<?php
/**
* @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OC\App\AppStore\Fetcher;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\IAppData;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
class AppFetcher extends Fetcher {
/**
* @param IAppData $appData
* @param IClientService $clientService
* @param ITimeFactory $timeFactory
* @param IConfig $config;
*/
public function __construct(IAppData $appData,
IClientService $clientService,
ITimeFactory $timeFactory,
IConfig $config) {
parent::__construct(
$appData,
$clientService,
$timeFactory
);
$this->fileName = 'apps.json';
$versionArray = \OC_Util::getVersion();
$this->endpointUrl = sprintf(
'https://apps.nextcloud.com/api/v1/platform/%d.%d.%d/apps.json',
$versionArray[0],
$versionArray[1],
$versionArray[2]
);
}
}

View file

@ -0,0 +1,45 @@
<?php
/**
* @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OC\App\AppStore\Fetcher;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\IAppData;
use OCP\Http\Client\IClientService;
class CategoryFetcher extends Fetcher {
/**
* @param IAppData $appData
* @param IClientService $clientService
* @param ITimeFactory $timeFactory
*/
public function __construct(IAppData $appData,
IClientService $clientService,
ITimeFactory $timeFactory) {
parent::__construct(
$appData,
$clientService,
$timeFactory
);
$this->fileName = 'categories.json';
$this->endpointUrl = 'https://apps.nextcloud.com/api/v1/categories.json';
}
}

View file

@ -0,0 +1,92 @@
<?php
/**
* @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OC\App\AppStore\Fetcher;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\IAppData;
use OCP\Files\NotFoundException;
use OCP\Http\Client\IClientService;
abstract class Fetcher {
const INVALIDATE_AFTER_SECONDS = 300;
/** @var IAppData */
private $appData;
/** @var IClientService */
private $clientService;
/** @var ITimeFactory */
private $timeFactory;
/** @var string */
protected $fileName;
/** @var string */
protected $endpointUrl;
/**
* @param IAppData $appData
* @param IClientService $clientService
* @param ITimeFactory $timeFactory
*/
public function __construct(IAppData $appData,
IClientService $clientService,
ITimeFactory $timeFactory) {
$this->appData = $appData;
$this->clientService = $clientService;
$this->timeFactory = $timeFactory;
}
/**
* Returns the array with the categories on the appstore server
*
* @return array
*/
public function get() {
$rootFolder = $this->appData->getFolder('/');
try {
// File does already exists
$file = $rootFolder->getFile($this->fileName);
$jsonBlob = json_decode($file->getContent(), true);
if(is_array($jsonBlob)) {
// If the timestamp is older than 300 seconds request the files new
if((int)$jsonBlob['timestamp'] > ($this->timeFactory->getTime() - self::INVALIDATE_AFTER_SECONDS)) {
return $jsonBlob['data'];
}
}
} catch (NotFoundException $e) {
// File does not already exists
$file = $rootFolder->newFile($this->fileName);
}
// Refresh the file content
$client = $this->clientService->newClient();
try {
$response = $client->get($this->endpointUrl);
$responseJson = [];
$responseJson['data'] = json_decode($response->getBody(), true);
$responseJson['timestamp'] = $this->timeFactory->getTime();
$file->putContent(json_encode($responseJson));
return json_decode($file->getContent(), true)['data'];
} catch (\Exception $e) {
return [];
}
}
}

View file

@ -0,0 +1,52 @@
<?php
/**
* @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OC\App\AppStore\Version;
class Version {
/** @var string */
private $minVersion;
/** @var string */
private $maxVersion;
/**
* @param string $minVersion
* @param string $maxVersion
*/
public function __construct($minVersion, $maxVersion) {
$this->minVersion = $minVersion;
$this->maxVersion = $maxVersion;
}
/**
* @return string
*/
public function getMinimumVersion() {
return $this->minVersion;
}
/**
* @return string
*/
public function getMaximumVersion() {
return $this->maxVersion;
}
}

View file

@ -0,0 +1,83 @@
<?php
/**
* @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OC\App\AppStore\Version;
/**
* Class VersionParser parses the versions as sent by the Nextcloud app store
*
* @package OC\App\AppStore
*/
class VersionParser {
/**
* @param string $versionString
* @return bool
*/
private function isValidVersionString($versionString) {
return (bool)preg_match('/^[0-9.]+$/', $versionString);
}
/**
* Returns the version for a version string
*
* @param string $versionSpec
* @return Version
* @throws \Exception If the version cannot be parsed
*/
public function getVersion($versionSpec) {
// * indicates that the version is compatible with all versions
if($versionSpec === '*') {
return new Version('', '');
}
// Count the amount of =, if it is one then it's either maximum or minimum
// version. If it is two then it is maximum and minimum.
$versionElements = explode(' ', $versionSpec);
$firstVersion = isset($versionElements[0]) ? $versionElements[0] : '';
$firstVersionNumber = substr($firstVersion, 2);
$secondVersion = isset($versionElements[1]) ? $versionElements[1] : '';
$secondVersionNumber = substr($secondVersion, 2);
switch(count($versionElements)) {
case 1:
if(!$this->isValidVersionString($firstVersionNumber)) {
break;
}
if(substr($firstVersion, 0, 1) === '>') {
return new Version($firstVersionNumber, '');
} else {
return new Version('', $firstVersionNumber);
}
case 2:
if(!$this->isValidVersionString($firstVersionNumber) || !$this->isValidVersionString($secondVersionNumber)) {
break;
}
return new Version($firstVersionNumber, $secondVersionNumber);
}
throw new \Exception(
sprintf(
'Version cannot be parsed: %s',
$versionSpec
)
);
}
}

View file

@ -1,6 +1,7 @@
<?php
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
* @copyright Copyright (c) 2016, Lukas Reschke <lukas@statuscode.ch>
*
* @author Bernhard Posselt <dev@bernhard-posselt.com>
* @author Joas Schilling <coding@schilljs.com>
@ -294,7 +295,9 @@ class DependencyAnalyzer {
private function analyzeOC(array $dependencies, array $appInfo) {
$missing = [];
$minVersion = null;
if (isset($dependencies['owncloud']['@attributes']['min-version'])) {
if (isset($dependencies['nextcloud']['@attributes']['min-version'])) {
$minVersion = $dependencies['nextcloud']['@attributes']['min-version'];
} elseif (isset($dependencies['owncloud']['@attributes']['min-version'])) {
$minVersion = $dependencies['owncloud']['@attributes']['min-version'];
} elseif (isset($appInfo['requiremin'])) {
$minVersion = $appInfo['requiremin'];
@ -302,7 +305,9 @@ class DependencyAnalyzer {
$minVersion = $appInfo['require'];
}
$maxVersion = null;
if (isset($dependencies['owncloud']['@attributes']['max-version'])) {
if (isset($dependencies['nextcloud']['@attributes']['max-version'])) {
$maxVersion = $dependencies['nextcloud']['@attributes']['max-version'];
} elseif (isset($dependencies['owncloud']['@attributes']['max-version'])) {
$maxVersion = $dependencies['owncloud']['@attributes']['max-version'];
} elseif (isset($appInfo['requiremax'])) {
$maxVersion = $appInfo['requiremax'];

View file

@ -32,26 +32,7 @@
namespace OC\Archive;
abstract class Archive{
/**
* Open any of the supported archive types
*
* @param string $path
* @return Archive|void
*/
public static function open($path) {
$mime = \OC::$server->getMimeTypeDetector()->detect($path);
switch($mime) {
case 'application/zip':
return new ZIP($path);
case 'application/x-gzip':
return new TAR($path);
case 'application/x-bzip2':
return new TAR($path);
}
}
abstract class Archive {
/**
* @param $source
*/

View file

@ -1,6 +1,7 @@
<?php
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
* @copyright Copyright (c) 2016, Lukas Reschke <lukas@statuscode.ch>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Bart Visscher <bartv@thisnet.nl>
@ -40,90 +41,64 @@
namespace OC;
use OC\App\AppStore\Fetcher\AppFetcher;
use OC\App\CodeChecker\CodeChecker;
use OC\App\CodeChecker\EmptyCheck;
use OC\App\CodeChecker\PrivateCheck;
use OC\Archive\Archive;
use OC\Archive\TAR;
use OC_App;
use OC_DB;
use OC_Helper;
use OCP\Http\Client\IClientService;
use OCP\ILogger;
use OCP\ITempManager;
use phpseclib\File\X509;
/**
* This class provides the functionality needed to install, update and remove plugins/apps
* This class provides the functionality needed to install, update and remove apps
*/
class Installer {
/** @var AppFetcher */
private $appFetcher;
/** @var IClientService */
private $clientService;
/** @var ITempManager */
private $tempManager;
/** @var ILogger */
private $logger;
/**
* @param AppFetcher $appFetcher
* @param IClientService $clientService
* @param ITempManager $tempManager
* @param ILogger $logger
*/
public function __construct(AppFetcher $appFetcher,
IClientService $clientService,
ITempManager $tempManager,
ILogger $logger) {
$this->appFetcher = $appFetcher;
$this->clientService = $clientService;
$this->tempManager = $tempManager;
$this->logger = $logger;
}
/**
* Installs an app that is located in one of the app folders already
*
* This function installs an app. All information needed are passed in the
* associative array $data.
* The following keys are required:
* - source: string, can be "path" or "http"
*
* One of the following keys is required:
* - path: path to the file containing the app
* - href: link to the downloadable file containing the app
*
* The following keys are optional:
* - pretend: boolean, if set true the system won't do anything
* - noinstall: boolean, if true appinfo/install.php won't be loaded
* - inactive: boolean, if set true the appconfig/app.sample.php won't be
* renamed
*
* This function works as follows
* -# fetching the file
* -# unzipping it
* -# check the code
* -# installing the database at appinfo/database.xml
* -# including appinfo/install.php
* -# setting the installed version
*
* It is the task of oc_app_install to create the tables and do whatever is
* needed to get the app working.
*
* Installs an app
* @param array $data with all information
* @param string $appId App to install
* @throws \Exception
* @return integer
*/
public static function installApp( $data = array()) {
$l = \OC::$server->getL10N('lib');
list($extractDir, $path) = self::downloadApp($data);
$info = self::checkAppsIntegrity($data, $extractDir, $path);
$appId = OC_App::cleanAppId($info['id']);
$basedir = OC_App::getInstallPath().'/'.$appId;
//check if the destination directory already exists
if(is_dir($basedir)) {
OC_Helper::rmdirr($extractDir);
if($data['source']=='http') {
unlink($path);
}
throw new \Exception($l->t("App directory already exists"));
public function installApp($appId) {
$app = \OC_App::findAppInDirectories($appId);
if($app === false) {
throw new \Exception('App not found in any app directory');
}
if(!empty($data['pretent'])) {
return false;
}
//copy the app to the correct place
if(@!mkdir($basedir)) {
OC_Helper::rmdirr($extractDir);
if($data['source']=='http') {
unlink($path);
}
throw new \Exception($l->t("Can't create app folder. Please fix permissions. %s", array($basedir)));
}
$extractDir .= '/' . $info['id'];
if(!file_exists($extractDir)) {
OC_Helper::rmdirr($basedir);
throw new \Exception($l->t("Archive does not contain a directory named %s", $info['id']));
}
OC_Helper::copyr($extractDir, $basedir);
//remove temporary files
OC_Helper::rmdirr($extractDir);
$basedir = $app['path'].'/'.$appId;
$info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true);
//install the database
if(is_file($basedir.'/appinfo/database.xml')) {
@ -168,259 +143,189 @@ class Installer {
*
* Checks whether or not an app is installed, i.e. registered in apps table.
*/
public static function isInstalled( $app ) {
public static function isInstalled( $app ) {
return (\OC::$server->getConfig()->getAppValue($app, "installed_version", null) !== null);
}
/**
* @brief Update an application
* @param array $info
* @param bool $isShipped
* @throws \Exception
* Updates the specified app from the appstore
*
* @param string $appId
* @return bool
*
* This function could work like described below, but currently it disables and then
* enables the app again. This does result in an updated app.
*
*
* This function installs an app. All information needed are passed in the
* associative array $info.
* The following keys are required:
* - source: string, can be "path" or "http"
*
* One of the following keys is required:
* - path: path to the file containing the app
* - href: link to the downloadable file containing the app
*
* The following keys are optional:
* - pretend: boolean, if set true the system won't do anything
* - noupgrade: boolean, if true appinfo/upgrade.php won't be loaded
*
* This function works as follows
* -# fetching the file
* -# removing the old files
* -# unzipping new file
* -# including appinfo/upgrade.php
* -# setting the installed version
*
* upgrade.php can determine the current installed version of the app using
* "\OC::$server->getAppConfig()->getValue($appid, 'installed_version')"
*/
public static function updateApp($info=array(), $isShipped=false) {
list($extractDir, $path) = self::downloadApp($info);
$info = self::checkAppsIntegrity($info, $extractDir, $path, $isShipped);
$currentDir = OC_App::getAppPath($info['id']);
$basedir = OC_App::getInstallPath();
$basedir .= '/';
$basedir .= $info['id'];
if($currentDir !== false && is_writable($currentDir)) {
$basedir = $currentDir;
}
if(is_dir($basedir)) {
OC_Helper::rmdirr($basedir);
public function updateAppstoreApp($appId) {
if(self::isUpdateAvailable($appId, $this->appFetcher)) {
try {
$this->downloadApp($appId);
} catch (\Exception $e) {
$this->logger->error($e->getMessage(), ['app' => 'core']);
return false;
}
return OC_App::updateApp($appId);
}
$appInExtractDir = $extractDir;
if (substr($extractDir, -1) !== '/') {
$appInExtractDir .= '/';
}
$appInExtractDir .= $info['id'];
OC_Helper::copyr($appInExtractDir, $basedir);
OC_Helper::rmdirr($extractDir);
return OC_App::updateApp($info['id']);
return false;
}
/**
* update an app by it's id
* Downloads an app and puts it into the app directory
*
* @param integer $ocsId
* @return bool
* @throws \Exception
* @param string $appId
*
* @throws \Exception If the installation was not successful
*/
public static function updateAppByOCSId($ocsId) {
$ocsClient = new OCSClient(
\OC::$server->getHTTPClientService(),
\OC::$server->getConfig(),
\OC::$server->getLogger()
);
$appData = $ocsClient->getApplication($ocsId, \OCP\Util::getVersion());
$download = $ocsClient->getApplicationDownload($ocsId, \OCP\Util::getVersion());
public function downloadApp($appId) {
$appId = strtolower($appId);
if (isset($download['downloadlink']) && trim($download['downloadlink']) !== '') {
$download['downloadlink'] = str_replace(' ', '%20', $download['downloadlink']);
$info = array(
'source' => 'http',
'href' => $download['downloadlink'],
'appdata' => $appData
);
} else {
throw new \Exception('Could not fetch app info!');
}
$apps = $this->appFetcher->get();
foreach($apps as $app) {
if($app['id'] === $appId) {
// Load the certificate
$certificate = new X509();
$certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt'));
$loadedCertificate = $certificate->loadX509($app['certificate']);
return self::updateApp($info);
}
// Verify if the certificate has been revoked
$crl = new X509();
$crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt'));
$crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl'));
if($crl->validateSignature() !== true) {
throw new \Exception('Could not validate CRL signature');
}
$csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString();
$revoked = $crl->getRevoked($csn);
if ($revoked !== false) {
throw new \Exception(
sprintf(
'Certificate "%s" has been revoked',
$csn
)
);
}
/**
* @param array $data
* @return array
* @throws \Exception
*/
public static function downloadApp($data = array()) {
$l = \OC::$server->getL10N('lib');
// Verify if the certificate has been issued by the Nextcloud Code Authority CA
if($certificate->validateSignature() !== true) {
throw new \Exception(
sprintf(
'App with id %s has a certificate not issued by a trusted Code Signing Authority',
$appId
)
);
}
if(!isset($data['source'])) {
throw new \Exception($l->t("No source specified when installing app"));
}
// Verify if the certificate is issued for the requested app id
$certInfo = openssl_x509_parse($app['certificate']);
if(!isset($certInfo['subject']['CN'])) {
throw new \Exception(
sprintf(
'App with id %s has a cert with no CN',
$appId
)
);
}
if($certInfo['subject']['CN'] !== $appId) {
throw new \Exception(
sprintf(
'App with id %s has a cert issued to %s',
$appId,
$certInfo['subject']['CN']
)
);
}
//download the file if necessary
if($data['source']=='http') {
$pathInfo = pathinfo($data['href']);
$extension = isset($pathInfo['extension']) ? '.' . $pathInfo['extension'] : '';
$path = \OC::$server->getTempManager()->getTemporaryFile($extension);
if(!isset($data['href'])) {
throw new \Exception($l->t("No href specified when installing app from http"));
}
$client = \OC::$server->getHTTPClientService()->newClient();
$client->get($data['href'], ['save_to' => $path]);
} else {
if(!isset($data['path'])) {
throw new \Exception($l->t("No path specified when installing app from local file"));
}
$path=$data['path'];
}
// Download the release
$tempFile = $this->tempManager->getTemporaryFile('.tar.gz');
$client = $this->clientService->newClient();
$client->get($app['releases'][0]['download'], ['save_to' => $tempFile]);
//detect the archive type
$mime = \OC::$server->getMimeTypeDetector()->detect($path);
if ($mime !=='application/zip' && $mime !== 'application/x-gzip' && $mime !== 'application/x-bzip2') {
throw new \Exception($l->t("Archives of type %s are not supported", array($mime)));
}
// Check if the signature actually matches the downloaded content
$certificate = openssl_get_publickey($app['certificate']);
$verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512);
openssl_free_key($certificate);
//extract the archive in a temporary folder
$extractDir = \OC::$server->getTempManager()->getTemporaryFolder();
OC_Helper::rmdirr($extractDir);
mkdir($extractDir);
if($archive=\OC\Archive\Archive::open($path)) {
$archive->extract($extractDir);
} else {
OC_Helper::rmdirr($extractDir);
if($data['source']=='http') {
unlink($path);
}
throw new \Exception($l->t("Failed to open archive when installing app"));
}
if($verified === true) {
// Seems to match, let's proceed
$extractDir = $this->tempManager->getTemporaryFolder();
$archive = new TAR($tempFile);
return array(
$extractDir,
$path
);
}
if($archive) {
$archive->extract($extractDir);
$allFiles = scandir($extractDir);
$folders = array_diff($allFiles, ['.', '..']);
$folders = array_values($folders);
/**
* check an app's integrity
* @param array $data
* @param string $extractDir
* @param string $path
* @param bool $isShipped
* @return array
* @throws \Exception
*/
public static function checkAppsIntegrity($data, $extractDir, $path, $isShipped = false) {
$l = \OC::$server->getL10N('lib');
//load the info.xml file of the app
if(!is_file($extractDir.'/appinfo/info.xml')) {
//try to find it in a subdir
$dh=opendir($extractDir);
if(is_resource($dh)) {
while (($folder = readdir($dh)) !== false) {
if($folder[0]!='.' and is_dir($extractDir.'/'.$folder)) {
if(is_file($extractDir.'/'.$folder.'/appinfo/info.xml')) {
$extractDir.='/'.$folder;
if(count($folders) > 1) {
throw new \Exception(
sprintf(
'Extracted app %s has more than 1 folder',
$appId
)
);
}
// Check if appinfo/info.xml has the same app ID as well
$loadEntities = libxml_disable_entity_loader(false);
$xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml');
libxml_disable_entity_loader($loadEntities);
if((string)$xml->id !== $appId) {
throw new \Exception(
sprintf(
'App for id %s has a wrong app ID in info.xml: %s',
$appId,
(string)$xml->id
)
);
}
$baseDir = OC_App::getInstallPath() . '/' . $appId;
// Remove old app with the ID if existent
OC_Helper::rmdirr($baseDir);
// Move to app folder
if(@mkdir($baseDir)) {
$extractDir .= '/' . $folders[0];
OC_Helper::copyr($extractDir, $baseDir);
}
OC_Helper::copyr($extractDir, $baseDir);
OC_Helper::rmdirr($extractDir);
return;
} else {
throw new \Exception(
sprintf(
'Could not extract app with ID %s to %s',
$appId,
$extractDir
)
);
}
} else {
// Signature does not match
throw new \Exception(
sprintf(
'App with id %s has invalid signature',
$appId
)
);
}
}
}
if(!is_file($extractDir.'/appinfo/info.xml')) {
OC_Helper::rmdirr($extractDir);
if($data['source'] === 'http') {
unlink($path);
}
throw new \Exception($l->t("App does not provide an info.xml file"));
}
$info = OC_App::getAppInfo($extractDir.'/appinfo/info.xml', true);
if(!is_array($info)) {
throw new \Exception($l->t('App cannot be installed because appinfo file cannot be read.'));
}
// We can't trust the parsed info.xml file as it may have been tampered
// with by an attacker and thus we need to use the local data to check
// whether the application needs to be signed.
$appId = OC_App::cleanAppId($data['appdata']['id']);
$appBelongingToId = OC_App::getInternalAppIdByOcs($appId);
if(is_string($appBelongingToId)) {
$previouslySigned = \OC::$server->getConfig()->getAppValue($appBelongingToId, 'signed', 'false');
} else {
$appBelongingToId = $info['id'];
$previouslySigned = 'false';
}
if($data['appdata']['level'] === OC_App::officialApp || $previouslySigned === 'true') {
\OC::$server->getConfig()->setAppValue($appBelongingToId, 'signed', 'true');
$integrityResult = \OC::$server->getIntegrityCodeChecker()->verifyAppSignature(
$appBelongingToId,
$extractDir
);
if($integrityResult !== []) {
$e = new \Exception(
$l->t(
'Signature could not get checked. Please contact the app developer and check your admin screen.'
)
);
throw $e;
}
}
// check the code for not allowed calls
if(!$isShipped && !Installer::checkCode($extractDir)) {
OC_Helper::rmdirr($extractDir);
throw new \Exception($l->t("App can't be installed because of not allowed code in the App"));
}
// check if the app is compatible with this version of ownCloud
if(!OC_App::isAppCompatible(\OCP\Util::getVersion(), $info)) {
OC_Helper::rmdirr($extractDir);
throw new \Exception($l->t("App can't be installed because it is not compatible with this version of the server"));
}
// check if shipped tag is set which is only allowed for apps that are shipped with ownCloud
if(!$isShipped && isset($info['shipped']) && ($info['shipped']=='true')) {
OC_Helper::rmdirr($extractDir);
throw new \Exception($l->t("App can't be installed because it contains the <shipped>true</shipped> tag which is not allowed for non shipped apps"));
}
// check if the ocs version is the same as the version in info.xml/version
$version = trim($info['version']);
if(isset($data['appdata']['version']) && $version<>trim($data['appdata']['version'])) {
OC_Helper::rmdirr($extractDir);
throw new \Exception($l->t("App can't be installed because the version in info.xml is not the same as the version reported from the app store"));
}
return $info;
throw new \Exception(
sprintf(
'Could not download app %s',
$appId
)
);
}
/**
* Check if an update for the app is available
* @param string $app
* @return string|false false or the version number of the update
*
* The function will check if an update for a version is available
* @param string $appId
* @param AppFetcher $appFetcher
* @return string|false false or the version number of the update
*/
public static function isUpdateAvailable( $app ) {
public static function isUpdateAvailable($appId,
AppFetcher $appFetcher) {
static $isInstanceReadyForUpdates = null;
if ($isInstanceReadyForUpdates === null) {
@ -436,27 +341,20 @@ class Installer {
return false;
}
$ocsid=\OC::$server->getAppConfig()->getValue( $app, 'ocsid', '');
if($ocsid<>'') {
$ocsClient = new OCSClient(
\OC::$server->getHTTPClientService(),
\OC::$server->getConfig(),
\OC::$server->getLogger()
);
$ocsdata = $ocsClient->getApplication($ocsid, \OCP\Util::getVersion());
$ocsversion= (string) $ocsdata['version'];
$currentversion=OC_App::getAppVersion($app);
if (version_compare($ocsversion, $currentversion, '>')) {
return($ocsversion);
}else{
return false;
$apps = $appFetcher->get();
foreach($apps as $app) {
if($app['id'] === $appId) {
$currentVersion = OC_App::getAppVersion($appId);
$newestVersion = $app['releases'][0]['version'];
if (version_compare($newestVersion, $currentVersion, '>')) {
return $newestVersion;
} else {
return false;
}
}
}else{
return false;
}
return false;
}
/**
@ -466,7 +364,7 @@ class Installer {
*
* The function will check if the app is already downloaded in the apps repository
*/
public static function isDownloaded( $name ) {
public function isDownloaded($name) {
foreach(\OC::$APPSROOTS as $dir) {
$dirToTest = $dir['path'];
$dirToTest .= '/';
@ -483,7 +381,7 @@ class Installer {
/**
* Removes an app
* @param string $name name of the application to remove
* @param string $appId ID of the application to remove
* @return boolean
*
*
@ -494,12 +392,10 @@ class Installer {
* The function will not delete preferences, tables and the configuration,
* this has to be done by the function oc_app_uninstall().
*/
public static function removeApp($appId) {
if(Installer::isDownloaded( $appId )) {
$appDir=OC_App::getInstallPath() . '/' . $appId;
public function removeApp($appId) {
if($this->isDownloaded( $appId )) {
$appDir = OC_App::getInstallPath() . '/' . $appId;
OC_Helper::rmdirr($appDir);
return true;
}else{
\OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR);
@ -620,7 +516,7 @@ class Installer {
}
/**
* @param $basedir
* @param string $script
*/
private static function includeAppScript($script) {
if ( file_exists($script) ){

View file

@ -1,351 +0,0 @@
<?php
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Bart Visscher <bartv@thisnet.nl>
* @author Brice Maron <brice@bmaron.net>
* @author Felix Moeller <mail@felixmoeller.de>
* @author Frank Karlitschek <frank@karlitschek.de>
* @author Jarrett <JetUni@users.noreply.github.com>
* @author Joas Schilling <coding@schilljs.com>
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
* @author Kamil Domanski <kdomanski@kdemail.net>
* @author Lukas Reschke <lukas@statuscode.ch>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Robin McCorkell <robin@mccorkell.me.uk>
* @author Sam Tuke <mail@samtuke.com>
* @author Thomas Müller <thomas.mueller@tmit.eu>
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OC;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\ILogger;
/**
* Class OCSClient is a class for communication with the ownCloud appstore
*
* @package OC
*/
class OCSClient {
/** @var IClientService */
private $httpClientService;
/** @var IConfig */
private $config;
/** @var ILogger */
private $logger;
/**
* @param IClientService $httpClientService
* @param IConfig $config
* @param ILogger $logger
*/
public function __construct(IClientService $httpClientService,
IConfig $config,
ILogger $logger) {
$this->httpClientService = $httpClientService;
$this->config = $config;
$this->logger = $logger;
}
/**
* Returns whether the AppStore is enabled (i.e. because the AppStore is disabled for EE)
*
* @return bool
*/
public function isAppStoreEnabled() {
return $this->config->getSystemValue('appstoreenabled', true) === true;
}
/**
* Get the url of the OCS AppStore server.
*
* @return string of the AppStore server
*/
private function getAppStoreUrl() {
return $this->config->getSystemValue('appstoreurl', 'https://api.owncloud.com/v1');
}
/**
* @param string $body
* @param string $action
* @return null|\SimpleXMLElement
*/
private function loadData($body, $action) {
$loadEntities = libxml_disable_entity_loader(true);
$data = @simplexml_load_string($body);
libxml_disable_entity_loader($loadEntities);
if($data === false) {
libxml_clear_errors();
$this->logger->error(
sprintf('Could not get %s, content was no valid XML', $action),
[
'app' => 'core',
]
);
return null;
}
return $data;
}
/**
* Get all the categories from the OCS server
*
* @param array $targetVersion The target ownCloud version
* @return array|null an array of category ids or null
* @note returns NULL if config value appstoreenabled is set to false
* This function returns a list of all the application categories on the OCS server
*/
public function getCategories(array $targetVersion) {
if (!$this->isAppStoreEnabled()) {
return null;
}
$client = $this->httpClientService->newClient();
try {
$response = $client->get(
$this->getAppStoreUrl() . '/content/categories',
[
'timeout' => 20,
'query' => [
'version' => implode('x', $targetVersion),
],
]
);
} catch(\Exception $e) {
$this->logger->error(
sprintf('Could not get categories: %s', $e->getMessage()),
[
'app' => 'core',
]
);
return null;
}
$data = $this->loadData($response->getBody(), 'categories');
if($data === null) {
return null;
}
$tmp = $data->data;
$cats = [];
foreach ($tmp->category as $value) {
$id = (int)$value->id;
$name = (string)$value->name;
$cats[$id] = $name;
}
return $cats;
}
/**
* Get all the applications from the OCS server
* @param array $categories
* @param int $page
* @param string $filter
* @param array $targetVersion The target ownCloud version
* @return array An array of application data
*/
public function getApplications(array $categories, $page, $filter, array $targetVersion) {
if (!$this->isAppStoreEnabled()) {
return [];
}
$client = $this->httpClientService->newClient();
try {
$response = $client->get(
$this->getAppStoreUrl() . '/content/data',
[
'timeout' => 20,
'query' => [
'version' => implode('x', $targetVersion),
'filter' => $filter,
'categories' => implode('x', $categories),
'sortmode' => 'new',
'page' => $page,
'pagesize' => 100,
'approved' => $filter
],
]
);
} catch(\Exception $e) {
$this->logger->error(
sprintf('Could not get applications: %s', $e->getMessage()),
[
'app' => 'core',
]
);
return [];
}
$data = $this->loadData($response->getBody(), 'applications');
if($data === null) {
return [];
}
$tmp = $data->data->content;
$tmpCount = count($tmp);
$apps = [];
for ($i = 0; $i < $tmpCount; $i++) {
$app = [];
$app['id'] = (string)$tmp[$i]->id;
$app['name'] = (string)$tmp[$i]->name;
$app['label'] = (string)$tmp[$i]->label;
$app['version'] = (string)$tmp[$i]->version;
$app['type'] = (string)$tmp[$i]->typeid;
$app['typename'] = (string)$tmp[$i]->typename;
$app['personid'] = (string)$tmp[$i]->personid;
$app['profilepage'] = (string)$tmp[$i]->profilepage;
$app['license'] = (string)$tmp[$i]->license;
$app['detailpage'] = (string)$tmp[$i]->detailpage;
$app['preview'] = (string)$tmp[$i]->smallpreviewpic1;
$app['preview-full'] = (string)$tmp[$i]->previewpic1;
$app['changed'] = strtotime($tmp[$i]->changed);
$app['description'] = (string)$tmp[$i]->description;
$app['score'] = (string)$tmp[$i]->score;
$app['downloads'] = (int)$tmp[$i]->downloads;
$app['level'] = (int)$tmp[$i]->approved;
$apps[] = $app;
}
return $apps;
}
/**
* Get an the applications from the OCS server
*
* @param string $id
* @param array $targetVersion The target ownCloud version
* @return array|null an array of application data or null
*
* This function returns an applications from the OCS server
*/
public function getApplication($id, array $targetVersion) {
if (!$this->isAppStoreEnabled()) {
return null;
}
$client = $this->httpClientService->newClient();
try {
$response = $client->get(
$this->getAppStoreUrl() . '/content/data/' . urlencode($id),
[
'timeout' => 20,
'query' => [
'version' => implode('x', $targetVersion),
],
]
);
} catch(\Exception $e) {
$this->logger->error(
sprintf('Could not get application: %s', $e->getMessage()),
[
'app' => 'core',
]
);
return null;
}
$data = $this->loadData($response->getBody(), 'application');
if($data === null) {
return null;
}
$tmp = $data->data->content;
if (is_null($tmp)) {
\OCP\Util::writeLog('core', 'No update found at the ownCloud appstore for app ' . $id, \OCP\Util::DEBUG);
return null;
}
$app = [];
$app['id'] = (int)$id;
$app['name'] = (string)$tmp->name;
$app['version'] = (string)$tmp->version;
$app['type'] = (string)$tmp->typeid;
$app['label'] = (string)$tmp->label;
$app['typename'] = (string)$tmp->typename;
$app['personid'] = (string)$tmp->personid;
$app['profilepage'] = (string)$tmp->profilepage;
$app['detailpage'] = (string)$tmp->detailpage;
$app['preview1'] = (string)$tmp->smallpreviewpic1;
$app['preview2'] = (string)$tmp->smallpreviewpic2;
$app['preview3'] = (string)$tmp->smallpreviewpic3;
$app['changed'] = strtotime($tmp->changed);
$app['description'] = (string)$tmp->description;
$app['detailpage'] = (string)$tmp->detailpage;
$app['score'] = (int)$tmp->score;
$app['level'] = (int)$tmp->approved;
return $app;
}
/**
* Get the download url for an application from the OCS server
* @param string $id
* @param array $targetVersion The target ownCloud version
* @return array|null an array of application data or null
*/
public function getApplicationDownload($id, array $targetVersion) {
if (!$this->isAppStoreEnabled()) {
return null;
}
$url = $this->getAppStoreUrl() . '/content/download/' . urlencode($id) . '/1';
$client = $this->httpClientService->newClient();
try {
$response = $client->get(
$url,
[
'timeout' => 20,
'query' => [
'version' => implode('x', $targetVersion),
],
]
);
} catch(\Exception $e) {
$this->logger->error(
sprintf('Could not get application download URL: %s', $e->getMessage()),
[
'app' => 'core',
]
);
return null;
}
$data = $this->loadData($response->getBody(), 'application download URL');
if($data === null) {
return null;
}
$tmp = $data->data->content;
$app = [];
if (isset($tmp->downloadlink)) {
$app['downloadlink'] = (string)$tmp->downloadlink;
} else {
$app['downloadlink'] = '';
}
return $app;
}
}

View file

@ -1,6 +1,7 @@
<?php
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
* @copyright Copyright (c) 2016, Lukas Reschke <lukas@statuscode.ch>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Bart Visscher <bartv@thisnet.nl>
@ -41,6 +42,8 @@
namespace OC;
use bantu\IniGetWrapper\IniGetWrapper;
use OC\App\AppStore\Fetcher\AppFetcher;
use OC\App\AppStore\Fetcher\CategoryFetcher;
use OC\AppFramework\Http\Request;
use OC\AppFramework\Db\Db;
use OC\AppFramework\Utility\TimeFactory;
@ -320,6 +323,21 @@ class Server extends ServerContainer implements IServerContainer {
$this->registerService('AppHelper', function ($c) {
return new \OC\AppHelper();
});
$this->registerService('AppFetcher', function ($c) {
return new AppFetcher(
$this->getAppDataDir('appstore'),
$this->getHTTPClientService(),
$this->query(TimeFactory::class),
$this->getConfig()
);
});
$this->registerService('CategoryFetcher', function ($c) {
return new CategoryFetcher(
$this->getAppDataDir('appstore'),
$this->getHTTPClientService(),
$this->query(TimeFactory::class)
);
});
$this->registerService('UserCache', function ($c) {
return new Cache\File();
});
@ -580,13 +598,6 @@ class Server extends ServerContainer implements IServerContainer {
$c->getThemingDefaults()
);
});
$this->registerService('OcsClient', function (Server $c) {
return new OCSClient(
$this->getHTTPClientService(),
$this->getConfig(),
$this->getLogger()
);
});
$this->registerService('LDAPProvider', function(Server $c) {
$config = $c->getConfig();
$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
@ -1007,6 +1018,13 @@ class Server extends ServerContainer implements IServerContainer {
return $this->query('AppHelper');
}
/**
* @return AppFetcher
*/
public function getAppFetcher() {
return $this->query('AppFetcher');
}
/**
* Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
* getMemCacheFactory() instead.

View file

@ -1,6 +1,7 @@
<?php
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
* @copyright Copyright (c) 2016, Lukas Reschke <lukas@statuscode.ch>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Frank Karlitschek <frank@karlitschek.de>
@ -426,11 +427,15 @@ class Updater extends BasicEmitter {
private function upgradeAppStoreApps(array $disabledApps) {
foreach($disabledApps as $app) {
try {
if (Installer::isUpdateAvailable($app)) {
$ocsId = \OC::$server->getConfig()->getAppValue($app, 'ocsid', '');
$this->emit('\OC\Updater', 'upgradeAppStoreApp', array($app));
Installer::updateAppByOCSId($ocsId);
$installer = new Installer(
\OC::$server->getAppFetcher(),
\OC::$server->getHTTPClientService(),
\OC::$server->getTempManager(),
$this->log
);
if (Installer::isUpdateAvailable($app, \OC::$server->getAppFetcher())) {
$this->emit('\OC\Updater', 'upgradeAppStoreApp', [$app]);
$installer->updateAppstoreApp($app);
}
} catch (\Exception $ex) {
$this->log->logException($ex, ['app' => 'core']);

View file

@ -1,6 +1,7 @@
<?php
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
* @copyright Copyright (c) 2016, Lukas Reschke <lukas@statuscode.ch>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Bart Visscher <bartv@thisnet.nl>
@ -326,24 +327,44 @@ class OC_App {
/**
* enables an app
*
* @param mixed $app app
* @param string $appId
* @param array $groups (optional) when set, only these groups will have access to the app
* @throws \Exception
* @return void
*
* This function set an app as enabled in appconfig.
*/
public static function enable($app, $groups = null) {
public function enable($appId,
$groups = null) {
self::$enabledAppsCache = []; // flush
if (!Installer::isInstalled($app)) {
$app = self::installApp($app);
$l = \OC::$server->getL10N('core');
$config = \OC::$server->getConfig();
// Check if app is already downloaded
$installer = new Installer(
\OC::$server->getAppFetcher(),
\OC::$server->getHTTPClientService(),
\OC::$server->getTempManager(),
\OC::$server->getLogger()
);
$isDownloaded = $installer->isDownloaded($appId);
if(!$isDownloaded) {
$installer->downloadApp($appId);
}
if (!Installer::isInstalled($appId)) {
$appId = self::installApp(
$appId,
$config,
$l
);
$installer->installApp($appId);
} else {
// check for required dependencies
$config = \OC::$server->getConfig();
$l = \OC::$server->getL10N('core');
$info = self::getAppInfo($app);
$info = self::getAppInfo($appId);
self::checkAppDependencies($config, $l, $info);
$installer->installApp($appId);
}
$appManager = \OC::$server->getAppManager();
@ -356,40 +377,19 @@ class OC_App {
$groupsList[] = $groupManager->get($group);
}
}
$appManager->enableAppForGroups($app, $groupsList);
$appManager->enableAppForGroups($appId, $groupsList);
} else {
$appManager->enableApp($app);
$appManager->enableApp($appId);
}
$info = self::getAppInfo($app);
$info = self::getAppInfo($appId);
if(isset($info['settings']) && is_array($info['settings'])) {
$appPath = self::getAppPath($app);
self::registerAutoloading($app, $appPath);
$appPath = self::getAppPath($appId);
self::registerAutoloading($appId, $appPath);
\OC::$server->getSettingsManager()->setupSettings($info['settings']);
}
}
/**
* @param string $app
* @return int
*/
private static function downloadApp($app) {
$ocsClient = new OCSClient(
\OC::$server->getHTTPClientService(),
\OC::$server->getConfig(),
\OC::$server->getLogger()
);
$appData = $ocsClient->getApplication($app, \OCP\Util::getVersion());
$download = $ocsClient->getApplicationDownload($app, \OCP\Util::getVersion());
if(isset($download['downloadlink']) and $download['downloadlink']!='') {
// Replace spaces in download link without encoding entire URL
$download['downloadlink'] = str_replace(' ', '%20', $download['downloadlink']);
$info = array('source' => 'http', 'href' => $download['downloadlink'], 'appdata' => $appData);
$app = Installer::installApp($info);
}
return $app;
}
/**
* @param string $app
* @return bool
@ -399,7 +399,13 @@ class OC_App {
return false;
}
return Installer::removeApp($app);
$installer = new Installer(
\OC::$server->getAppFetcher(),
\OC::$server->getHTTPClientService(),
\OC::$server->getTempManager(),
\OC::$server->getLogger()
);
return $installer->removeApp($app);
}
/**
@ -409,11 +415,6 @@ class OC_App {
* @throws Exception
*/
public static function disable($app) {
// Convert OCS ID to regular application identifier
if(self::getInternalAppIdByOcs($app) !== false) {
$app = self::getInternalAppIdByOcs($app);
}
// flush
self::$enabledAppsCache = array();
@ -554,7 +555,7 @@ class OC_App {
* @param string $appId
* @return false|string
*/
protected static function findAppInDirectories($appId) {
public static function findAppInDirectories($appId) {
$sanitizedAppId = self::cleanAppId($appId);
if($sanitizedAppId !== $appId) {
return false;
@ -613,18 +614,6 @@ class OC_App {
return false;
}
/**
* check if an app's directory is writable
*
* @param string $appId
* @return bool
*/
public static function isAppDirWritable($appId) {
$path = self::getAppPath($appId);
return ($path !== false) ? is_writable($path) : false;
}
/**
* Get the path for the given app on the access
* If the app is defined in multiple directories, the first one is taken. (false if not found)
@ -837,20 +826,11 @@ class OC_App {
/**
* List all apps, this is used in apps.php
*
* @param bool $onlyLocal
* @param bool $includeUpdateInfo Should we check whether there is an update
* in the app store?
* @param OCSClient $ocsClient
* @return array
*/
public static function listAllApps($onlyLocal = false,
$includeUpdateInfo = true,
OCSClient $ocsClient) {
public function listAllApps() {
$installedApps = OC_App::getAllApps();
//TODO which apps do we want to blacklist and how do we integrate
// blacklisting with the multi apps folder feature?
//we don't want to show configuration for these
$blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps();
$appList = array();
@ -893,8 +873,6 @@ class OC_App {
$info['removable'] = true;
}
$info['update'] = ($includeUpdateInfo) ? Installer::isUpdateAvailable($app) : null;
$appPath = self::getAppPath($app);
if($appPath !== false) {
$appIcon = $appPath . '/img/' . $app . '.svg';
@ -926,29 +904,8 @@ class OC_App {
$appList[] = $info;
}
}
if ($onlyLocal) {
$remoteApps = [];
} else {
$remoteApps = OC_App::getAppstoreApps('approved', null, $ocsClient);
}
if ($remoteApps) {
// Remove duplicates
foreach ($appList as $app) {
foreach ($remoteApps AS $key => $remote) {
if ($app['name'] === $remote['name'] ||
(isset($app['ocsid']) &&
$app['ocsid'] === $remote['id'])
) {
unset($remoteApps[$key]);
}
}
}
$combinedApps = array_merge($appList, $remoteApps);
} else {
$combinedApps = $appList;
}
return $combinedApps;
return $appList;
}
/**
@ -966,70 +923,6 @@ class OC_App {
return false;
}
/**
* Get a list of all apps on the appstore
* @param string $filter
* @param string|null $category
* @param OCSClient $ocsClient
* @return array|bool multi-dimensional array of apps.
* Keys: id, name, type, typename, personid, license, detailpage, preview, changed, description
*/
public static function getAppstoreApps($filter = 'approved',
$category = null,
OCSClient $ocsClient) {
$categories = [$category];
if (is_null($category)) {
$categoryNames = $ocsClient->getCategories(\OCP\Util::getVersion());
if (is_array($categoryNames)) {
// Check that categories of apps were retrieved correctly
if (!$categories = array_keys($categoryNames)) {
return false;
}
} else {
return false;
}
}
$page = 0;
$remoteApps = $ocsClient->getApplications($categories, $page, $filter, \OCP\Util::getVersion());
$apps = [];
$i = 0;
$l = \OC::$server->getL10N('core');
foreach ($remoteApps as $app) {
$potentialCleanId = self::getInternalAppIdByOcs($app['id']);
// enhance app info (for example the description)
$apps[$i] = OC_App::parseAppInfo($app);
$apps[$i]['author'] = $app['personid'];
$apps[$i]['ocs_id'] = $app['id'];
$apps[$i]['internal'] = 0;
$apps[$i]['active'] = ($potentialCleanId !== false) ? self::isEnabled($potentialCleanId) : false;
$apps[$i]['update'] = false;
$apps[$i]['groups'] = false;
$apps[$i]['score'] = $app['score'];
$apps[$i]['removable'] = false;
if ($app['label'] == 'recommended') {
$apps[$i]['internallabel'] = (string)$l->t('Recommended');
$apps[$i]['internalclass'] = 'recommendedapp';
}
// Apps from the appstore are always assumed to be compatible with the
// the current release as the initial filtering is done on the appstore
$apps[$i]['dependencies']['owncloud']['@attributes']['min-version'] = implode('.', \OCP\Util::getVersion());
$apps[$i]['dependencies']['owncloud']['@attributes']['max-version'] = implode('.', \OCP\Util::getVersion());
$i++;
}
if (empty($apps)) {
return false;
} else {
return $apps;
}
}
public static function shouldUpgrade($app) {
$versions = self::getAppVersions();
$currentVersion = OC_App::getAppVersion($app);
@ -1083,7 +976,9 @@ class OC_App {
public static function isAppCompatible($ocVersion, $appInfo) {
$requireMin = '';
$requireMax = '';
if (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) {
if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) {
$requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version'];
} elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) {
$requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version'];
} else if (isset($appInfo['requiremin'])) {
$requireMin = $appInfo['requiremin'];
@ -1091,7 +986,9 @@ class OC_App {
$requireMin = $appInfo['require'];
}
if (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) {
if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) {
$requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version'];
} elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) {
$requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version'];
} else if (isset($appInfo['requiremax'])) {
$requireMax = $appInfo['requiremax'];
@ -1132,46 +1029,16 @@ class OC_App {
/**
* @param string $app
* @param \OCP\IConfig $config
* @param \OCP\IL10N $l
* @return bool
*
* @throws Exception if app is not compatible with this version of ownCloud
* @throws Exception if no app-name was specified
*/
public static function installApp($app) {
$appName = $app; // $app will be overwritten, preserve name for error logging
$l = \OC::$server->getL10N('core');
$config = \OC::$server->getConfig();
$ocsClient = new OCSClient(
\OC::$server->getHTTPClientService(),
$config,
\OC::$server->getLogger()
);
$appData = $ocsClient->getApplication($app, \OCP\Util::getVersion());
// check if app is a shipped app or not. OCS apps have an integer as id, shipped apps use a string
if (!is_numeric($app)) {
$shippedVersion = self::getAppVersion($app);
if ($appData && version_compare($shippedVersion, $appData['version'], '<')) {
$app = self::downloadApp($app);
} else {
$app = Installer::installShippedApp($app);
}
} else {
// Maybe the app is already installed - compare the version in this
// case and use the local already installed one.
// FIXME: This is a horrible hack. I feel sad. The god of code cleanness may forgive me.
$internalAppId = self::getInternalAppIdByOcs($app);
if($internalAppId !== false) {
if($appData && version_compare(\OC_App::getAppVersion($internalAppId), $appData['version'], '<')) {
$app = self::downloadApp($app);
} else {
self::enable($internalAppId);
$app = $internalAppId;
}
} else {
$app = self::downloadApp($app);
}
}
public function installApp($app,
\OCP\IConfig $config,
\OCP\IL10N $l) {
if ($app !== false) {
// check if the app is compatible with this version of ownCloud
$info = self::getAppInfo($app);

View file

@ -757,6 +757,7 @@ class OC_Util {
'simplexml_load_string' => 'SimpleXML',
'hash' => 'HASH Message Digest Framework',
'curl_init' => 'cURL',
'openssl_verify' => 'OpenSSL',
],
'defined' => array(
'PDO::ATTR_DRIVER_NAME' => 'PDO'

View file

@ -0,0 +1,14 @@
-----BEGIN X509 CRL-----
MIICDTCB9gIBATANBgkqhkiG9w0BAQsFADB7MQswCQYDVQQGEwJERTEbMBkGA1UE
CAwSQmFkZW4tV3VlcnR0ZW1iZXJnMRcwFQYDVQQKDA5OZXh0Y2xvdWQgR21iSDE2
MDQGA1UEAwwtTmV4dGNsb3VkIENvZGUgU2lnbmluZyBJbnRlcm1lZGlhdGUgQXV0
aG9yaXR5Fw0xNjEwMTcxMjA5MjhaFw0yNjA4MjYxMjA5MjhaMBUwEwICEBAXDTE2
MTAxNzEyMDkxOVqgMDAuMB8GA1UdIwQYMBaAFG3qbqqpNyw8iS0XPv1G7sOeeO10
MAsGA1UdFAQEAgIQAzANBgkqhkiG9w0BAQsFAAOCAQEAZGJNwERFseCv6cS6bfmq
hIIqHieG+/mp4kjqtk4mg8CEYZq/M0q2DMjh7xZUuflV3wadqTCDunDXoyUIV36K
TwLsrREKGFqpSDsVgnX6IYeG0Sf7rnV5PYD2ODWfXrjp3yU7/Jgc2qjco11X5psV
uUnqGDU7DoMwFB6GTTRXfjpCKn8SUtuETAEN013Ii6xXsfCJQTjzQaZByz/Xbypr
sPfotQRfpAhhfjowK5B2ESjXePdNuFlPEAJ114HDJrI89dndIzus95N+3q2sm80T
TFwdooAghAvVmABADC3GQ9bvQb9CUC14DQZJWesy/ps64fgKdXcnBhsX9uPJ7Fdb
hQ==
-----END X509 CRL-----

View file

@ -30,7 +30,11 @@
namespace OC\Settings;
use OC\App\AppStore\Fetcher\AppFetcher;
use OC\App\AppStore\Fetcher\CategoryFetcher;
use OC\AppFramework\Utility\TimeFactory;
use OC\Authentication\Token\IProvider;
use OC\Server;
use OC\Settings\Middleware\SubadminMiddleware;
use OCP\AppFramework\App;
use OCP\IContainer;
@ -86,5 +90,24 @@ class Application extends App {
$container->registerService(IManager::class, function (IContainer $c) {
return $c->query('ServerContainer')->getSettingsManager();
});
$container->registerService(AppFetcher::class, function (IContainer $c) {
/** @var Server $server */
$server = $c->query('ServerContainer');
return new AppFetcher(
$server->getAppDataDir('appstore'),
$server->getHTTPClientService(),
$server->query(TimeFactory::class),
$server->getConfig()
);
});
$container->registerService(CategoryFetcher::class, function (IContainer $c) {
/** @var Server $server */
$server = $c->query('ServerContainer');
return new CategoryFetcher(
$server->getAppDataDir('appstore'),
$server->getHTTPClientService(),
$server->query(TimeFactory::class)
);
});
}
}

View file

@ -1,6 +1,7 @@
<?php
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
* @copyright Copyright (c) 2016, Lukas Reschke <lukas@statuscode.ch>
*
* @author Christoph Wurst <christoph@owncloud.com>
* @author Joas Schilling <coding@schilljs.com>
@ -26,19 +27,21 @@
namespace OC\Settings\Controller;
use OC\App\AppStore\Fetcher\AppFetcher;
use OC\App\AppStore\Fetcher\CategoryFetcher;
use OC\App\AppStore\Version\VersionParser;
use OC\App\DependencyAnalyzer;
use OC\App\Platform;
use OC\OCSClient;
use OCP\App\IAppManager;
use \OCP\AppFramework\Controller;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\ICacheFactory;
use OCP\INavigationManager;
use OCP\IRequest;
use OCP\IL10N;
use OCP\IConfig;
use OCP\L10N\IFactory;
/**
* @package OC\Settings\Controller
@ -51,95 +54,66 @@ class AppSettingsController extends Controller {
private $l10n;
/** @var IConfig */
private $config;
/** @var \OCP\ICache */
private $cache;
/** @var INavigationManager */
private $navigationManager;
/** @var IAppManager */
private $appManager;
/** @var OCSClient */
private $ocsClient;
/** @var CategoryFetcher */
private $categoryFetcher;
/** @var AppFetcher */
private $appFetcher;
/** @var IFactory */
private $l10nFactory;
/**
* @param string $appName
* @param IRequest $request
* @param IL10N $l10n
* @param IConfig $config
* @param ICacheFactory $cache
* @param INavigationManager $navigationManager
* @param IAppManager $appManager
* @param OCSClient $ocsClient
* @param CategoryFetcher $categoryFetcher
* @param AppFetcher $appFetcher
* @param IFactory $l10nFactory
*/
public function __construct($appName,
IRequest $request,
IL10N $l10n,
IConfig $config,
ICacheFactory $cache,
INavigationManager $navigationManager,
IAppManager $appManager,
OCSClient $ocsClient) {
CategoryFetcher $categoryFetcher,
AppFetcher $appFetcher,
IFactory $l10nFactory) {
parent::__construct($appName, $request);
$this->l10n = $l10n;
$this->config = $config;
$this->cache = $cache->create($appName);
$this->navigationManager = $navigationManager;
$this->appManager = $appManager;
$this->ocsClient = $ocsClient;
}
/**
* Enables or disables the display of experimental apps
* @param bool $state
* @return DataResponse
*/
public function changeExperimentalConfigState($state) {
$this->config->setSystemValue('appstore.experimental.enabled', $state);
$this->appManager->clearAppsCache();
return new DataResponse();
}
/**
* @param string|int $category
* @return int
*/
protected function getCategory($category) {
if (is_string($category)) {
foreach ($this->listCategories() as $cat) {
if (isset($cat['ident']) && $cat['ident'] === $category) {
$category = (int) $cat['id'];
break;
}
}
// Didn't find the category, falling back to enabled
if (is_string($category)) {
$category = self::CAT_ENABLED;
}
}
return (int) $category;
$this->categoryFetcher = $categoryFetcher;
$this->appFetcher = $appFetcher;
$this->l10nFactory = $l10nFactory;
}
/**
* @NoCSRFRequired
*
* @param string $category
* @return TemplateResponse
*/
public function viewApps($category = '') {
$categoryId = $this->getCategory($category);
if ($categoryId === self::CAT_ENABLED) {
// Do not use an arbitrary input string, because we put the category in html
if ($category === '') {
$category = 'enabled';
}
$params = [];
$params['experimentalEnabled'] = $this->config->getSystemValue('appstore.experimental.enabled', false);
$params['category'] = $category;
$params['appstoreEnabled'] = $this->config->getSystemValue('appstoreenabled', true) === true;
$this->navigationManager->setActiveEntry('core_apps');
$templateResponse = new TemplateResponse($this->appName, 'apps', $params, 'user');
$policy = new ContentSecurityPolicy();
$policy->addAllowedImageDomain('https://apps.owncloud.com');
$policy->addAllowedImageDomain('https://usercontent.apps.nextcloud.com');
$templateResponse->setContentSecurityPolicy($policy);
return $templateResponse;
@ -147,139 +121,192 @@ class AppSettingsController extends Controller {
/**
* Get all available categories
* @return array
*
* @return JSONResponse
*/
public function listCategories() {
$currentLanguage = substr($this->l10nFactory->findLanguage(), 0, 2);
if(!is_null($this->cache->get('listCategories'))) {
return $this->cache->get('listCategories');
}
$categories = [
$formattedCategories = [
['id' => self::CAT_ENABLED, 'ident' => 'enabled', 'displayName' => (string)$this->l10n->t('Enabled')],
['id' => self::CAT_DISABLED, 'ident' => 'disabled', 'displayName' => (string)$this->l10n->t('Not enabled')],
];
$categories = $this->categoryFetcher->get();
foreach($categories as $category) {
$formattedCategories[] = [
'id' => $category['id'],
'ident' => $category['id'],
'displayName' => isset($category['translations'][$currentLanguage]['name']) ? $category['translations'][$currentLanguage]['name'] : $category['translations']['en']['name'],
];
}
if($this->ocsClient->isAppStoreEnabled()) {
// apps from external repo via OCS
$ocs = $this->ocsClient->getCategories(\OCP\Util::getVersion());
if ($ocs) {
foreach($ocs as $k => $v) {
$name = str_replace('ownCloud ', '', $v);
$ident = str_replace(' ', '-', urlencode(strtolower($name)));
$categories[] = [
'id' => $k,
'ident' => $ident,
'displayName' => $name,
];
return new JSONResponse($formattedCategories);
}
/**
* Get all apps for a category
*
* @param string $requestedCategory
* @return array
*/
private function getAppsForCategory($requestedCategory) {
$versionParser = new VersionParser();
$formattedApps = [];
$apps = $this->appFetcher->get();
foreach($apps as $app) {
// Skip all apps not in the requested category
$isInCategory = false;
foreach($app['categories'] as $category) {
if($category === $requestedCategory) {
$isInCategory = true;
}
}
if(!$isInCategory) {
continue;
}
$nextCloudVersion = $versionParser->getVersion($app['releases'][0]['rawPlatformVersionSpec']);
$nextCloudVersionDependencies = [];
if($nextCloudVersion->getMinimumVersion() !== '') {
$nextCloudVersionDependencies['owncloud']['@attributes']['min-version'] = $nextCloudVersion->getMinimumVersion();
}
if($nextCloudVersion->getMaximumVersion() !== '') {
$nextCloudVersionDependencies['owncloud']['@attributes']['max-version'] = $nextCloudVersion->getMaximumVersion();
}
$phpVersion = $versionParser->getVersion($app['releases'][0]['rawPhpVersionSpec']);
$existsLocally = (\OC_App::getAppPath($app['id']) !== false) ? true : false;
$phpDependencies = [];
if($phpVersion->getMinimumVersion() !== '') {
$phpDependencies['php']['@attributes']['min-version'] = $phpVersion->getMinimumVersion();
}
if($phpVersion->getMaximumVersion() !== '') {
$phpDependencies['php']['@attributes']['max-version'] = $phpVersion->getMaximumVersion();
}
if(isset($app['releases'][0]['minIntSize'])) {
$phpDependencies['php']['@attributes']['min-int-size'] = $app['releases'][0]['minIntSize'];
}
$authors = '';
foreach($app['authors'] as $key => $author) {
$authors .= $author['name'];
if($key !== count($app['authors']) - 1) {
$authors .= ', ';
}
}
$currentLanguage = substr(\OC::$server->getL10NFactory()->findLanguage(), 0, 2);
$enabledValue = $this->config->getAppValue($app['id'], 'enabled', 'no');
$groups = null;
if($enabledValue !== 'no' && $enabledValue !== 'yes') {
$groups = $enabledValue;
}
$currentVersion = '';
if($this->appManager->isInstalled($app['id'])) {
$currentVersion = \OC_App::getAppVersion($app['id']);
} else {
$currentLanguage = $app['releases'][0]['version'];
}
$formattedApps[] = [
'id' => $app['id'],
'name' => isset($app['translations'][$currentLanguage]['name']) ? $app['translations'][$currentLanguage]['name'] : $app['translations']['en']['name'],
'description' => isset($app['translations'][$currentLanguage]['description']) ? $app['translations'][$currentLanguage]['description'] : $app['translations']['en']['description'],
'license' => $app['releases'][0]['licenses'],
'author' => $authors,
'shipped' => false,
'version' => $currentVersion,
'default_enable' => '',
'types' => [],
'documentation' => [
'admin' => $app['adminDocs'],
'user' => $app['userDocs'],
'developer' => $app['developerDocs']
],
'website' => $app['website'],
'bugs' => $app['issueTracker'],
'detailpage' => $app['website'],
'dependencies' => array_merge(
$nextCloudVersionDependencies,
$phpDependencies
),
'level' => ($app['featured'] === true) ? 200 : 100,
'missingMaxOwnCloudVersion' => false,
'missingMinOwnCloudVersion' => false,
'canInstall' => true,
'preview' => isset($app['screenshots'][0]['url']) ? 'https://usercontent.apps.nextcloud.com/'.base64_encode($app['screenshots'][0]['url']) : '',
'score' => $app['ratingOverall'],
'removable' => $existsLocally,
'active' => $this->appManager->isEnabledForUser($app['id']),
'needsDownload' => !$existsLocally,
'groups' => $groups,
'fromAppStore' => true,
];
$appFetcher = \OC::$server->getAppFetcher();
$newVersion = \OC\Installer::isUpdateAvailable($app['id'], $appFetcher);
if($newVersion && $this->appManager->isInstalled($app['id'])) {
$formattedApps[count($formattedApps)-1]['update'] = $newVersion;
}
}
$this->cache->set('listCategories', $categories, 3600);
return $categories;
return $formattedApps;
}
/**
* Get all available apps in a category
*
* @param string $category
* @param bool $includeUpdateInfo Should we check whether there is an update
* in the app store?
* @return array
* @return JSONResponse
*/
public function listApps($category = '', $includeUpdateInfo = true) {
$category = $this->getCategory($category);
$cacheName = 'listApps-' . $category . '-' . (int) $includeUpdateInfo;
public function listApps($category = '') {
$appClass = new \OC_App();
if(!is_null($this->cache->get($cacheName))) {
$apps = $this->cache->get($cacheName);
} else {
switch ($category) {
// installed apps
case 0:
$apps = $this->getInstalledApps($includeUpdateInfo);
usort($apps, function ($a, $b) {
$a = (string)$a['name'];
$b = (string)$b['name'];
if ($a === $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
});
$version = \OCP\Util::getVersion();
foreach($apps as $key => $app) {
if(!array_key_exists('level', $app) && array_key_exists('ocsid', $app)) {
$remoteAppEntry = $this->ocsClient->getApplication($app['ocsid'], $version);
if(is_array($remoteAppEntry) && array_key_exists('level', $remoteAppEntry)) {
$apps[$key]['level'] = $remoteAppEntry['level'];
}
}
switch ($category) {
// installed apps
case 'enabled':
$apps = $appClass->listAllApps();
$apps = array_filter($apps, function ($app) {
return $app['active'];
});
usort($apps, function ($a, $b) {
$a = (string)$a['name'];
$b = (string)$b['name'];
if ($a === $b) {
return 0;
}
break;
// not-installed apps
case 1:
$apps = \OC_App::listAllApps(true, $includeUpdateInfo, $this->ocsClient);
$apps = array_filter($apps, function ($app) {
return !$app['active'];
});
$version = \OCP\Util::getVersion();
foreach($apps as $key => $app) {
if(!array_key_exists('level', $app) && array_key_exists('ocsid', $app)) {
$remoteAppEntry = $this->ocsClient->getApplication($app['ocsid'], $version);
if(is_array($remoteAppEntry) && array_key_exists('level', $remoteAppEntry)) {
$apps[$key]['level'] = $remoteAppEntry['level'];
}
}
return ($a < $b) ? -1 : 1;
});
break;
// disabled apps
case 'disabled':
$apps = $appClass->listAllApps();
$apps = array_filter($apps, function ($app) {
return !$app['active'];
});
usort($apps, function ($a, $b) {
$a = (string)$a['name'];
$b = (string)$b['name'];
if ($a === $b) {
return 0;
}
usort($apps, function ($a, $b) {
$a = (string)$a['name'];
$b = (string)$b['name'];
if ($a === $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
});
break;
default:
$filter = $this->config->getSystemValue('appstore.experimental.enabled', false) ? 'all' : 'approved';
return ($a < $b) ? -1 : 1;
});
break;
default:
$apps = $this->getAppsForCategory($category);
$apps = \OC_App::getAppstoreApps($filter, $category, $this->ocsClient);
if (!$apps) {
$apps = array();
} else {
// don't list installed apps
$installedApps = $this->getInstalledApps(false);
$installedApps = array_map(function ($app) {
if (isset($app['ocsid'])) {
return $app['ocsid'];
}
return $app['id'];
}, $installedApps);
$apps = array_filter($apps, function ($app) use ($installedApps) {
return !in_array($app['id'], $installedApps);
});
// show tooltip if app is downloaded from remote server
$inactiveApps = $this->getInactiveApps();
foreach ($apps as &$app) {
$app['needsDownload'] = !in_array($app['id'], $inactiveApps);
}
// sort by score
usort($apps, function ($a, $b) {
$a = (int)$a['score'];
$b = (int)$b['score'];
if ($a === $b) {
return 0;
}
// sort by score
usort($apps, function ($a, $b) {
$a = (int)$a['score'];
$b = (int)$b['score'];
if ($a === $b) {
return 0;
}
return ($a > $b) ? -1 : 1;
});
break;
}
return ($a > $b) ? -1 : 1;
});
break;
}
// fix groups to be an array
@ -310,40 +337,6 @@ class AppSettingsController extends Controller {
return $app;
}, $apps);
$this->cache->set($cacheName, $apps, 300);
return ['apps' => $apps, 'status' => 'success'];
return new JSONResponse(['apps' => $apps, 'status' => 'success']);
}
/**
* @param bool $includeUpdateInfo Should we check whether there is an update
* in the app store?
* @return array
*/
private function getInstalledApps($includeUpdateInfo = true) {
$apps = \OC_App::listAllApps(true, $includeUpdateInfo, $this->ocsClient);
$apps = array_filter($apps, function ($app) {
return $app['active'];
});
return $apps;
}
/**
* @return array
*/
private function getInactiveApps() {
$inactiveApps = \OC_App::listAllApps(true, false, $this->ocsClient);
$inactiveApps = array_filter($inactiveApps,
function ($app) {
return !$app['active'];
});
$inactiveApps = array_map(function($app) {
if (isset($app['ocsid'])) {
return $app['ocsid'];
}
return $app['id'];
}, $inactiveApps);
return $inactiveApps;
}
}

View file

@ -31,8 +31,10 @@ OCP\JSON::callCheck();
$groups = isset($_POST['groups']) ? (array)$_POST['groups'] : null;
try {
$app = OC_App::cleanAppId((string)$_POST['appid']);
OC_App::enable($app, $groups);
$app = new OC_App();
$appId = (string)$_POST['appid'];
$appId = OC_App::cleanAppId($appId);
$app->enable($appId, $groups);
OC_JSON::success(['data' => ['update_required' => \OC_App::shouldUpgrade($app)]]);
} catch (Exception $e) {
\OCP\Util::writeLog('core', $e->getMessage(), \OCP\Util::ERROR);

View file

@ -29,14 +29,15 @@ if (!array_key_exists('appid', $_POST)) {
exit;
}
$app = new OC_App();
$appId = (string)$_POST['appid'];
$appId = OC_App::cleanAppId($appId);
$result = OC_App::installApp($appId);
$result = $app->installApp(
$appId,
\OC::$server->getConfig(),
\OC::$server->getL10N('core')
);
if($result !== false) {
// FIXME: Clear the cache - move that into some sane helper method
\OC::$server->getMemCacheFactory()->create('settings')->remove('listApps-0');
\OC::$server->getMemCacheFactory()->create('settings')->remove('listApps-1');
OC_JSON::success(array('data' => array('appid' => $appId)));
} else {
$l = \OC::$server->getL10N('settings');

View file

@ -35,23 +35,18 @@ if (!array_key_exists('appid', $_POST)) {
}
$appId = (string)$_POST['appid'];
if (!is_numeric($appId)) {
$appId = \OC::$server->getAppConfig()->getValue($appId, 'ocsid', null);
if ($appId === null) {
OCP\JSON::error(array(
'message' => 'No OCS-ID found for app!'
));
exit;
}
}
$appId = OC_App::cleanAppId($appId);
$config = \OC::$server->getConfig();
$config->setSystemValue('maintenance', true);
try {
$result = \OC\Installer::updateAppByOCSId($appId);
$installer = new \OC\Installer(
\OC::$server->getAppFetcher(),
\OC::$server->getHTTPClientService(),
\OC::$server->getTempManager(),
\OC::$server->getLogger()
);
$result = $installer->updateAppstoreApp($appId);
$config->setSystemValue('maintenance', false);
} catch(Exception $ex) {
$config->setSystemValue('maintenance', false);

View file

@ -415,17 +415,6 @@ span.version {
background-position: 5px center;
padding-left: 25px;
}
.app-level .approved {
border-color: #0082c9;
}
.app-level .experimental {
background-color: #ce3702;
border-color: #ce3702;
color: #fff;
}
.apps-experimental {
color: #ce3702;
}
.app-score {
position: relative;

View file

@ -2,7 +2,7 @@
Handlebars.registerHelper('score', function() {
if(this.score) {
var score = Math.round( this.score / 10 );
var score = Math.round( this.score * 10 );
var imageName = 'rating/s' + score + '.svg';
return new Handlebars.SafeString('<img src="' + OC.imagePath('core', imageName) + '">');
@ -13,10 +13,6 @@ Handlebars.registerHelper('level', function() {
if(typeof this.level !== 'undefined') {
if(this.level === 200) {
return new Handlebars.SafeString('<span class="official icon-checkmark">' + t('settings', 'Official') + '</span>');
} else if(this.level === 100) {
return new Handlebars.SafeString('<span class="approved">' + t('settings', 'Approved') + '</span>');
} else {
return new Handlebars.SafeString('<span class="experimental">' + t('settings', 'Experimental') + '</span>');
}
}
});
@ -211,7 +207,7 @@ OC.Settings.Apps = OC.Settings.Apps || {
currentImage.onload = function() {
page.find('.app-image')
.append(OC.Settings.Apps.imageUrl(app.preview, app.detailpage))
.append(OC.Settings.Apps.imageUrl(app.preview, app.fromAppStore))
.fadeIn();
};
}
@ -248,7 +244,7 @@ OC.Settings.Apps = OC.Settings.Apps || {
var img = '<svg width="72" height="72" viewBox="0 0 72 72">';
if (appfromstore) {
img += '<image x="0" y="0" width="72" height="72" preserveAspectRatio="xMinYMin meet" xlink:href="' + url + '?v=' + oc_config.version + '" class="app-icon" /></svg>';
img += '<image x="0" y="0" width="72" height="72" preserveAspectRatio="xMinYMin meet" xlink:href="' + url + '" class="app-icon" /></svg>';
} else {
img += '<image x="0" y="0" width="72" height="72" preserveAspectRatio="xMinYMin meet" filter="url(#invertIcon)" xlink:href="' + url + '?v=' + oc_config.version + '" class="app-icon"></image></svg>';
}

View file

@ -49,7 +49,6 @@ $application->registerRoutes($this, [
['name' => 'AppSettings#listCategories', 'url' => '/settings/apps/categories', 'verb' => 'GET'],
['name' => 'AppSettings#viewApps', 'url' => '/settings/apps', 'verb' => 'GET'],
['name' => 'AppSettings#listApps', 'url' => '/settings/apps/list', 'verb' => 'GET'],
['name' => 'AppSettings#changeExperimentalConfigState', 'url' => '/settings/apps/experimental', 'verb' => 'POST'],
['name' => 'SecuritySettings#trustedDomains', 'url' => '/settings/admin/security/trustedDomains', 'verb' => 'POST'],
['name' => 'Users#setDisplayName', 'url' => '/settings/users/{username}/displayName', 'verb' => 'POST'],
['name' => 'Users#setMailAddress', 'url' => '/settings/users/{id}/mailAddress', 'verb' => 'PUT'],

View file

@ -30,15 +30,6 @@ script(
</script>
<script id="app-template" type="text/x-handlebars">
{{#if firstExperimental}}
<div class="section apps-experimental">
<h2><?php p($l->t('Experimental applications ahead')) ?></h2>
<p>
<?php p($l->t('Experimental apps are not checked for security issues, new or known to be unstable and under heavy development. Installing them can cause data loss or security breaches.')) ?>
</p>
</div>
{{/if}}
<div class="section" id="app-{{id}}">
{{#if preview}}
<div class="app-image{{#if previewAsIcon}} app-image-icon{{/if}} hidden">
@ -160,16 +151,6 @@ script(
<div id="app-settings-header">
<button class="settings-button" data-apps-slide-toggle="#app-settings-content"></button>
</div>
<div id="app-settings-content" class="apps-experimental">
<input type="checkbox" id="enable-experimental-apps" <?php if($_['experimentalEnabled']) { print_unescaped('checked="checked"'); }?> class="checkbox">
<label for="enable-experimental-apps"><?php p($l->t('Enable experimental apps')) ?></label>
<p>
<small>
<?php p($l->t('Experimental apps are not checked for security issues, new or known to be unstable and under heavy development. Installing them can cause data loss or security breaches.')) ?>
</small>
</p>
</div>
</div>
</div>
<div id="app-content">

File diff suppressed because one or more lines are too long

BIN
tests/data/testapp.tar.gz Normal file

Binary file not shown.

BIN
tests/data/testapp1.tar.gz Normal file

Binary file not shown.

View file

@ -10,7 +10,7 @@ require_once __DIR__.'/../lib/base.php';
function enableApp($app) {
try {
OC_App::enable($app);
(new \OC_App())->enable($app);
} catch (Exception $e) {
echo $e;
}

View file

@ -0,0 +1,39 @@
<?php
/**
* @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace Test\App\AppStore\Fetcher;
use OC\App\AppStore\Fetcher\AppFetcher;
class AppFetcherTest extends FetcherBase {
public function setUp() {
parent::setUp();
$this->fileName = 'apps.json';
$this->endpoint = 'https://apps.nextcloud.com/api/v1/platform/9.2.0/apps.json';
$this->fetcher = new AppFetcher(
$this->appData,
$this->clientService,
$this->timeFactory,
$this->config
);
}
}

View file

@ -0,0 +1,38 @@
<?php
/**
* @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace Test\App\AppStore\Fetcher;
use OC\App\AppStore\Fetcher\CategoryFetcher;
class CategoryFetcherTest extends FetcherBase {
public function setUp() {
parent::setUp();
$this->fileName = 'categories.json';
$this->endpoint = 'https://apps.nextcloud.com/api/v1/categories.json';
$this->fetcher = new CategoryFetcher(
$this->appData,
$this->clientService,
$this->timeFactory
);
}
}

View file

@ -0,0 +1,246 @@
<?php
/**
* @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace Test\App\AppStore\Fetcher;
use OC\App\AppStore\Fetcher\AppFetcher;
use OC\App\AppStore\Fetcher\Fetcher;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\IAppData;
use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\Files\SimpleFS\ISimpleFolder;
use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;
use OCP\Http\Client\IResponse;
use OCP\IConfig;
use Test\TestCase;
abstract class FetcherBase extends TestCase {
/** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */
protected $appData;
/** @var IClientService|\PHPUnit_Framework_MockObject_MockObject */
protected $clientService;
/** @var ITimeFactory|\PHPUnit_Framework_MockObject_MockObject */
protected $timeFactory;
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
protected $config;
/** @var Fetcher */
protected $fetcher;
/** @var string */
protected $fileName;
/** @var string */
protected $endpoint;
public function setUp() {
parent::setUp();
$this->appData = $this->createMock(IAppData::class);
$this->clientService = $this->createMock(IClientService::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->config = $this->createMock(IConfig::class);
}
public function testGetWithAlreadyExistingFileAndUpToDateTimestamp() {
$folder = $this->createMock(ISimpleFolder::class);
$file = $this->createMock(ISimpleFile::class);
$this->appData
->expects($this->once())
->method('getFolder')
->with('/')
->willReturn($folder);
$folder
->expects($this->once())
->method('getFile')
->with($this->fileName)
->willReturn($file);
$file
->expects($this->once())
->method('getContent')
->willReturn('{"timestamp":1200,"data":[{"id":"MyApp"}]}');
$this->timeFactory
->expects($this->once())
->method('getTime')
->willReturn(1499);
$expected = [
[
'id' => 'MyApp',
],
];
$this->assertSame($expected, $this->fetcher->get());
}
public function testGetWithNotExistingFileAndUpToDateTimestamp() {
$folder = $this->createMock(ISimpleFolder::class);
$file = $this->createMock(ISimpleFile::class);
$this->appData
->expects($this->once())
->method('getFolder')
->with('/')
->willReturn($folder);
$folder
->expects($this->at(0))
->method('getFile')
->with($this->fileName)
->willThrowException(new NotFoundException());
$folder
->expects($this->at(1))
->method('newFile')
->with($this->fileName)
->willReturn($file);
$client = $this->createMock(IClient::class);
$this->clientService
->expects($this->once())
->method('newClient')
->willReturn($client);
$response = $this->createMock(IResponse::class);
$client
->expects($this->once())
->method('get')
->with($this->endpoint)
->willReturn($response);
$response
->expects($this->once())
->method('getBody')
->willReturn('[{"id":"MyNewApp", "foo": "foo"}, {"id":"bar"}]');
$fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1502}';
$file
->expects($this->at(0))
->method('putContent')
->with($fileData);
$file
->expects($this->at(1))
->method('getContent')
->willReturn($fileData);
$this->timeFactory
->expects($this->at(0))
->method('getTime')
->willReturn(1502);
$expected = [
[
'id' => 'MyNewApp',
'foo' => 'foo',
],
[
'id' => 'bar',
],
];
$this->assertSame($expected, $this->fetcher->get());
}
public function testGetWithAlreadyExistingFileAndOutdatedTimestamp() {
$folder = $this->createMock(ISimpleFolder::class);
$file = $this->createMock(ISimpleFile::class);
$this->appData
->expects($this->once())
->method('getFolder')
->with('/')
->willReturn($folder);
$folder
->expects($this->once())
->method('getFile')
->with($this->fileName)
->willReturn($file);
$file
->expects($this->at(0))
->method('getContent')
->willReturn('{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}}}');
$this->timeFactory
->expects($this->at(0))
->method('getTime')
->willReturn(1501);
$client = $this->createMock(IClient::class);
$this->clientService
->expects($this->once())
->method('newClient')
->willReturn($client);
$response = $this->createMock(IResponse::class);
$client
->expects($this->once())
->method('get')
->with($this->endpoint)
->willReturn($response);
$response
->expects($this->once())
->method('getBody')
->willReturn('[{"id":"MyNewApp", "foo": "foo"}, {"id":"bar"}]');
$fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1502}';
$file
->expects($this->at(1))
->method('putContent')
->with($fileData);
$file
->expects($this->at(2))
->method('getContent')
->willReturn($fileData);
$this->timeFactory
->expects($this->at(1))
->method('getTime')
->willReturn(1502);
$expected = [
[
'id' => 'MyNewApp',
'foo' => 'foo',
],
[
'id' => 'bar',
],
];
$this->assertSame($expected, $this->fetcher->get());
}
public function testGetWithExceptionInClient() {
$folder = $this->createMock(ISimpleFolder::class);
$file = $this->createMock(ISimpleFile::class);
$this->appData
->expects($this->once())
->method('getFolder')
->with('/')
->willReturn($folder);
$folder
->expects($this->once())
->method('getFile')
->with($this->fileName)
->willReturn($file);
$file
->expects($this->at(0))
->method('getContent')
->willReturn('{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}}}');
$this->timeFactory
->expects($this->at(0))
->method('getTime')
->willReturn(1501);
$client = $this->createMock(IClient::class);
$this->clientService
->expects($this->once())
->method('newClient')
->willReturn($client);
$client
->expects($this->once())
->method('get')
->with($this->endpoint)
->willThrowException(new \Exception());
$this->assertSame([], $this->fetcher->get());
}
}

View file

@ -0,0 +1,99 @@
<?php
/**
* @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace Test\App\AppStore\Version;
use OC\App\AppStore\Version\Version;
use OC\App\AppStore\Version\VersionParser;
use Test\TestCase;
class VersionParserTest extends TestCase {
/** @var VersionParser */
private $versionParser;
public function setUp() {
parent::setUp();
$this->versionParser = new VersionParser();
}
/**
* @return array
*/
public function versionProvider() {
return [
[
'*',
new Version('', ''),
],
[
'<=8.1.2',
new Version('', '8.1.2'),
],
[
'<=9',
new Version('', '9'),
],
[
'>=9.3.2',
new Version('9.3.2', ''),
],
[
'>=8.1.2 <=9.3.2',
new Version('8.1.2', '9.3.2'),
],
[
'>=8.2 <=9.1',
new Version('8.2', '9.1'),
],
[
'>=9 <=11',
new Version('9', '11'),
],
];
}
/**
* @dataProvider versionProvider
*
* @param string $input
* @param Version $expected
*/
public function testGetVersion($input,
Version $expected) {
$this->assertEquals($expected, $this->versionParser->getVersion($input));
}
/**
* @expectedException \Exception
* @expectedExceptionMessage Version cannot be parsed: BogusVersion
*/
public function testGetVersionException() {
$this->versionParser->getVersion('BogusVersion');
}
/**
* @expectedException \Exception
* @expectedExceptionMessage Version cannot be parsed: >=8.2 <=9.1a
*/
public function testGetVersionExceptionWithMultiple() {
$this->versionParser->getVersion('>=8.2 <=9.1a');
}
}

View file

@ -0,0 +1,37 @@
<?php
/**
* @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace Test\App\AppStore\Version;
use OC\App\AppStore\Version\Version;
use Test\TestCase;
class VersionTest extends TestCase {
public function testGetMinimumVersion() {
$version = new Version('9', '10');
$this->assertSame('9', $version->getMinimumVersion());
}
public function testGetMaximumVersion() {
$version = new Version('9', '10');
$this->assertSame('10', $version->getMaximumVersion());
}
}

View file

@ -1,9 +1,10 @@
<?php
/**
* @author Thomas Müller
* @author Lukas Reschke
* @copyright 2014 Thomas Müller deepdiver@owncloud.com
* later.
* @copyright 2016 Lukas Reschke <lukas@statuscode.ch>
*
* See the COPYING-README file.
*/
@ -187,7 +188,7 @@ class DependencyAnalyzerTest extends TestCase {
'dependencies' => array()
);
if (!is_null($oc)) {
$app['dependencies']['owncloud'] = $oc;
$app['dependencies'] = $oc;
}
$missing = $this->analyser->analyze($app);
@ -200,18 +201,216 @@ class DependencyAnalyzerTest extends TestCase {
* @return array
*/
function providesOC() {
return array(
return [
// no version -> no missing dependency
array(array(), null),
array(array(), array('@attributes' => array('min-version' => '8', 'max-version' => '8'))),
array(array(), array('@attributes' => array('min-version' => '8.0', 'max-version' => '8.0'))),
array(array(), array('@attributes' => array('min-version' => '8.0.2', 'max-version' => '8.0.2'))),
array(array('Server version 8.0.3 or higher is required.'), array('@attributes' => array('min-version' => '8.0.3'))),
array(array('Server version 9 or higher is required.'), array('@attributes' => array('min-version' => '9'))),
array(array('Server version 10 or higher is required.'), array('@attributes' => array('min-version' => '9.1'))),
array(array('Server version 11 or higher is required.'), array('@attributes' => array('min-version' => '9.2'))),
[['Server version 8.0.1 or lower is required.'], ['@attributes' => ['max-version' => '8.0.1']]],
);
[
[],
null,
],
[
[],
[
'nextcloud' => [
'@attributes' => [
'min-version' => '8',
'max-version' => '8',
],
],
],
],
[
[],
[
'nextcloud' => [
'@attributes' => [
'min-version' => '8.0',
'max-version' => '8.0',
],
],
],
],
[
[],
[
'nextcloud' => [
'@attributes' => [
'min-version' => '8.0.2',
'max-version' => '8.0.2'
],
],
],
],
[
[
'Server version 8.0.3 or higher is required.',
],
[
'nextcloud' => [
'@attributes' => [
'min-version' => '8.0.3'
],
],
],
],
[
[
'Server version 9 or higher is required.',
],
[
'nextcloud' => [
'@attributes' => [
'min-version' => '9'
],
],
],
],
[
[
'Server version 10 or higher is required.',
],
[
'nextcloud' => [
'@attributes' => [
'min-version' => '10'
],
],
'owncloud' => [
'@attributes' => [
'min-version' => '9'
],
],
],
],
[
[
'Server version 10 or higher is required.',
],
[
'nextcloud' => [
'@attributes' => [
'min-version' => '9.1',
],
],
],
],
[
[
'Server version 11 or higher is required.',
],
[
'nextcloud' => [
'@attributes' => [
'min-version' => '9.2',
],
],
],
],
[
[
'Server version 8.0.1 or lower is required.',
],
[
'nextcloud' => [
'@attributes' => [
'max-version' => '8.0.1',
],
],
],
],
[
[],
[
'owncloud' => [
'@attributes' => [
'min-version' => '8',
'max-version' => '8',
],
],
],
],
[
[],
[
'owncloud' => [
'@attributes' => [
'min-version' => '8.0',
'max-version' => '8.0',
],
],
],
],
[
[],
[
'owncloud' => [
'@attributes' => [
'min-version' => '8.0.2',
'max-version' => '8.0.2'
],
],
],
],
[
[
'Server version 8.0.3 or higher is required.',
],
[
'owncloud' => [
'@attributes' => [
'min-version' => '8.0.3'
],
],
],
],
[
[
'Server version 9 or higher is required.',
],
[
'owncloud' => [
'@attributes' => [
'min-version' => '9'
],
],
],
],
[
[
'Server version 10 or higher is required.',
],
[
'owncloud' => [
'@attributes' => [
'min-version' => '9.1',
],
],
],
],
[
[
'Server version 11 or higher is required.',
],
[
'owncloud' => [
'@attributes' => [
'min-version' => '9.2',
],
],
],
],
[
[
'Server version 8.0.1 or lower is required.',
],
[
'owncloud' => [
'@attributes' => [
'max-version' => '8.0.1',
],
],
],
],
];
}
/**

View file

@ -264,6 +264,40 @@ class AppTest extends \Test\TestCase {
),
true
),
[
'9.2.0.0',
[
'dependencies' => [
'owncloud' => [
'@attributes' => [
'min-version' => '9.0',
'max-version' => '9.1',
],
],
'nextcloud' => [
'@attributes' => [
'min-version' => '9.1',
'max-version' => '9.2',
],
],
],
],
true
],
[
'9.2.0.0',
[
'dependencies' => [
'nextcloud' => [
'@attributes' => [
'min-version' => '9.1',
'max-version' => '9.2',
],
],
],
],
true
],
);
}

View file

@ -9,91 +9,572 @@
namespace Test;
use OC\App\AppStore\Fetcher\AppFetcher;
use OC\Archive\ZIP;
use OC\Installer;
use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;
use OCP\ILogger;
use OCP\ITempManager;
class InstallerTest extends TestCase {
private static $appid = 'testapp';
private $appstore;
/** @var AppFetcher|\PHPUnit_Framework_MockObject_MockObject */
private $appFetcher;
/** @var IClientService|\PHPUnit_Framework_MockObject_MockObject */
private $clientService;
/** @var ITempManager|\PHPUnit_Framework_MockObject_MockObject */
private $tempManager;
/** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
private $logger;
/** @var Installer */
private $installer;
protected function setUp() {
parent::setUp();
$this->appFetcher = $this->createMock(AppFetcher::class);
$this->clientService = $this->createMock(IClientService::class);
$this->tempManager = $this->createMock(ITempManager::class);
$this->logger = $this->createMock(ILogger::class);
$this->installer = new Installer(
$this->appFetcher,
$this->clientService,
$this->tempManager,
$this->logger
);
$config = \OC::$server->getConfig();
$this->appstore = $config->setSystemValue('appstoreenabled', true);
$config->setSystemValue('appstoreenabled', true);
Installer::removeApp(self::$appid);
$installer = new Installer(
\OC::$server->getAppFetcher(),
\OC::$server->getHTTPClientService(),
\OC::$server->getTempManager(),
\OC::$server->getLogger()
);
$installer->removeApp(self::$appid);
}
protected function tearDown() {
Installer::removeApp(self::$appid);
$installer = new Installer(
\OC::$server->getAppFetcher(),
\OC::$server->getHTTPClientService(),
\OC::$server->getTempManager(),
\OC::$server->getLogger()
);
$installer->removeApp(self::$appid);
\OC::$server->getConfig()->setSystemValue('appstoreenabled', $this->appstore);
parent::tearDown();
}
public function testInstallApp() {
$pathOfTestApp = __DIR__;
$pathOfTestApp .= '/../data/';
$pathOfTestApp .= 'testapp.zip';
// Extract app
$pathOfTestApp = __DIR__ . '/../data/testapp.zip';
$tar = new ZIP($pathOfTestApp);
$tar->extract(\OC_App::getInstallPath());
$tmp = \OC::$server->getTempManager()->getTemporaryFile('.zip');
\OC_Helper::copyr($pathOfTestApp, $tmp);
$data = array(
'path' => $tmp,
'source' => 'path',
'appdata' => [
'id' => 'Bar',
'level' => 100,
]
// Install app
$installer = new Installer(
\OC::$server->getAppFetcher(),
\OC::$server->getHTTPClientService(),
\OC::$server->getTempManager(),
\OC::$server->getLogger()
);
Installer::installApp($data);
$installer->installApp(self::$appid);
$isInstalled = Installer::isInstalled(self::$appid);
$this->assertTrue($isInstalled);
$installer->removeApp(self::$appid);
}
public function testUpdateApp() {
$pathOfOldTestApp = __DIR__;
$pathOfOldTestApp .= '/../data/';
$pathOfOldTestApp .= 'testapp.zip';
public function updateArrayProvider() {
return [
// Update available
[
[
[
'id' => 'files',
'releases' => [
[
'version' => '1111.0'
],
],
],
],
'1111.0',
],
// No update available
[
[
[
'id' => 'files',
'releases' => [
[
'version' => '1.0'
],
],
],
],
false,
],
];
}
$oldTmp = \OC::$server->getTempManager()->getTemporaryFile('.zip');
\OC_Helper::copyr($pathOfOldTestApp, $oldTmp);
/**
* @dataProvider updateArrayProvider
* @param array $appArray
* @param string|bool $updateAvailable
*/
public function testIsUpdateAvailable(array $appArray, $updateAvailable) {
$this->appFetcher
->expects($this->once())
->method('get')
->willReturn($appArray);
$oldData = array(
'path' => $oldTmp,
'source' => 'path',
'appdata' => [
'id' => 'Bar',
'level' => 100,
]
);
$this->assertSame($updateAvailable, Installer::isUpdateAvailable('files', $this->appFetcher));
}
$pathOfNewTestApp = __DIR__;
$pathOfNewTestApp .= '/../data/';
$pathOfNewTestApp .= 'testapp2.zip';
/**
* @expectedException \Exception
* @expectedExceptionMessage Certificate "4112" has been revoked
*/
public function testDownloadAppWithRevokedCertificate() {
$appArray = [
[
'id' => 'news',
'certificate' => '-----BEGIN CERTIFICATE-----
MIIEAjCCAuoCAhAQMA0GCSqGSIb3DQEBCwUAMHsxCzAJBgNVBAYTAkRFMRswGQYD
VQQIDBJCYWRlbi1XdWVydHRlbWJlcmcxFzAVBgNVBAoMDk5leHRjbG91ZCBHbWJI
MTYwNAYDVQQDDC1OZXh0Y2xvdWQgQ29kZSBTaWduaW5nIEludGVybWVkaWF0ZSBB
dXRob3JpdHkwHhcNMTYxMDAzMTMyNDM3WhcNMjcwMTA5MTMyNDM3WjASMRAwDgYD
VQQDDAdwYXNzbWFuMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEApEt+
KZGs+WqdZkHZflzqk+ophYWB8qB47XCzy+xdTGPFM84/9wXltRPbcQQWJJl5aOx0
FPbsyTGhIt/IYZ2Vl0XrDRJjsaxzPcrofrwpJ2tqforXjGohl6mZUBA0ESzFiPzT
SAZe8E14+Jk8rbF/ecrkqcWf2cTMV3Qfu9YvJo8WVs4lHc95r1F+Nalh/OLkHkzb
fYPno2Z5cco6U7BXunFQG2gqy3wWQwmlhDxh5fwrCoFzPWm7WhwSyK+eMoSDz+Vp
3kmtyijsqnda0zA9bfNzgW26czbJaObbnkdtDC2nfoAWXndlS/5YRI8yHd9miB5C
u1OC8LUWToDGNa9+FOxBSj7Nk6iyjbVfRXcTqThdkVZdOOPaBRMsL9R4UYywCbhA
yGNiQ0ahfXD8MZSb08rlQg8tAtcUZW1sYQcbtMGnu8OyC5J7N1efzv5mys4+9hBS
5ECeyCuQTuOkF4H/XS2BMSFZWF2xh7wzhMLca+5yauDW4i8baFEv74QTeY1DADgI
Lz29NJ6z9xYzEnPesjNrwIcJwIjV52EkdLTi+EIf83UjXLQdwDbLxu76qxqP7K0I
oMmwbl7UNA0wzq7nmgRhvqhow5RoCaSJjTz0EYQVSa1xelwiKeJiSKj2G9Mgt5Ms
Miuy3C3VAGvQJ2ocILPGOt54oVeNRFLpnCo1e3sCAwEAATANBgkqhkiG9w0BAQsF
AAOCAQEAkGYtg21rGpUVT/AokGUfI0PeyYAkcXKy2yuBAzfRk+uIXnRR0vK+OMpx
shBoYGR3JEGUHZcMTRh8wjAZ0wuyYlQONtJbFFF3bCfODXxCsw0Vm8/Ms+KCmE4Z
SyQafWEQf1sdqNw4VS4DYS2mlpDgAl+U9UY6HQKuT3+GFIxCsQSdS0GTaiYVKPVE
p/eKou739h+5dM4FEhIYZX+7PWlHmX6wPCFAjgNu3kiRGmF6LKmCNNXTySATEP86
tczQMzLtVdTg5z8XMi//6TkAPxRPjYi8Vef/s2mLo7KystTmofxI/HZePSieJ9tj
gLgK8d8sKL60JMmKHN3boHrsThKBVA==
-----END CERTIFICATE-----',
],
];
$this->appFetcher
->expects($this->once())
->method('get')
->willReturn($appArray);
$newTmp = \OC::$server->getTempManager()->getTemporaryFile('.zip');
\OC_Helper::copyr($pathOfNewTestApp, $newTmp);
$newData = array(
'path' => $newTmp,
'source' => 'path',
'appdata' => [
'id' => 'Bar',
'level' => 100,
]
);
$this->installer->downloadApp('news');
}
Installer::installApp($oldData);
$oldVersionNumber = \OC_App::getAppVersion(self::$appid);
/**
* @expectedException \Exception
* @expectedExceptionMessage App with id news has a certificate not issued by a trusted Code Signing Authority
*/
public function testDownloadAppWithNotNextcloudCertificate() {
$appArray = [
[
'id' => 'news',
'certificate' => '-----BEGIN CERTIFICATE-----
MIID8TCCAdkCAhAAMA0GCSqGSIb3DQEBCwUAMG0xCzAJBgNVBAYTAlVTMQ8wDQYD
VQQIDAZCb3N0b24xFjAUBgNVBAoMDW93bkNsb3VkIEluYy4xNTAzBgNVBAMMLG93
bkNsb3VkIENvZGUgU2lnbmluZyBJbnRlcm1lZGlhdGUgQXV0aG9yaXR5MB4XDTE2
MDIwMzE3NTE0OVoXDTI2MDEzMTE3NTE0OVowDzENMAsGA1UEAwwEY29yZTCCASIw
DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAPHdSljnHI+ueQd27UyWPO9n4Lqt
bK0kdekiC3si7Mee7uXXJaGuqXJozHEZYB1LIFLdCU/itCxEk9hyLcyNzeT+nRT/
zDuOYdbLgCj7/A5bX+u3jc29UlCYybSFchfMdvn7a0njCna4dE+73b4yEj16tS2h
S1EUygSzgicWlJqMD3Z9Qc+zLEpdhq9oDdDB8HURi2NW4KzIraVncSH+zF1QduOh
nERDnF8x48D3FLdTxGA0W/Kg4gYsq4NRvU6g3DJNdp4YfqRSFMmLFDCgzDuhan7D
wgRlI9NAeHbnyoUPtrDBUceI7shIbC/i87xk9ptqV0AyFonkJtK6lWwZjNkCAwEA
ATANBgkqhkiG9w0BAQsFAAOCAgEAAMgymqZE1YaHYlRGwvTE7gGDY3gmFOMaxQL4
E5m0CnkBz4BdIPRsQFFdOv3l/MIWkw5ED3vUB925VpQZYFSiEuv5NbnlPaHZlIMI
n8AV/sTP5jue3LhtAN4EM63xNBhudAT6wVsvGwOuQOx9Xv+ptO8Po7sTuNYP0CMH
EOQN+/q8tYlSm2VW+dAlaJ+zVZwZldhVjL+lSH4E9ktWn3PmgNQeKfcnJISUbus6
ZtsYDF/X96/Z2ZQvMXOKksgvU6XlvIxllcyebC9Bxe/h0D63GCO2tqN5CWQzIIqn
apUynPX8BlLaaExqYGERwlUi/yOGaUVPUjEPVehviOQYgAqxlrkJk1dWeCrwUori
CXpi+IUYkidfgiJ9F88M3ElpwqIaXp7G3/4oHBuE2u6M+L+1/vqPJeTCAWUxxpJE
yYmM+db6D4TySFpQPENNzPS8bpR6T8w2hRumkldC42HrnyJJbpjOieTXhXzjdPvZ
IEP9JGtkhB2du6nBF2MNAq2TqRXpcfQrQEbnQ13aV9bl+roTwwO+SOWK/wgvdOMI
STQ0Xk0sTGlmQjPYPkibVceaWMR3sX4cNt5c33YhJys5jxHoAh42km4nN9tfykR5
crl5lBlKjXh2GP0+omSO3x1jX4+iQPCW2TWoyKkUdLu/hGHG2w8RrTeme+kATECH
YSu356M=
-----END CERTIFICATE-----',
],
];
$this->appFetcher
->expects($this->once())
->method('get')
->willReturn($appArray);
Installer::updateApp($newData);
$newVersionNumber = \OC_App::getAppVersion(self::$appid);
$this->installer->downloadApp('news');
}
$this->assertNotEquals($oldVersionNumber, $newVersionNumber);
/**
* @expectedException \Exception
* @expectedExceptionMessage App with id news has a cert issued to passman
*/
public function testDownloadAppWithDifferentCN() {
$appArray = [
[
'id' => 'news',
'certificate' => '-----BEGIN CERTIFICATE-----
MIIEAjCCAuoCAhAYMA0GCSqGSIb3DQEBCwUAMHsxCzAJBgNVBAYTAkRFMRswGQYD
VQQIDBJCYWRlbi1XdWVydHRlbWJlcmcxFzAVBgNVBAoMDk5leHRjbG91ZCBHbWJI
MTYwNAYDVQQDDC1OZXh0Y2xvdWQgQ29kZSBTaWduaW5nIEludGVybWVkaWF0ZSBB
dXRob3JpdHkwHhcNMTYxMDE5MTkzNTEyWhcNMjcwMTI1MTkzNTEyWjASMRAwDgYD
VQQDDAdwYXNzbWFuMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA1Jw1
8F0DefogaLaBudGbhK2zcFIBSzxhh7dRWguZKHGE+rG00BOvFLIAo37Bfmy9WKLc
3BFYvuFBowaVdaFOLxQJod0sOTmVMXhwoY5e3Xx+P+nsAw1/0gI10/LD1Vgl6i1u
gMocmnbEYhKwr0NbdiQiMI9UB9Ge/51wt4WtAxwK7yJFl3+5qzvJgfX75Wt+8L1e
Wk0LpVW23tUueJovjYZJXyAtohNaV3gwiST+QmKljCd4gwGX9abqfc76/lWtS+hI
rKptuICc55ffH30rqVhAgCMouF/Ml5Qru8tDen5dSNtmAXz89OlDNisP+9HL4WDZ
wvgps0mm/OYAUAQln24uXPDmAX/H2P5xIDHAa8avsqdgmHiqnLr4GYD8JYeb8GmB
zZ38hEMjCr2F1k1h9T1+SyfRiDPDqqv1mBtcvNVc1JmZvSikMxhtQbU0C4/o2SBG
RPCirknfPeKu8wBi6gvH4/SK0XTyuM8H58b9AKxzoo/wLbQ668+faLYyMSzCvsZD
eeZkiO85y87Ax57WRY93arccCMaUeks/cTriNw3JrvdDyb2SeQOX9JUp0orUlC64
AzK2xhXCpmkprVBGizT5g3brrknX6VDX1gXFAmH/daCRJAIHPX0S/ol0z9w/hCEl
CpbiJPEphGtxqz4SfMv6IrIfneuDDKbF+w5MV/sCAwEAATANBgkqhkiG9w0BAQsF
AAOCAQEAUKj+/GpnMn+0/u9SPHTNmX3U3Y/ldmud0CsU5ELzMf/3YPbC/qWziRik
ewM2WyG8cwT9ayt9DxWGfu/zLv+ddyl8Wje1e/FIkRKXK0WW6OMz3e8Y45ONzpmu
8ME75IpnMuZEqE/WayRg27dQT5QNnEe/uNLd4m9BfsQcHIx3OfHCu5Of6/BclgsJ
VWp31zY8kcT0QN1GQxfB3eXnMyELneKCP3OH9DBhr4FUFb0vRHc8/1rdADFvSsdX
hNm8iRq+s2n0F6OGBofYT8ZyCnDUSQAoKMTIHcz+dDGyP4BfPY5w0ZGUfuaYATvm
cR92p/PYCFXkAKP3OO0RPlf6dXNKTw==
-----END CERTIFICATE-----',
],
];
$this->appFetcher
->expects($this->once())
->method('get')
->willReturn($appArray);
$this->installer->downloadApp('news');
}
/**
* @expectedException \Exception
* @expectedExceptionMessage App with id passman has invalid signature
*/
public function testDownloadAppWithInvalidSignature() {
$appArray = [
[
'id' => 'passman',
'certificate' => '-----BEGIN CERTIFICATE-----
MIIEAjCCAuoCAhAYMA0GCSqGSIb3DQEBCwUAMHsxCzAJBgNVBAYTAkRFMRswGQYD
VQQIDBJCYWRlbi1XdWVydHRlbWJlcmcxFzAVBgNVBAoMDk5leHRjbG91ZCBHbWJI
MTYwNAYDVQQDDC1OZXh0Y2xvdWQgQ29kZSBTaWduaW5nIEludGVybWVkaWF0ZSBB
dXRob3JpdHkwHhcNMTYxMDE5MTkzNTEyWhcNMjcwMTI1MTkzNTEyWjASMRAwDgYD
VQQDDAdwYXNzbWFuMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA1Jw1
8F0DefogaLaBudGbhK2zcFIBSzxhh7dRWguZKHGE+rG00BOvFLIAo37Bfmy9WKLc
3BFYvuFBowaVdaFOLxQJod0sOTmVMXhwoY5e3Xx+P+nsAw1/0gI10/LD1Vgl6i1u
gMocmnbEYhKwr0NbdiQiMI9UB9Ge/51wt4WtAxwK7yJFl3+5qzvJgfX75Wt+8L1e
Wk0LpVW23tUueJovjYZJXyAtohNaV3gwiST+QmKljCd4gwGX9abqfc76/lWtS+hI
rKptuICc55ffH30rqVhAgCMouF/Ml5Qru8tDen5dSNtmAXz89OlDNisP+9HL4WDZ
wvgps0mm/OYAUAQln24uXPDmAX/H2P5xIDHAa8avsqdgmHiqnLr4GYD8JYeb8GmB
zZ38hEMjCr2F1k1h9T1+SyfRiDPDqqv1mBtcvNVc1JmZvSikMxhtQbU0C4/o2SBG
RPCirknfPeKu8wBi6gvH4/SK0XTyuM8H58b9AKxzoo/wLbQ668+faLYyMSzCvsZD
eeZkiO85y87Ax57WRY93arccCMaUeks/cTriNw3JrvdDyb2SeQOX9JUp0orUlC64
AzK2xhXCpmkprVBGizT5g3brrknX6VDX1gXFAmH/daCRJAIHPX0S/ol0z9w/hCEl
CpbiJPEphGtxqz4SfMv6IrIfneuDDKbF+w5MV/sCAwEAATANBgkqhkiG9w0BAQsF
AAOCAQEAUKj+/GpnMn+0/u9SPHTNmX3U3Y/ldmud0CsU5ELzMf/3YPbC/qWziRik
ewM2WyG8cwT9ayt9DxWGfu/zLv+ddyl8Wje1e/FIkRKXK0WW6OMz3e8Y45ONzpmu
8ME75IpnMuZEqE/WayRg27dQT5QNnEe/uNLd4m9BfsQcHIx3OfHCu5Of6/BclgsJ
VWp31zY8kcT0QN1GQxfB3eXnMyELneKCP3OH9DBhr4FUFb0vRHc8/1rdADFvSsdX
hNm8iRq+s2n0F6OGBofYT8ZyCnDUSQAoKMTIHcz+dDGyP4BfPY5w0ZGUfuaYATvm
cR92p/PYCFXkAKP3OO0RPlf6dXNKTw==
-----END CERTIFICATE-----',
'releases' => [
[
'download' => 'https://example.com',
'signature' => 'MySignature',
],
[
'download' => 'https://nextcloud.com',
],
],
],
];
$this->appFetcher
->expects($this->once())
->method('get')
->willReturn($appArray);
$realTmpFile = \OC::$server->getTempManager()->getTemporaryFile('.tar.gz');
copy(__DIR__ . '/../data/testapp.tar.gz', $realTmpFile);
$this->tempManager
->expects($this->at(0))
->method('getTemporaryFile')
->with('.tar.gz')
->willReturn($realTmpFile);
$client = $this->createMock(IClient::class);
$client
->expects($this->once())
->method('get')
->with('https://example.com', ['save_to' => $realTmpFile]);
$this->clientService
->expects($this->once())
->method('newClient')
->willReturn($client);
$this->installer->downloadApp('passman');
}
/**
* @expectedException \Exception
* @expectedExceptionMessage Extracted app testapp has more than 1 folder
*/
public function testDownloadAppWithMoreThanOneFolderDownloaded() {
$appArray = [
[
'id' => 'testapp',
'certificate' => '-----BEGIN CERTIFICATE-----
MIIEAjCCAuoCAhAbMA0GCSqGSIb3DQEBCwUAMHsxCzAJBgNVBAYTAkRFMRswGQYD
VQQIDBJCYWRlbi1XdWVydHRlbWJlcmcxFzAVBgNVBAoMDk5leHRjbG91ZCBHbWJI
MTYwNAYDVQQDDC1OZXh0Y2xvdWQgQ29kZSBTaWduaW5nIEludGVybWVkaWF0ZSBB
dXRob3JpdHkwHhcNMTYxMDMxMTgxNTI2WhcNMjcwMjA2MTgxNTI2WjASMRAwDgYD
VQQDEwd0ZXN0YXBwMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAqa0x
FcVa0YcO/ABqSNdbf7Bzp2PBBJzVM9gI4/HzzBKU/NY9/RibBBpNjAIWEFAbTI4j
ilFSoxHDQ8HrboFOeKCrOIdp9ATQ8SnYVNIQ12Ym3LA/XxcG0gG0H7DeS9C0uACe
svN8fwD1wnKnLLU9GBzO77jwYkneed85wwKG4waHd3965gxQWq0N5gnYS0TTn7Yr
l1veRiw+ryefXvfWI0cN1WBZJ/4XAkwVlpG1HP60AunIpcwn9bfG4XCka+7x26E4
6Hw0Ot7D7j0yzVzimJDPB2h2buEtPVd6m+oNPueVvKGta+p6cEEaHlFVh2Pa9DI+
me3nb6aXE2kABWXav3BmK18A5Rg4ZY4VFYvmHmxkOhT/ulGZRqy6TccL/optqs52
KQ6P0e5dfmhLeoCvJObD+ZYKv+kJCRFtX1Hve/R4IHG6XSFKUfrRjyor9b6TX2L/
l2vV0mFjmy4g3l05vWHg1Edtq7M29S/xNA3/hF29NjBq6NoMbLGcBtFced1iK07Z
yHLjXRZRfURP671Svqqg8pjxuDqkJ2vIj/Vpod4kF2jeiZYXcfmNKhEhxpkccSe0
dI6p76Ne7XSUpf8yCPiSnWZLadqKZdEulcB4SlrZO2+/pycgqrqihofDrvDeWeeg
gQyvbZZKl4ylRNj6IRKnosKLVXNqMHQxLmxLHeUCAwEAATANBgkqhkiG9w0BAQsF
AAOCAQEALkKQwa40HfuP4Q6ShwBFJbXLyodIAXCT014kBVjReDKNl5oHtMXRjPxj
nj9doKu+3bLNuLCv9uU3H5+t/GFogReV3Av3z/fCqJ6wHv/KX+lacj31dWXZGD8G
z+RYibrxKkPN0V6q1mSvkg3hJOOE+/4FPIdc8PNlgratv3WS4dT8QwGSUavHW2Kx
89nIdnwtLEFpgML/bTG0dm8BH57xER8LCYixW1VmpV6A4IsoKVsnB7KUCRTK3iUJ
Zh8Xg8UMNrOtXc1Wx1Wmjaa4ZE9dY6/KkU2ny2UWyDHKU/9VE8QQ4HN93gxU4+H7
cUg0V1uAxqUvKytKkMfcyPWsz/AINA==
-----END CERTIFICATE-----',
'releases' => [
[
'download' => 'https://example.com',
'signature' => 'h8H3tUy2dDlwrV/hY/ZxqYqe8Vue+IINluLtAt1HxX2cjz3vdoVHJRINRkMYYcdz
VlndvHyKdqJHDAACphR8tVV6EFrPermn7gEgWk7a51LbUM7sAN7RV7ijEooUo+TQ
jNW9Ch48Wg3jvebMwWNr5t5U4MEXTP5f0YX/kxvkJoUrG3a3spt7ziEuHaq8IPvt
Jj/JSDFhvRNpom7yNNcI1Ijoq8yC11sg7RJBNfrHdGPHPZVz2SyBiY9OcvgGSpUU
bfvzhIZDCl/RRi5fs39jLLupAP69Ez6+jylNXEMsNwM0YL5+egSXFtkCvgOw8UBg
ZqNZZojcS22acuvHRnoa6PDDhwHdCH+zpifXSOhSQvue5n6q+FVX6aeD1LnCQkYB
D2wvNyZWwdADJtvDj03DKhm21g+TPy63XC94q4IqvjQ94pV8U+qrBBfkQ62NGjaC
oOU6y5sEmQeAdVRpWVo0Hewmjp4Adoj5JRwuqCVEynTC6DXHs3HvHxYlmib1F05a
GqEhdDmOHsxNaeJ08Hlptq5yLv3+0wEdtriVjgAZNVduHG1F1FkhPIrDHaB6pd67
0AFvO/pZgMSHDRHD+safBgaLb5dBZ895Qvudbq3RQevVnO+YZQYZkpmjoF/+TQ7/
YwDVP+QmNRzx72jtqAN/Kc3CvQ9nkgYhU65B95aX0xA=',
],
[
'download' => 'https://nextcloud.com',
],
],
],
];
$this->appFetcher
->expects($this->once())
->method('get')
->willReturn($appArray);
$realTmpFile = \OC::$server->getTempManager()->getTemporaryFile('.tar.gz');
copy(__DIR__ . '/../data/testapp1.tar.gz', $realTmpFile);
$this->tempManager
->expects($this->at(0))
->method('getTemporaryFile')
->with('.tar.gz')
->willReturn($realTmpFile);
$realTmpFolder = \OC::$server->getTempManager()->getTemporaryFolder();
mkdir($realTmpFolder . '/testfolder');
$this->tempManager
->expects($this->at(1))
->method('getTemporaryFolder')
->willReturn($realTmpFolder);
$client = $this->createMock(IClient::class);
$client
->expects($this->once())
->method('get')
->with('https://example.com', ['save_to' => $realTmpFile]);
$this->clientService
->expects($this->once())
->method('newClient')
->willReturn($client);
$this->installer->downloadApp('testapp');
}
/**
* @expectedException \Exception
* @expectedExceptionMessage App for id testapp has a wrong app ID in info.xml: testapp1
*/
public function testDownloadAppWithMismatchingIdentifier() {
$appArray = [
[
'id' => 'testapp',
'certificate' => '-----BEGIN CERTIFICATE-----
MIIEAjCCAuoCAhAbMA0GCSqGSIb3DQEBCwUAMHsxCzAJBgNVBAYTAkRFMRswGQYD
VQQIDBJCYWRlbi1XdWVydHRlbWJlcmcxFzAVBgNVBAoMDk5leHRjbG91ZCBHbWJI
MTYwNAYDVQQDDC1OZXh0Y2xvdWQgQ29kZSBTaWduaW5nIEludGVybWVkaWF0ZSBB
dXRob3JpdHkwHhcNMTYxMDMxMTgxNTI2WhcNMjcwMjA2MTgxNTI2WjASMRAwDgYD
VQQDEwd0ZXN0YXBwMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAqa0x
FcVa0YcO/ABqSNdbf7Bzp2PBBJzVM9gI4/HzzBKU/NY9/RibBBpNjAIWEFAbTI4j
ilFSoxHDQ8HrboFOeKCrOIdp9ATQ8SnYVNIQ12Ym3LA/XxcG0gG0H7DeS9C0uACe
svN8fwD1wnKnLLU9GBzO77jwYkneed85wwKG4waHd3965gxQWq0N5gnYS0TTn7Yr
l1veRiw+ryefXvfWI0cN1WBZJ/4XAkwVlpG1HP60AunIpcwn9bfG4XCka+7x26E4
6Hw0Ot7D7j0yzVzimJDPB2h2buEtPVd6m+oNPueVvKGta+p6cEEaHlFVh2Pa9DI+
me3nb6aXE2kABWXav3BmK18A5Rg4ZY4VFYvmHmxkOhT/ulGZRqy6TccL/optqs52
KQ6P0e5dfmhLeoCvJObD+ZYKv+kJCRFtX1Hve/R4IHG6XSFKUfrRjyor9b6TX2L/
l2vV0mFjmy4g3l05vWHg1Edtq7M29S/xNA3/hF29NjBq6NoMbLGcBtFced1iK07Z
yHLjXRZRfURP671Svqqg8pjxuDqkJ2vIj/Vpod4kF2jeiZYXcfmNKhEhxpkccSe0
dI6p76Ne7XSUpf8yCPiSnWZLadqKZdEulcB4SlrZO2+/pycgqrqihofDrvDeWeeg
gQyvbZZKl4ylRNj6IRKnosKLVXNqMHQxLmxLHeUCAwEAATANBgkqhkiG9w0BAQsF
AAOCAQEALkKQwa40HfuP4Q6ShwBFJbXLyodIAXCT014kBVjReDKNl5oHtMXRjPxj
nj9doKu+3bLNuLCv9uU3H5+t/GFogReV3Av3z/fCqJ6wHv/KX+lacj31dWXZGD8G
z+RYibrxKkPN0V6q1mSvkg3hJOOE+/4FPIdc8PNlgratv3WS4dT8QwGSUavHW2Kx
89nIdnwtLEFpgML/bTG0dm8BH57xER8LCYixW1VmpV6A4IsoKVsnB7KUCRTK3iUJ
Zh8Xg8UMNrOtXc1Wx1Wmjaa4ZE9dY6/KkU2ny2UWyDHKU/9VE8QQ4HN93gxU4+H7
cUg0V1uAxqUvKytKkMfcyPWsz/AINA==
-----END CERTIFICATE-----',
'releases' => [
[
'download' => 'https://example.com',
'signature' => 'h8H3tUy2dDlwrV/hY/ZxqYqe8Vue+IINluLtAt1HxX2cjz3vdoVHJRINRkMYYcdz
VlndvHyKdqJHDAACphR8tVV6EFrPermn7gEgWk7a51LbUM7sAN7RV7ijEooUo+TQ
jNW9Ch48Wg3jvebMwWNr5t5U4MEXTP5f0YX/kxvkJoUrG3a3spt7ziEuHaq8IPvt
Jj/JSDFhvRNpom7yNNcI1Ijoq8yC11sg7RJBNfrHdGPHPZVz2SyBiY9OcvgGSpUU
bfvzhIZDCl/RRi5fs39jLLupAP69Ez6+jylNXEMsNwM0YL5+egSXFtkCvgOw8UBg
ZqNZZojcS22acuvHRnoa6PDDhwHdCH+zpifXSOhSQvue5n6q+FVX6aeD1LnCQkYB
D2wvNyZWwdADJtvDj03DKhm21g+TPy63XC94q4IqvjQ94pV8U+qrBBfkQ62NGjaC
oOU6y5sEmQeAdVRpWVo0Hewmjp4Adoj5JRwuqCVEynTC6DXHs3HvHxYlmib1F05a
GqEhdDmOHsxNaeJ08Hlptq5yLv3+0wEdtriVjgAZNVduHG1F1FkhPIrDHaB6pd67
0AFvO/pZgMSHDRHD+safBgaLb5dBZ895Qvudbq3RQevVnO+YZQYZkpmjoF/+TQ7/
YwDVP+QmNRzx72jtqAN/Kc3CvQ9nkgYhU65B95aX0xA=',
],
[
'download' => 'https://nextcloud.com',
],
],
],
];
$this->appFetcher
->expects($this->once())
->method('get')
->willReturn($appArray);
$realTmpFile = \OC::$server->getTempManager()->getTemporaryFile('.tar.gz');
copy(__DIR__ . '/../data/testapp1.tar.gz', $realTmpFile);
$this->tempManager
->expects($this->at(0))
->method('getTemporaryFile')
->with('.tar.gz')
->willReturn($realTmpFile);
$realTmpFolder = \OC::$server->getTempManager()->getTemporaryFolder();
$this->tempManager
->expects($this->at(1))
->method('getTemporaryFolder')
->willReturn($realTmpFolder);
$client = $this->createMock(IClient::class);
$client
->expects($this->once())
->method('get')
->with('https://example.com', ['save_to' => $realTmpFile]);
$this->clientService
->expects($this->once())
->method('newClient')
->willReturn($client);
$this->installer->downloadApp('testapp');
}
public function testDownloadAppSuccessful() {
$appArray = [
[
'id' => 'testapp',
'certificate' => '-----BEGIN CERTIFICATE-----
MIIEAjCCAuoCAhAbMA0GCSqGSIb3DQEBCwUAMHsxCzAJBgNVBAYTAkRFMRswGQYD
VQQIDBJCYWRlbi1XdWVydHRlbWJlcmcxFzAVBgNVBAoMDk5leHRjbG91ZCBHbWJI
MTYwNAYDVQQDDC1OZXh0Y2xvdWQgQ29kZSBTaWduaW5nIEludGVybWVkaWF0ZSBB
dXRob3JpdHkwHhcNMTYxMDMxMTgxNTI2WhcNMjcwMjA2MTgxNTI2WjASMRAwDgYD
VQQDEwd0ZXN0YXBwMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAqa0x
FcVa0YcO/ABqSNdbf7Bzp2PBBJzVM9gI4/HzzBKU/NY9/RibBBpNjAIWEFAbTI4j
ilFSoxHDQ8HrboFOeKCrOIdp9ATQ8SnYVNIQ12Ym3LA/XxcG0gG0H7DeS9C0uACe
svN8fwD1wnKnLLU9GBzO77jwYkneed85wwKG4waHd3965gxQWq0N5gnYS0TTn7Yr
l1veRiw+ryefXvfWI0cN1WBZJ/4XAkwVlpG1HP60AunIpcwn9bfG4XCka+7x26E4
6Hw0Ot7D7j0yzVzimJDPB2h2buEtPVd6m+oNPueVvKGta+p6cEEaHlFVh2Pa9DI+
me3nb6aXE2kABWXav3BmK18A5Rg4ZY4VFYvmHmxkOhT/ulGZRqy6TccL/optqs52
KQ6P0e5dfmhLeoCvJObD+ZYKv+kJCRFtX1Hve/R4IHG6XSFKUfrRjyor9b6TX2L/
l2vV0mFjmy4g3l05vWHg1Edtq7M29S/xNA3/hF29NjBq6NoMbLGcBtFced1iK07Z
yHLjXRZRfURP671Svqqg8pjxuDqkJ2vIj/Vpod4kF2jeiZYXcfmNKhEhxpkccSe0
dI6p76Ne7XSUpf8yCPiSnWZLadqKZdEulcB4SlrZO2+/pycgqrqihofDrvDeWeeg
gQyvbZZKl4ylRNj6IRKnosKLVXNqMHQxLmxLHeUCAwEAATANBgkqhkiG9w0BAQsF
AAOCAQEALkKQwa40HfuP4Q6ShwBFJbXLyodIAXCT014kBVjReDKNl5oHtMXRjPxj
nj9doKu+3bLNuLCv9uU3H5+t/GFogReV3Av3z/fCqJ6wHv/KX+lacj31dWXZGD8G
z+RYibrxKkPN0V6q1mSvkg3hJOOE+/4FPIdc8PNlgratv3WS4dT8QwGSUavHW2Kx
89nIdnwtLEFpgML/bTG0dm8BH57xER8LCYixW1VmpV6A4IsoKVsnB7KUCRTK3iUJ
Zh8Xg8UMNrOtXc1Wx1Wmjaa4ZE9dY6/KkU2ny2UWyDHKU/9VE8QQ4HN93gxU4+H7
cUg0V1uAxqUvKytKkMfcyPWsz/AINA==
-----END CERTIFICATE-----',
'releases' => [
[
'download' => 'https://example.com',
'signature' => 'O5UWFRnSx4mSdEX83Uh9u7KW+Gl1OWU4uaFg6aYY19zc+lWP4rKCbAUH7Jo1Bohf
qxQbhXs4cMqGmoL8dW4zeFUqSJCRk52LA+ciLezjPFv275q+BxEgyWOylLnbhBaz
+v6lXLaeG0J/ry8wEdg+rwP8FCYPsvKlXSVbFjgubvCR/owKJJf5iL0B93noBwBN
jfbcxi7Kh16HAKy6f/gVZ6hf/4Uo7iEFMCPEHjidope+ejUpqbd8XhQg5/yh7TQ7
VKR7pkdDG2eFr5c3CpaECdNg5ZIGRbQNJHBXHT/wliorWpYJtwtNAQJ4xC635gLP
4klkKN4XtSj8bJUaJC6aaksLFgRSeKXaYAHai/XP6BkeyNzlSbsmyZk8cZbySx8F
gVOzPok1c94UGT57FjeW5eqRjtmzbYivQdP89Ouz6et7PY69yOCqiRFQanrqzwoX
MPLX6f5V9tCJtlH6ztmEcDROfvuVc0U3rEhqx2hphoyo+MZrPFpdcJL8KkIdMKbY
7yQWrsV7QvAzygAOFsC0TlSNJbmMCljouUk9di4CUZ+xsQ6n6TZtE7gsdljlKjPS
3Ys+e3V1HUaVzv8SaSmKwjRoQxQxHWLtXpJS2Yq+i+gq7LuC+aStzxAzV/h2plDW
358picx/PobNDi71Q97+/CAOq+4wDOwhKwls7lwudIs=',
],
[
'download' => 'https://nextcloud.com',
],
],
],
];
$this->appFetcher
->expects($this->once())
->method('get')
->willReturn($appArray);
$realTmpFile = \OC::$server->getTempManager()->getTemporaryFile('.tar.gz');
copy(__DIR__ . '/../data/testapp.tar.gz', $realTmpFile);
$this->tempManager
->expects($this->at(0))
->method('getTemporaryFile')
->with('.tar.gz')
->willReturn($realTmpFile);
$realTmpFolder = \OC::$server->getTempManager()->getTemporaryFolder();
$this->tempManager
->expects($this->at(1))
->method('getTemporaryFolder')
->willReturn($realTmpFolder);
$client = $this->createMock(IClient::class);
$client
->expects($this->once())
->method('get')
->with('https://example.com', ['save_to' => $realTmpFile]);
$this->clientService
->expects($this->once())
->method('newClient')
->willReturn($client);
$this->installer->downloadApp('testapp');
$this->assertTrue(file_exists(__DIR__ . '/../../apps/testapp/appinfo/info.xml'));
$this->assertEquals('0.9', \OC_App::getAppVersionByPath(__DIR__ . '/../../apps/testapp/'));
}
}

File diff suppressed because it is too large Load diff

View file

@ -23,6 +23,8 @@
*/
namespace Test;
use OC\App\AppStore\Fetcher\AppFetcher;
use OC\App\AppStore\Fetcher\CategoryFetcher;
/**
* Class Server
@ -50,6 +52,7 @@ class ServerTest extends \Test\TestCase {
['AllConfig', '\OCP\IConfig'],
['AppConfig', '\OC\AppConfig'],
['AppConfig', '\OCP\IAppConfig'],
['AppFetcher', AppFetcher::class],
['AppHelper', '\OC\AppHelper'],
['AppHelper', '\OCP\IHelper'],
['AppManager', '\OC\App\AppManager'],
@ -59,6 +62,7 @@ class ServerTest extends \Test\TestCase {
['AvatarManager', '\OC\AvatarManager'],
['AvatarManager', '\OCP\IAvatarManager'],
['CategoryFetcher', CategoryFetcher::class],
['CapabilitiesManager', '\OC\CapabilitiesManager'],
['ContactsManager', '\OC\ContactsManager'],
['ContactsManager', '\OCP\Contacts\IManager'],
@ -122,8 +126,6 @@ class ServerTest extends \Test\TestCase {
['UserCache', '\OC\Cache\File'],
['UserCache', '\OCP\ICache'],
['OcsClient', '\OC\OCSClient'],
['PreviewManager', '\OC\PreviewManager'],
['PreviewManager', '\OCP\IPreview'],

View file

@ -38,7 +38,7 @@ class StreamWrappersTest extends \Test\TestCase {
public static function tearDownAfterClass() {
if (self::$trashBinStatus) {
\OC_App::enable('files_trashbin');
(new \OC_App())->enable('files_trashbin');
}
}