forked from nextcloud/server
-
Notifications
You must be signed in to change notification settings - Fork 0
extend admin-delegation #36
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
092b714
chore(tests): add unit tests for AdminDelegation command and Authoriz…
printminion-co 54d17c4
IONOS(admin-delegation): add unit tests for Delegation class
printminion-co 04f994d
IONOS(admin-delegation): update Delegation class to implement IDelega…
printminion-co 7078ebf
IONOS(admin-delegation): implement delegated settings logic in Manage…
printminion-co c8cf689
IONOS(admin-delegation): fix: clone settingManager in Delegation cons…
printminion-co 287eed5
IONOS(admin-delegation): Do not allow duplicated group delegations
printminion-co dca6279
IONOS(admin-delegation): fix display delegated section in common sett…
printminion-co 821309d
IONOS(admin-delegation): add support for only displaying delegated se…
printminion-co f13355f
IONOS(config): update submodule to 0d518e2 (configure only-delegated-…
printminion-co File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
| namespace OCA\Settings\Service; | ||
|
|
||
| class ConflictException extends ServiceException { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
184 changes: 184 additions & 0 deletions
184
apps/settings/tests/Command/AdminDelegation/AddTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,184 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Settings\Tests\Command\AdminDelegation; | ||
|
|
||
| use OC\Settings\AuthorizedGroup; | ||
| use OCA\Settings\Command\AdminDelegation\Add; | ||
| use OCA\Settings\Service\AuthorizedGroupService; | ||
| use OCA\Settings\Service\ConflictException; | ||
| use OCP\IGroupManager; | ||
| use OCP\Settings\IManager; | ||
| use PHPUnit\Framework\MockObject\MockObject; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
| use Test\TestCase; | ||
|
|
||
| class AddTest extends TestCase { | ||
|
|
||
| private IManager&MockObject $settingManager; | ||
| private AuthorizedGroupService&MockObject $authorizedGroupService; | ||
| private IGroupManager&MockObject $groupManager; | ||
| private Add $command; | ||
| private InputInterface&MockObject $input; | ||
| private OutputInterface&MockObject $output; | ||
|
|
||
| protected function setUp(): void { | ||
| parent::setUp(); | ||
|
|
||
| $this->settingManager = $this->createMock(IManager::class); | ||
| $this->authorizedGroupService = $this->createMock(AuthorizedGroupService::class); | ||
| $this->groupManager = $this->createMock(IGroupManager::class); | ||
|
|
||
| $this->command = new Add( | ||
| $this->settingManager, | ||
| $this->authorizedGroupService, | ||
| $this->groupManager | ||
| ); | ||
|
|
||
| $this->input = $this->createMock(InputInterface::class); | ||
| $this->output = $this->createMock(OutputInterface::class); | ||
| } | ||
|
|
||
| /** | ||
| * Helper method to execute the command using reflection since execute() is protected | ||
| */ | ||
| private function executeCommand(): int { | ||
| $reflection = new \ReflectionClass($this->command); | ||
| $method = $reflection->getMethod('execute'); | ||
| $method->setAccessible(true); | ||
| return $method->invokeArgs($this->command, [$this->input, $this->output]); | ||
| } | ||
|
|
||
| public function testExecuteSuccessfulDelegation(): void { | ||
| $settingClass = 'OCA\\Settings\\Settings\\Admin\\Server'; | ||
| $groupId = 'testgroup'; | ||
|
|
||
| // Mock valid delegated settings class | ||
| $this->input->expects($this->exactly(2)) | ||
| ->method('getArgument') | ||
| ->willReturnMap([ | ||
| ['settingClass', $settingClass], | ||
| ['groupId', $groupId] | ||
| ]); | ||
|
|
||
| // Mock group exists | ||
| $this->groupManager->expects($this->once()) | ||
| ->method('groupExists') | ||
| ->with($groupId) | ||
| ->willReturn(true); | ||
|
|
||
| // Mock successful creation | ||
| $authorizedGroup = new AuthorizedGroup(); | ||
| $authorizedGroup->setGroupId($groupId); | ||
| $authorizedGroup->setClass($settingClass); | ||
|
|
||
| $this->authorizedGroupService->expects($this->once()) | ||
| ->method('create') | ||
| ->with($groupId, $settingClass) | ||
| ->willReturn($authorizedGroup); | ||
|
|
||
| $result = $this->executeCommand(); | ||
|
|
||
| $this->assertEquals(0, $result); | ||
| } | ||
|
|
||
| public function testExecuteHandlesDuplicateAssignment(): void { | ||
| $settingClass = 'OCA\\Settings\\Settings\\Admin\\Server'; | ||
| $groupId = 'testgroup'; | ||
|
|
||
| // Mock valid delegated settings class | ||
| $this->input->expects($this->exactly(2)) | ||
| ->method('getArgument') | ||
| ->willReturnMap([ | ||
| ['settingClass', $settingClass], | ||
| ['groupId', $groupId] | ||
| ]); | ||
|
|
||
| // Mock group exists | ||
| $this->groupManager->expects($this->once()) | ||
| ->method('groupExists') | ||
| ->with($groupId) | ||
| ->willReturn(true); | ||
|
|
||
| // Mock ConflictException when trying to create duplicate | ||
| $this->authorizedGroupService->expects($this->once()) | ||
| ->method('create') | ||
| ->with($groupId, $settingClass) | ||
| ->willThrowException(new ConflictException('Group is already assigned to this class')); | ||
|
|
||
| $result = $this->executeCommand(); | ||
|
|
||
| // Should return exit code 4 for conflict | ||
| $this->assertEquals(4, $result); | ||
| } | ||
|
|
||
| public function testExecuteInvalidSettingClass(): void { | ||
| // Use a real class that exists but doesn't implement IDelegatedSettings | ||
| $settingClass = 'stdClass'; | ||
|
|
||
| $this->input->expects($this->once()) | ||
| ->method('getArgument') | ||
| ->with('settingClass') | ||
| ->willReturn($settingClass); | ||
|
|
||
| $result = $this->executeCommand(); | ||
|
|
||
| // Should return exit code 2 for invalid setting class | ||
| $this->assertEquals(2, $result); | ||
| } | ||
|
|
||
| public function testExecuteNonExistentGroup(): void { | ||
| $settingClass = 'OCA\\Settings\\Settings\\Admin\\Server'; | ||
| $groupId = 'nonexistentgroup'; | ||
|
|
||
| $this->input->expects($this->exactly(2)) | ||
| ->method('getArgument') | ||
| ->willReturnMap([ | ||
| ['settingClass', $settingClass], | ||
| ['groupId', $groupId] | ||
| ]); | ||
|
|
||
| // Mock group does not exist | ||
| $this->groupManager->expects($this->once()) | ||
| ->method('groupExists') | ||
| ->with($groupId) | ||
| ->willReturn(false); | ||
|
|
||
| $result = $this->executeCommand(); | ||
|
|
||
| // Should return exit code 3 for non-existent group | ||
| $this->assertEquals(3, $result); | ||
| } | ||
|
|
||
| public function testExecuteReturnsDifferentExitCodesForDifferentErrors(): void { | ||
| // Test that duplicate assignment returns code 4 | ||
| $settingClass = 'OCA\\Settings\\Settings\\Admin\\Server'; | ||
| $groupId = 'testgroup'; | ||
|
|
||
| $this->input->expects($this->exactly(2)) | ||
| ->method('getArgument') | ||
| ->willReturnMap([ | ||
| ['settingClass', $settingClass], | ||
| ['groupId', $groupId] | ||
| ]); | ||
|
|
||
| $this->groupManager->expects($this->once()) | ||
| ->method('groupExists') | ||
| ->with($groupId) | ||
| ->willReturn(true); | ||
|
|
||
| $this->authorizedGroupService->expects($this->once()) | ||
| ->method('create') | ||
| ->with($groupId, $settingClass) | ||
| ->willThrowException(new ConflictException('Group is already assigned to this class')); | ||
|
|
||
| $result = $this->executeCommand(); | ||
|
|
||
| $this->assertEquals(4, $result, 'Duplicate assignment should return exit code 4'); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.