mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 20:15:07 +08:00
Bug(auth): Wrap key list in results
This commit is contained in:
parent
c0251eb680
commit
c0d4f71a34
@ -2,7 +2,7 @@ use std::str;
|
|||||||
|
|
||||||
use actix_web::{web, HttpRequest, HttpResponse};
|
use actix_web::{web, HttpRequest, HttpResponse};
|
||||||
use chrono::SecondsFormat;
|
use chrono::SecondsFormat;
|
||||||
use log::debug;
|
|
||||||
use meilisearch_auth::{generate_key, Action, AuthController, Key};
|
use meilisearch_auth::{generate_key, Action, AuthController, Key};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::Value;
|
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 key = auth_controller.create_key(body.into_inner()).await?;
|
||||||
let res = KeyView::from_key(key, auth_controller.get_master_key());
|
let res = KeyView::from_key(key, auth_controller.get_master_key());
|
||||||
|
|
||||||
debug!("returns: {:?}", res);
|
|
||||||
Ok(HttpResponse::Created().json(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()))
|
.map(|k| KeyView::from_key(k, auth_controller.get_master_key()))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
debug!("returns: {:?}", res);
|
Ok(HttpResponse::Ok().json(KeyListView::from(res)))
|
||||||
Ok(HttpResponse::Ok().json(res))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_api_key(
|
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 key = auth_controller.get_key(&path.api_key).await?;
|
||||||
let res = KeyView::from_key(key, auth_controller.get_master_key());
|
let res = KeyView::from_key(key, auth_controller.get_master_key());
|
||||||
|
|
||||||
debug!("returns: {:?}", res);
|
|
||||||
Ok(HttpResponse::Ok().json(res))
|
Ok(HttpResponse::Ok().json(res))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +70,6 @@ pub async fn patch_api_key(
|
|||||||
.await?;
|
.await?;
|
||||||
let res = KeyView::from_key(key, auth_controller.get_master_key());
|
let res = KeyView::from_key(key, auth_controller.get_master_key());
|
||||||
|
|
||||||
debug!("returns: {:?}", res);
|
|
||||||
Ok(HttpResponse::Ok().json(res))
|
Ok(HttpResponse::Ok().json(res))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,3 +121,14 @@ impl KeyView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
struct KeyListView {
|
||||||
|
results: Vec<KeyView>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Vec<KeyView>> for KeyListView {
|
||||||
|
fn from(results: Vec<KeyView>) -> Self {
|
||||||
|
Self { results }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -571,40 +571,42 @@ async fn list_api_keys() {
|
|||||||
|
|
||||||
let (response, code) = server.list_api_keys().await;
|
let (response, code) = server.list_api_keys().await;
|
||||||
|
|
||||||
let expected_response = json!([
|
let expected_response = json!({ "results":
|
||||||
{
|
[
|
||||||
"description": "Indexing API key",
|
{
|
||||||
"indexes": ["products"],
|
"description": "Indexing API key",
|
||||||
"actions": [
|
"indexes": ["products"],
|
||||||
"search",
|
"actions": [
|
||||||
"documents.add",
|
"search",
|
||||||
"documents.get",
|
"documents.add",
|
||||||
"documents.delete",
|
"documents.get",
|
||||||
"indexes.create",
|
"documents.delete",
|
||||||
"indexes.get",
|
"indexes.create",
|
||||||
"indexes.update",
|
"indexes.get",
|
||||||
"indexes.delete",
|
"indexes.update",
|
||||||
"tasks.get",
|
"indexes.delete",
|
||||||
"settings.get",
|
"tasks.get",
|
||||||
"settings.update",
|
"settings.get",
|
||||||
"stats.get",
|
"settings.update",
|
||||||
"dumps.create",
|
"stats.get",
|
||||||
"dumps.get"
|
"dumps.create",
|
||||||
],
|
"dumps.get"
|
||||||
"expiresAt": "2050-11-13T00:00:00Z"
|
],
|
||||||
},
|
"expiresAt": "2050-11-13T00:00:00Z"
|
||||||
{
|
},
|
||||||
"description": "Default Search API Key (Use it to search from the frontend)",
|
{
|
||||||
"indexes": ["*"],
|
"description": "Default Search API Key (Use it to search from the frontend)",
|
||||||
"actions": ["search"],
|
"indexes": ["*"],
|
||||||
"expiresAt": serde_json::Value::Null,
|
"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": ["*"],
|
"description": "Default Admin API Key (Use it for all other operations. Caution! Do not use it on a public frontend)",
|
||||||
"actions": ["*"],
|
"indexes": ["*"],
|
||||||
"expiresAt": serde_json::Value::Null,
|
"actions": ["*"],
|
||||||
}]);
|
"expiresAt": serde_json::Value::Null,
|
||||||
|
}
|
||||||
|
]});
|
||||||
|
|
||||||
assert_json_include!(actual: response, expected: expected_response);
|
assert_json_include!(actual: response, expected: expected_response);
|
||||||
assert_eq!(code, 200);
|
assert_eq!(code, 200);
|
||||||
|
Loading…
Reference in New Issue
Block a user