summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2021-07-22 11:41:29 +0200
committerCarl Schwan <carl@carlschwan.eu>2021-09-29 21:43:31 +0200
commit6958d8005ae3b86759f49746564bf7238456be52 (patch)
treeaab851e09351c631129e4729aa49c03533ce6180 /tests
parentee987d74303cb38b864f96660cd2ee6d6552ebfd (diff)
downloadnextcloud-server-6958d8005ae3b86759f49746564bf7238456be52.tar.gz
nextcloud-server-6958d8005ae3b86759f49746564bf7238456be52.zip
Add admin privilege delegation for admin settings
This makes it possible for selected groups to access some settings pages. Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php12
-rw-r--r--tests/lib/Settings/ManagerTest.php31
2 files changed, 33 insertions, 10 deletions
diff --git a/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php
index 8f55f90d377..bf84a631f74 100644
--- a/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php
+++ b/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php
@@ -32,6 +32,7 @@ use OC\AppFramework\Middleware\Security\Exceptions\SecurityException;
use OC\Appframework\Middleware\Security\Exceptions\StrictCookieMissingException;
use OC\AppFramework\Middleware\Security\SecurityMiddleware;
use OC\AppFramework\Utility\ControllerMethodReflector;
+use OC\Settings\AuthorizedGroupMapper;
use OCP\App\IAppManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
@@ -42,6 +43,7 @@ use OCP\IL10N;
use OCP\INavigationManager;
use OCP\IRequest;
use OCP\IURLGenerator;
+use OCP\IUserSession;
use OCP\Security\ISecureRandom;
use Psr\Log\LoggerInterface;
@@ -69,10 +71,16 @@ class SecurityMiddlewareTest extends \Test\TestCase {
private $appManager;
/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
private $l10n;
+ /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
+ private $userSession;
+ /** @var AuthorizedGroupMapper|\PHPUnit\Framework\MockObject\MockObject */
+ private $authorizedGroupMapper;
protected function setUp(): void {
parent::setUp();
+ $this->authorizedGroupMapper = $this->createMock(AuthorizedGroupMapper::class);
+ $this->userSession = $this->createMock(IUserSession::class);
$this->controller = $this->createMock(Controller::class);
$this->reader = new ControllerMethodReflector();
$this->logger = $this->createMock(LoggerInterface::class);
@@ -102,7 +110,9 @@ class SecurityMiddlewareTest extends \Test\TestCase {
$isAdminUser,
$isSubAdmin,
$this->appManager,
- $this->l10n
+ $this->l10n,
+ $this->authorizedGroupMapper,
+ $this->userSession
);
}
diff --git a/tests/lib/Settings/ManagerTest.php b/tests/lib/Settings/ManagerTest.php
index 3d967b2ed21..96711e75cab 100644
--- a/tests/lib/Settings/ManagerTest.php
+++ b/tests/lib/Settings/ManagerTest.php
@@ -23,22 +23,25 @@
namespace OCA\Settings\Tests\AppInfo;
+use OC\Settings\AuthorizedGroupMapper;
use OC\Settings\Manager;
+use OCP\Group\ISubAdmin;
use OCP\IDBConnection;
+use OCP\IGroupManager;
use OCP\IL10N;
-use OCP\ILogger;
use OCP\IServerContainer;
use OCP\IURLGenerator;
use OCP\L10N\IFactory;
use OCP\Settings\ISettings;
use OCP\Settings\ISubAdminSettings;
+use Psr\Log\LoggerInterface;
use Test\TestCase;
class ManagerTest extends TestCase {
/** @var Manager|\PHPUnit\Framework\MockObject\MockObject */
private $manager;
- /** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
private $logger;
/** @var IDBConnection|\PHPUnit\Framework\MockObject\MockObject */
private $l10n;
@@ -48,21 +51,31 @@ class ManagerTest extends TestCase {
private $url;
/** @var IServerContainer|\PHPUnit\Framework\MockObject\MockObject */
private $container;
+ /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */
+ private $groupManager;
+ /** @var ISubAdmin|\PHPUnit\Framework\MockObject\MockObject */
+ private $subAdmin;
protected function setUp(): void {
parent::setUp();
- $this->logger = $this->createMock(ILogger::class);
+ $this->logger = $this->createMock(LoggerInterface::class);
$this->l10n = $this->createMock(IL10N::class);
$this->l10nFactory = $this->createMock(IFactory::class);
$this->url = $this->createMock(IURLGenerator::class);
$this->container = $this->createMock(IServerContainer::class);
+ $this->mapper = $this->createMock(AuthorizedGroupMapper::class);
+ $this->groupManager = $this->createMock(IGroupManager::class);
+ $this->subAdmin = $this->createMock(ISubAdmin::class);
$this->manager = new Manager(
$this->logger,
$this->l10nFactory,
$this->url,
- $this->container
+ $this->container,
+ $this->mapper,
+ $this->groupManager,
+ $this->subAdmin,
);
}
@@ -106,7 +119,7 @@ class ManagerTest extends TestCase {
->willReturn(13);
$section->method('getSection')
->willReturn('sharing');
- $this->container->method('query')
+ $this->container->method('get')
->with('myAdminClass')
->willReturn($section);
@@ -124,7 +137,7 @@ class ManagerTest extends TestCase {
->willReturn(13);
$section->method('getSection')
->willReturn('sharing');
- $this->container->method('query')
+ $this->container->method('get')
->with('myAdminClass')
->willReturn($section);
@@ -141,7 +154,7 @@ class ManagerTest extends TestCase {
$section->method('getSection')
->willReturn('sharing');
$this->container->expects($this->once())
- ->method('query')
+ ->method('get')
->with('mySubAdminClass')
->willReturn($section);
@@ -169,11 +182,11 @@ class ManagerTest extends TestCase {
$this->manager->registerSetting('personal', 'section2');
$this->container->expects($this->at(0))
- ->method('query')
+ ->method('get')
->with('section1')
->willReturn($section);
$this->container->expects($this->at(1))
- ->method('query')
+ ->method('get')
->with('section2')
->willReturn($section2);