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
2 changes: 1 addition & 1 deletion lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1875,7 +1875,7 @@ private function storeAnswersForQuestion(Form $form, $submissionId, array $quest
*/
private function checkForbiddenKeys(array $keyValuePairs): void {
$forbiddenKeys = [
'id', 'hash', 'ownerId', 'created', 'lastUpdated', 'lockedBy', 'lockedUntil'
'id', 'hash', 'ownerId', 'created', 'lastUpdated', 'lockedBy', 'lockedUntil', 'accessEnum'
];
foreach ($forbiddenKeys as $key) {
if (array_key_exists($key, $keyValuePairs)) {
Expand Down
18 changes: 18 additions & 0 deletions tests/Integration/Api/ApiV3Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,24 @@ public function testUpdateFormProperties(array $expected): void {
$this->testGetFullForm($expected);
}

public function testUpdateFormRejectsForbiddenKeys(): void {
$before = $this->OcsResponse2Data($this->http->request('GET', "api/v3/forms/{$this->testForms[0]['id']}"));

$resp = $this->http->request('PATCH', "api/v3/forms/{$this->testForms[0]['id']}", [
'json' => [
'keyValuePairs' => [
'id' => 999,
],
],
'http_errors' => false,
]);

$this->assertEquals(403, $resp->getStatusCode());

$after = $this->OcsResponse2Data($this->http->request('GET', "api/v3/forms/{$this->testForms[0]['id']}"));
$this->assertEquals($before, $after);
}

public function testDeleteForm() {
$resp = $this->http->request('DELETE', "api/v3/forms/{$this->testForms[0]['id']}");
$data = $this->OcsResponse2Data($resp);
Expand Down
32 changes: 32 additions & 0 deletions tests/Unit/Controller/ApiControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,38 @@ public function testUpdateFormAllowsValidConfirmationEmailQuestionId(): void {
$this->assertSame(7, $form->getConfirmationEmailQuestionId());
}

public static function dataUpdateFormRejectsForbiddenKeys(): array {
return [
'id' => [['id' => 2]],
'hash' => [['hash' => 'new-hash']],
'created' => [['created' => 123456]],
'lastUpdated' => [['lastUpdated' => 123456]],
'lockedBy' => [['lockedBy' => 'anotherUser']],
'lockedUntil' => [['lockedUntil' => 123456]],
'accessEnum' => [['accessEnum' => 2]],
];
}

/**
* @dataProvider dataUpdateFormRejectsForbiddenKeys
*/
public function testUpdateFormRejectsForbiddenKeys(array $keyValuePairs): void {
$form = new Form();
$form->setId(1);
$form->setOwnerId('currentUser');
$form->setHash('hash');

$this->formsService
->method('getFormIfAllowed')
->with(1, Constants::PERMISSION_EDIT)
->willReturn($form);

$this->formMapper->expects($this->never())->method('update');

$this->expectException(OCSForbiddenException::class);
$this->apiController->updateForm(1, $keyValuePairs);
}

public static function dataUpdateFormRejectsInvalidConfirmationEmailQuestionId(): array {
return [
'invalid-question-id' => ['Invalid question ID'],
Expand Down
Loading