From c0d4f71a34736f451054c8c01e8e0899c42c4ce6 Mon Sep 17 00:00:00 2001 From: ManyTheFish Date: Tue, 4 Jan 2022 14:10:30 +0100 Subject: [PATCH] Bug(auth): Wrap key list in results --- meilisearch-http/src/routes/api_key.rs | 19 ++++--- meilisearch-http/tests/auth/api_keys.rs | 70 +++++++++++++------------ 2 files changed, 49 insertions(+), 40 deletions(-) diff --git a/meilisearch-http/src/routes/api_key.rs b/meilisearch-http/src/routes/api_key.rs index a64a17207..6d08dee71 100644 --- a/meilisearch-http/src/routes/api_key.rs +++ b/meilisearch-http/src/routes/api_key.rs @@ -2,7 +2,7 @@ use std::str; use actix_web::{web, HttpRequest, HttpResponse}; use chrono::SecondsFormat; -use log::debug; + use meilisearch_auth::{generate_key, Action, AuthController, Key}; use serde::{Deserialize, Serialize}; use serde_json::Value; @@ -32,7 +32,6 @@ pub async fn create_api_key( let key = auth_controller.create_key(body.into_inner()).await?; let res = KeyView::from_key(key, auth_controller.get_master_key()); - debug!("returns: {:?}", res); Ok(HttpResponse::Created().json(res)) } @@ -46,8 +45,7 @@ pub async fn list_api_keys( .map(|k| KeyView::from_key(k, auth_controller.get_master_key())) .collect(); - debug!("returns: {:?}", res); - Ok(HttpResponse::Ok().json(res)) + Ok(HttpResponse::Ok().json(KeyListView::from(res))) } pub async fn get_api_key( @@ -58,7 +56,6 @@ pub async fn get_api_key( let key = auth_controller.get_key(&path.api_key).await?; let res = KeyView::from_key(key, auth_controller.get_master_key()); - debug!("returns: {:?}", res); Ok(HttpResponse::Ok().json(res)) } @@ -73,7 +70,6 @@ pub async fn patch_api_key( .await?; let res = KeyView::from_key(key, auth_controller.get_master_key()); - debug!("returns: {:?}", res); Ok(HttpResponse::Ok().json(res)) } @@ -125,3 +121,14 @@ impl KeyView { } } } + +#[derive(Debug, Serialize)] +struct KeyListView { + results: Vec, +} + +impl From> for KeyListView { + fn from(results: Vec) -> Self { + Self { results } + } +} diff --git a/meilisearch-http/tests/auth/api_keys.rs b/meilisearch-http/tests/auth/api_keys.rs index ebbdf8378..fbe107837 100644 --- a/meilisearch-http/tests/auth/api_keys.rs +++ b/meilisearch-http/tests/auth/api_keys.rs @@ -571,40 +571,42 @@ async fn list_api_keys() { let (response, code) = server.list_api_keys().await; - let expected_response = json!([ - { - "description": "Indexing API key", - "indexes": ["products"], - "actions": [ - "search", - "documents.add", - "documents.get", - "documents.delete", - "indexes.create", - "indexes.get", - "indexes.update", - "indexes.delete", - "tasks.get", - "settings.get", - "settings.update", - "stats.get", - "dumps.create", - "dumps.get" - ], - "expiresAt": "2050-11-13T00:00:00Z" - }, - { - "description": "Default Search API Key (Use it to search from the frontend)", - "indexes": ["*"], - "actions": ["search"], - "expiresAt": serde_json::Value::Null, - }, - { - "description": "Default Admin API Key (Use it for all other operations. Caution! Do not use it on a public frontend)", - "indexes": ["*"], - "actions": ["*"], - "expiresAt": serde_json::Value::Null, - }]); + let expected_response = json!({ "results": + [ + { + "description": "Indexing API key", + "indexes": ["products"], + "actions": [ + "search", + "documents.add", + "documents.get", + "documents.delete", + "indexes.create", + "indexes.get", + "indexes.update", + "indexes.delete", + "tasks.get", + "settings.get", + "settings.update", + "stats.get", + "dumps.create", + "dumps.get" + ], + "expiresAt": "2050-11-13T00:00:00Z" + }, + { + "description": "Default Search API Key (Use it to search from the frontend)", + "indexes": ["*"], + "actions": ["search"], + "expiresAt": serde_json::Value::Null, + }, + { + "description": "Default Admin API Key (Use it for all other operations. Caution! Do not use it on a public frontend)", + "indexes": ["*"], + "actions": ["*"], + "expiresAt": serde_json::Value::Null, + } + ]}); assert_json_include!(actual: response, expected: expected_response); assert_eq!(code, 200);