summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2016-01-15 12:26:43 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2016-01-15 12:26:43 +0100
commitd8867f7692aae2cc5bb2ffaf00c53c9e77c61faf (patch)
tree52ca2bc073de23b16021e8bf1d54496da74b7980 /tests
parent64fb3c060620d099b7b9e8c7786aa50fc8be6dc5 (diff)
parente3a08584440b071e1caae7c7ff4f404c38b8794b (diff)
downloadnextcloud-server-d8867f7692aae2cc5bb2ffaf00c53c9e77c61faf.tar.gz
nextcloud-server-d8867f7692aae2cc5bb2ffaf00c53c9e77c61faf.zip
Merge pull request #21723 from owncloud/prevent-group-enable-for-apps
Prevent group enable for apps
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/app/manager.php93
1 files changed, 93 insertions, 0 deletions
diff --git a/tests/lib/app/manager.php b/tests/lib/app/manager.php
index a3e55c6b890..f82f1049ce3 100644
--- a/tests/lib/app/manager.php
+++ b/tests/lib/app/manager.php
@@ -13,6 +13,12 @@ use OC\Group\Group;
use OC\User\User;
use Test\TestCase;
+/**
+ * Class Manager
+ *
+ * @package Test\App
+ * @group DB
+ */
class Manager extends TestCase {
/**
* @return \OCP\IAppConfig | \PHPUnit_Framework_MockObject_MockObject
@@ -116,6 +122,93 @@ class Manager extends TestCase {
$this->assertEquals('["group1","group2"]', $this->appConfig->getValue('test', 'enabled', 'no'));
}
+ public function dataEnableAppForGroupsAllowedTypes() {
+ return [
+ [[]],
+ [[
+ 'types' => [],
+ ]],
+ [[
+ 'types' => ['nickvergessen'],
+ ]],
+ ];
+ }
+
+ /**
+ * @dataProvider dataEnableAppForGroupsAllowedTypes
+ *
+ * @param array $appInfo
+ */
+ public function testEnableAppForGroupsAllowedTypes(array $appInfo) {
+ $groups = array(
+ new Group('group1', array(), null),
+ new Group('group2', array(), null)
+ );
+ $this->expectClearCache();
+
+ /** @var \OC\App\AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */
+ $manager = $this->getMockBuilder('OC\App\AppManager')
+ ->setConstructorArgs([
+ $this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory
+ ])
+ ->setMethods([
+ 'getAppInfo'
+ ])
+ ->getMock();
+
+ $manager->expects($this->once())
+ ->method('getAppInfo')
+ ->with('test')
+ ->willReturn($appInfo);
+
+ $manager->enableAppForGroups('test', $groups);
+ $this->assertEquals('["group1","group2"]', $this->appConfig->getValue('test', 'enabled', 'no'));
+ }
+
+ public function dataEnableAppForGroupsForbiddenTypes() {
+ return [
+ ['filesystem'],
+ ['prelogin'],
+ ['authentication'],
+ ['logging'],
+ ['prevent_group_restriction'],
+ ];
+ }
+
+ /**
+ * @dataProvider dataEnableAppForGroupsForbiddenTypes
+ *
+ * @param string $type
+ *
+ * @expectedException \Exception
+ * @expectedExceptionMessage test can't be enabled for groups.
+ */
+ public function testEnableAppForGroupsForbiddenTypes($type) {
+ $groups = array(
+ new Group('group1', array(), null),
+ new Group('group2', array(), null)
+ );
+
+ /** @var \OC\App\AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */
+ $manager = $this->getMockBuilder('OC\App\AppManager')
+ ->setConstructorArgs([
+ $this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory
+ ])
+ ->setMethods([
+ 'getAppInfo'
+ ])
+ ->getMock();
+
+ $manager->expects($this->once())
+ ->method('getAppInfo')
+ ->with('test')
+ ->willReturn([
+ 'types' => [$type],
+ ]);
+
+ $manager->enableAppForGroups('test', $groups);
+ }
+
public function testIsInstalledEnabled() {
$this->appConfig->setValue('test', 'enabled', 'yes');
$this->assertTrue($this->manager->isInstalled('test'));