diff --git a/lib/Controller/KeyController.php b/lib/Controller/KeyController.php index 2ac65af6..8ee3a696 100644 --- a/lib/Controller/KeyController.php +++ b/lib/Controller/KeyController.php @@ -13,6 +13,7 @@ use OCA\EndToEndEncryption\IKeyStorage; use OCA\EndToEndEncryption\SignatureHandler; use OCP\AppFramework\Http; +use OCP\AppFramework\Http\Attribute\AnonRateLimit; use OCP\AppFramework\Http\Attribute\BruteForceProtection; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCS\OCSBadRequestException; @@ -140,11 +141,11 @@ public function setPrivateKey(string $privateKey): DataResponse { * @NoAdminRequired * @E2ERestrictUserAgent * @param string $users a json encoded list of users - * @return DataResponse}, array{}> + * @return DataResponse}, array{}>|DataResponse * @throws OCSBadRequestException Internal error - * @throws OCSNotFoundException Public key not found * * 200: Public keys returned + * 404: Public key for at least one user not found */ public function getPublicKeys(string $users = ''): DataResponse { $usersArray = $this->jsonDecode($users); @@ -155,7 +156,8 @@ public function getPublicKeys(string $users = ''): DataResponse { $publicKey = $this->keyStorage->getPublicKey($uid); $result['public-keys'][$uid] = $publicKey; } catch (NotFoundException $e) { - throw new OCSNotFoundException($this->l10n->t('Could not find the public key belonging to the user %s', [$uid])); + $this->logger->debug('Could not find the public key of the user: ' . $uid, ['exception' => $e]); + return $this->throttleRequest(Http::STATUS_NOT_FOUND, 'Could not find the public key belonging to the user ' . $uid); } catch (Exception $e) { $this->logger->critical($e->getMessage(), ['exception' => $e, 'app' => $this->appName]); throw new OCSBadRequestException($this->l10n->t('Internal error')); diff --git a/openapi.json b/openapi.json index 22452160..aadfa215 100644 --- a/openapi.json +++ b/openapi.json @@ -1053,8 +1053,8 @@ } } }, - "400": { - "description": "Internal error", + "404": { + "description": "Public key for at least one user not found", "content": { "application/json": { "schema": { @@ -1073,7 +1073,17 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": {} + "data": { + "type": "object", + "required": [ + "message" + ], + "properties": { + "message": { + "type": "string" + } + } + } } } } @@ -1081,8 +1091,8 @@ } } }, - "404": { - "description": "Public key not found", + "400": { + "description": "Internal error", "content": { "application/json": { "schema": { diff --git a/tests/Unit/Controller/KeyControllerTest.php b/tests/Unit/Controller/KeyControllerTest.php index f2a4c967..06418bb8 100644 --- a/tests/Unit/Controller/KeyControllerTest.php +++ b/tests/Unit/Controller/KeyControllerTest.php @@ -336,10 +336,9 @@ public function testGetPublicKeysNotFoundException(): void { return vsprintf($string, $args); }); - $this->expectException(OCSNotFoundException::class); - $this->expectExceptionMessage('Could not find the public key belonging to the user user1'); - - $this->controller->getPublicKeys($users); + $response = $this->controller->getPublicKeys($users); + self::assertEquals($response->getStatus(), 404); + self::assertEquals($response->getData(), ['message' => 'Could not find the public key belonging to the user user1']); } public function testGetPublicKeysGenericException(): void {