diff options
author | Daniel Kesselberg <mail@danielkesselberg.de> | 2019-01-26 22:31:45 +0100 |
---|---|---|
committer | Daniel Kesselberg <mail@danielkesselberg.de> | 2019-01-26 22:31:45 +0100 |
commit | c09ddf6c78cfd29de739d7b639700dab8b15707e (patch) | |
tree | 5195114f961f16144946d55d6e94f18f2797259f | |
parent | 996bad61b78b07f241b3b26c0fc98134ea8ab9f7 (diff) | |
download | nextcloud-server-c09ddf6c78cfd29de739d7b639700dab8b15707e.tar.gz nextcloud-server-c09ddf6c78cfd29de739d7b639700dab8b15707e.zip |
Check app path for enableAppForGroups
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
-rw-r--r-- | lib/private/App/AppManager.php | 13 | ||||
-rw-r--r-- | tests/lib/App/AppManagerTest.php | 34 |
2 files changed, 38 insertions, 9 deletions
diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php index 94addb2b785..7d4dbbbd34e 100644 --- a/lib/private/App/AppManager.php +++ b/lib/private/App/AppManager.php @@ -254,15 +254,16 @@ class AppManager implements IAppManager { * * @param string $appId * @param \OCP\IGroup[] $groups - * @throws \Exception if app can't be enabled for groups + * @throws \InvalidArgumentException if app can't be enabled for groups + * @throws AppPathNotFoundException */ public function enableAppForGroups($appId, $groups) { + // Check if app exists + $this->getAppPath($appId); + $info = $this->getAppInfo($appId); - if (!empty($info['types'])) { - $protectedTypes = array_intersect($this->protectedAppTypes, $info['types']); - if (!empty($protectedTypes)) { - throw new \Exception("$appId can't be enabled for groups."); - } + if (!empty($info['types']) && $this->hasProtectedAppType($info['types'])) { + throw new \InvalidArgumentException("$appId can't be enabled for groups."); } $groupIds = array_map(function ($group) { diff --git a/tests/lib/App/AppManagerTest.php b/tests/lib/App/AppManagerTest.php index bea39d1bc16..67188fae633 100644 --- a/tests/lib/App/AppManagerTest.php +++ b/tests/lib/App/AppManagerTest.php @@ -149,7 +149,23 @@ class AppManagerTest extends TestCase { new Group('group2', array(), null) ); $this->expectClearCache(); - $this->manager->enableAppForGroups('test', $groups); + + /** @var AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */ + $manager = $this->getMockBuilder(AppManager::class) + ->setConstructorArgs([ + $this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher + ]) + ->setMethods([ + 'getAppPath', + ]) + ->getMock(); + + $manager->expects($this->exactly(2)) + ->method('getAppPath') + ->with('test') + ->willReturn('apps/test'); + + $manager->enableAppForGroups('test', $groups); $this->assertEquals('["group1","group2"]', $this->appConfig->getValue('test', 'enabled', 'no')); } @@ -183,11 +199,17 @@ class AppManagerTest extends TestCase { $this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher ]) ->setMethods([ - 'getAppInfo' + 'getAppPath', + 'getAppInfo', ]) ->getMock(); $manager->expects($this->once()) + ->method('getAppPath') + ->with('test') + ->willReturn(null); + + $manager->expects($this->once()) ->method('getAppInfo') ->with('test') ->willReturn($appInfo); @@ -226,11 +248,17 @@ class AppManagerTest extends TestCase { $this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher ]) ->setMethods([ - 'getAppInfo' + 'getAppPath', + 'getAppInfo', ]) ->getMock(); $manager->expects($this->once()) + ->method('getAppPath') + ->with('test') + ->willReturn(null); + + $manager->expects($this->once()) ->method('getAppInfo') ->with('test') ->willReturn([ |