summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2019-07-17 17:36:00 +0200
committerGitHub <noreply@github.com>2019-07-17 17:36:00 +0200
commit782554d2acdfd48b322753500906e8b291035250 (patch)
tree883a1a7b664ce1d0af21cf76b284afa2fae1b470 /tests
parent223a91d5ef91057f0e373a5824e4f360724d72fd (diff)
parent99f2c82222b0c67b3eddc8dff71aed1acacf1f23 (diff)
downloadnextcloud-server-782554d2acdfd48b322753500906e8b291035250.tar.gz
nextcloud-server-782554d2acdfd48b322753500906e8b291035250.zip
Merge pull request #16075 from nextcloud/bugfix/15823/app-restricted-groups
Remove deleted groups from app restrictions fixes #15823
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/App/AppManagerTest.php53
-rw-r--r--tests/lib/AppTest.php3
2 files changed, 49 insertions, 7 deletions
diff --git a/tests/lib/App/AppManagerTest.php b/tests/lib/App/AppManagerTest.php
index cb94ccf44d0..371c2373f81 100644
--- a/tests/lib/App/AppManagerTest.php
+++ b/tests/lib/App/AppManagerTest.php
@@ -19,6 +19,7 @@ use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IGroup;
use OCP\IGroupManager;
+use OCP\ILogger;
use OCP\IUser;
use OCP\IUserSession;
use OCP\IAppConfig;
@@ -90,6 +91,9 @@ class AppManagerTest extends TestCase {
/** @var EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject */
protected $eventDispatcher;
+ /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
+ protected $logger;
+
/** @var IAppManager */
protected $manager;
@@ -102,11 +106,12 @@ class AppManagerTest extends TestCase {
$this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->cache = $this->createMock(ICache::class);
$this->eventDispatcher = $this->createMock(EventDispatcherInterface::class);
+ $this->logger = $this->createMock(ILogger::class);
$this->cacheFactory->expects($this->any())
->method('createDistributed')
->with('settings')
->willReturn($this->cache);
- $this->manager = new AppManager($this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher);
+ $this->manager = new AppManager($this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger);
}
protected function expectClearCache() {
@@ -159,7 +164,7 @@ class AppManagerTest extends TestCase {
/** @var AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */
$manager = $this->getMockBuilder(AppManager::class)
->setConstructorArgs([
- $this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher
+ $this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger
])
->setMethods([
'getAppPath',
@@ -206,7 +211,7 @@ class AppManagerTest extends TestCase {
/** @var AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */
$manager = $this->getMockBuilder(AppManager::class)
->setConstructorArgs([
- $this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher
+ $this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger
])
->setMethods([
'getAppPath',
@@ -259,7 +264,7 @@ class AppManagerTest extends TestCase {
/** @var AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */
$manager = $this->getMockBuilder(AppManager::class)
->setConstructorArgs([
- $this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher
+ $this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger
])
->setMethods([
'getAppPath',
@@ -418,7 +423,7 @@ class AppManagerTest extends TestCase {
public function testGetAppsNeedingUpgrade() {
/** @var AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */
$manager = $this->getMockBuilder(AppManager::class)
- ->setConstructorArgs([$this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher])
+ ->setConstructorArgs([$this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger])
->setMethods(['getAppInfo'])
->getMock();
@@ -466,7 +471,7 @@ class AppManagerTest extends TestCase {
public function testGetIncompatibleApps() {
/** @var AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */
$manager = $this->getMockBuilder(AppManager::class)
- ->setConstructorArgs([$this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher])
+ ->setConstructorArgs([$this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger])
->setMethods(['getAppInfo'])
->getMock();
@@ -504,4 +509,40 @@ class AppManagerTest extends TestCase {
$this->assertEquals('test1', $apps[0]['id']);
$this->assertEquals('test3', $apps[1]['id']);
}
+
+ public function testGetEnabledAppsForGroup() {
+ $group = $this->createMock(IGroup::class);
+ $group->expects($this->any())
+ ->method('getGID')
+ ->will($this->returnValue('foo'));
+
+ $this->appConfig->setValue('test1', 'enabled', 'yes');
+ $this->appConfig->setValue('test2', 'enabled', 'no');
+ $this->appConfig->setValue('test3', 'enabled', '["foo"]');
+ $this->appConfig->setValue('test4', 'enabled', '["asd"]');
+ $enabled = [
+ 'cloud_federation_api',
+ 'dav',
+ 'federatedfilesharing',
+ 'files',
+ 'lookup_server_connector',
+ 'oauth2',
+ 'provisioning_api',
+ 'test1',
+ 'test3',
+ 'twofactor_backupcodes',
+ 'workflowengine',
+ ];
+ $this->assertEquals($enabled, $this->manager->getEnabledAppsForGroup($group));
+ }
+
+ public function testGetAppRestriction() {
+ $this->appConfig->setValue('test1', 'enabled', 'yes');
+ $this->appConfig->setValue('test2', 'enabled', 'no');
+ $this->appConfig->setValue('test3', 'enabled', '["foo"]');
+
+ $this->assertEquals([], $this->manager->getAppRestriction('test1'));
+ $this->assertEquals([], $this->manager->getAppRestriction('test2'));
+ $this->assertEquals(['foo'], $this->manager->getAppRestriction('test3'));
+ }
}
diff --git a/tests/lib/AppTest.php b/tests/lib/AppTest.php
index 5d98dc7df57..954ffcfae7f 100644
--- a/tests/lib/AppTest.php
+++ b/tests/lib/AppTest.php
@@ -542,7 +542,8 @@ class AppTest extends \Test\TestCase {
$appConfig,
\OC::$server->getGroupManager(),
\OC::$server->getMemCacheFactory(),
- \OC::$server->getEventDispatcher()
+ \OC::$server->getEventDispatcher(),
+ \OC::$server->getLogger()
));
}