Skip to content

Commit c28f042

Browse files
Merge pull request #8191 from nextcloud/backport/8190/stable34
[stable34] fix: validate board permission in setDoneStack method
2 parents c2b50ef + 5d1843e commit c28f042

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

lib/Service/StackService.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,11 @@ public function reorder(int $id, int $order): array {
307307
*/
308308
public function setDoneStack(int $stackId, int $boardId, bool $isDone): void {
309309
$this->permissionService->checkPermission($this->stackMapper, $stackId, Acl::PERMISSION_MANAGE);
310+
$stack = $this->stackMapper->find($stackId);
311+
312+
if ($stack->getBoardId() !== $boardId) {
313+
throw new BadRequestException('Stack does not belong to the specified board.');
314+
}
310315

311316
if ($this->boardService->isArchived($this->stackMapper, $stackId)) {
312317
throw new NoPermissionException('Operation not allowed. This board is archived.');

tests/unit/Service/StackServiceTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ private function createStack(int $id, int $order) {
276276

277277
public function testSetDoneStackSetsDoneColumn(): void {
278278
$this->permissionService->expects($this->once())->method('checkPermission');
279+
$this->stackMapper->expects($this->once())
280+
->method('find')
281+
->with(5)
282+
->willReturn($this->createStack(5, 0));
279283
$this->boardService->expects($this->once())->method('isArchived')->willReturn(false);
280284
$this->stackMapper->expects($this->once())
281285
->method('clearDoneColumnForBoard')
@@ -303,6 +307,10 @@ public function testSetDoneStackSetsDoneColumn(): void {
303307
public function testSetDoneStackDoesNotMarkCardsWhenUnsetting(): void {
304308
$this->permissionService->expects($this->once())->method('checkPermission');
305309
$this->boardService->expects($this->once())->method('isArchived')->willReturn(false);
310+
$this->stackMapper->expects($this->once())
311+
->method('find')
312+
->with(5)
313+
->willReturn($this->createStack(5, 0));
306314
$this->stackMapper->expects($this->never())->method('clearDoneColumnForBoard');
307315
$this->cardMapper->expects($this->never())->method('findAll');
308316
$this->cardMapper->expects($this->never())->method('update');
@@ -314,9 +322,24 @@ public function testSetDoneStackDoesNotMarkCardsWhenUnsetting(): void {
314322

315323
public function testSetDoneStackThrowsOnArchivedBoard(): void {
316324
$this->permissionService->expects($this->once())->method('checkPermission');
325+
$this->stackMapper->expects($this->once())
326+
->method('find')
327+
->with(5)
328+
->willReturn($this->createStack(5, 0));
317329
$this->boardService->expects($this->once())->method('isArchived')->willReturn(true);
318330
$this->stackMapper->expects($this->never())->method('setIsDoneColumn');
319331
$this->expectException(\OCA\Deck\NoPermissionException::class);
320332
$this->stackService->setDoneStack(5, 1, true);
321333
}
334+
335+
public function testSetDoneStackThrowsOnMismatchBoardId(): void {
336+
$this->permissionService->expects($this->once())->method('checkPermission');
337+
$this->stackMapper->expects($this->once())
338+
->method('find')
339+
->with(5)
340+
->willReturn($this->createStack(5, 0));
341+
$this->stackMapper->expects($this->never())->method('setIsDoneColumn');
342+
$this->expectException(\OCA\Deck\BadRequestException::class);
343+
$this->stackService->setDoneStack(5, 2, true);
344+
}
322345
}

0 commit comments

Comments
 (0)