Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for app:enable in case of not valid/not existing enterprise key #36399

Merged
merged 4 commits into from
Dec 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions changelog/unreleased/36399
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Bugfix: Inform the admin if they enable an enterprise app without valid key

Previously no message was displayed but the app was not enabled.

Now, when the admin tries to enable an enterprise app when the enterprise key
is invalid, the message "cannot be enabled because of invalid enterprise key"
is displayed.

https://github.com/owncloud/core/issues/36351
https://github.com/owncloud/core/pull/36399
18 changes: 17 additions & 1 deletion core/Command/App/Enable.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

namespace OC\Core\Command\App;

use OCP\IConfig;
use OCP\App\IAppManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -36,12 +37,17 @@ class Enable extends Command {
/** @var IAppManager */
protected $manager;

/** @var IConfig */
protected $config;

/**
* @param IAppManager $manager
* @param IConfig $config
*/
public function __construct(IAppManager $manager) {
public function __construct(IAppManager $manager, IConfig $config) {
parent::__construct();
$this->manager = $manager;
$this->config = $config;
}

protected function configure() {
Expand Down Expand Up @@ -70,6 +76,16 @@ protected function execute(InputInterface $input, OutputInterface $output) {
return 1;
}

if (\OC_App::isEnabled('enterprise_key')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue we found now is that if you have the enterprise app enabled, but have an invalid enterprise key, and you are just trying to enable a non-enterprise app, then the app cannot be enabled. e.g. enabling the testing app does not work.

If there is some way to check if the app being enabled is an Enterprise app, then this could be fixed by:

if (\OC_App::isEnterpriseApp($appId) && \OC_App::isEnabled('enterprise_key')) {

/* @phan-suppress-next-line PhanUndeclaredClassMethod */
$key = new \OCA\Enterprise_Key\EnterpriseKey(false, $this->config);
karakayasemi marked this conversation as resolved.
Show resolved Hide resolved
/* @phan-suppress-next-line PhanUndeclaredClassMethod */
if ($key && !$key->isValid()) {
phil-davis marked this conversation as resolved.
Show resolved Hide resolved
$output->writeln($appId . ' cannot be enabled because of invalid enterprise key');
return 1;
}
}

$groups = $input->getOption('groups');
if (empty($groups)) {
micbar marked this conversation as resolved.
Show resolved Hide resolved
\OC_App::enable($appId);
Expand Down
2 changes: 1 addition & 1 deletion core/register_command.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

if (\OC::$server->getConfig()->getSystemValue('installed', false)) {
$application->add(new OC\Core\Command\App\Disable(\OC::$server->getAppManager()));
$application->add(new OC\Core\Command\App\Enable(\OC::$server->getAppManager()));
$application->add(new OC\Core\Command\App\Enable(\OC::$server->getAppManager(), \OC::$server->getConfig()));
$application->add(new OC\Core\Command\App\GetPath());
$application->add(new OC\Core\Command\App\ListApps(\OC::$server->getAppManager()));

Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ parameters:
- '#Undefined variable: \$vendor#'
- '#Undefined variable: \$baseuri#'
- '#Instantiated class OC_Theme not found.#'
-
message: '#Instantiated class OCA\\Enterprise_Key\\EnterpriseKey not found.#'
path: core/Command/App/Enable.php
# errors below are to be addressed by own pull requests - non trivial changes required
- '#OCA\\DAV\\Connector\\Sabre\\ObjectTree::__construct\(\) does not call parent constructor from Sabre\\DAV\\Tree.#'
- '#OC\\Files\\ObjectStore\\NoopScanner::__construct\(\) does not call parent constructor from OC\\Files\\Cache\\Scanner.#'
Expand Down
5 changes: 4 additions & 1 deletion tests/Core/Command/Apps/AppsEnableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ class AppsEnableTest extends TestCase {
public function setUp(): void {
parent::setUp();

$command = new Enable(\OC::$server->getAppManager());
$command = new Enable(
\OC::$server->getAppManager(),
\OC::$server->getConfig()
);
$this->commandTester = new CommandTester($command);
}

Expand Down