Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/Service/ShareService.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ public function create(ShareCreate $dto): Share {
* @param string $receiverType
*
* @throws InternalError
* @throws PermissionError
*
* @return Share
*/
Expand All @@ -290,6 +291,14 @@ private function buildBaseShare(
$this->logger->error($e->getMessage(), ['exception' => $e]);
throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage());
}
$allowedReceiverTypes = [
ShareReceiverType::USER,
ShareReceiverType::GROUP,
ShareReceiverType::CIRCLE,
];
if (!in_array($receiverType, $allowedReceiverTypes, true)) {
throw new PermissionError('Invalid share receiver type.');
}
if ($receiverType === ShareReceiverType::GROUP && !$this->shareManager->allowGroupSharing()) {
throw new PermissionError('Group sharing is disabled by your administrator.');
}
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/Service/ShareServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,26 @@ public function testUpdatePermissionThrowsOnContextShare(): void {
$this->expectException(PermissionError::class);
$this->shareService->updatePermission(1, 'manage', true);
}

public function testCreateThrowsForUnsupportedReceiverType(): void {
$this->mapper->expects($this->never())->method('insert');

$this->expectException(PermissionError::class);
$this->expectExceptionMessage('Invalid share receiver type.');

$this->shareService->create(
new ShareCreate(
1,
'table',
'',
'link',
true,
false,
false,
false,
false,
0,
)
);
}
}
Loading