Skip to content
Draft
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
8 changes: 5 additions & 3 deletions lib/Controller/KeyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -140,11 +141,11 @@ public function setPrivateKey(string $privateKey): DataResponse {
* @NoAdminRequired
* @E2ERestrictUserAgent
* @param string $users a json encoded list of users
* @return DataResponse<Http::STATUS_OK, array{public-keys: array<string, string>}, array{}>
* @return DataResponse<Http::STATUS_OK, array{public-keys: array<string, string>}, array{}>|DataResponse<Http::STATUS_NOT_FOUND, array{message: string}, array{}>
* @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);
Expand All @@ -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'));
Expand Down
20 changes: 15 additions & 5 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1053,8 +1053,8 @@
}
}
},
"400": {
"description": "Internal error",
"404": {
"description": "Public key for at least one user not found",
"content": {
"application/json": {
"schema": {
Expand All @@ -1073,16 +1073,26 @@
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {}
"data": {
"type": "object",
"required": [
"message"
],
"properties": {
"message": {
"type": "string"
}
}
}
}
}
}
}
}
}
},
"404": {
"description": "Public key not found",
"400": {
"description": "Internal error",
"content": {
"application/json": {
"schema": {
Expand Down
7 changes: 3 additions & 4 deletions tests/Unit/Controller/KeyControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down