mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 14:54:27 +01:00
bug(auth): Make API keys accept Null descriptions
This commit is contained in:
parent
622c15e825
commit
3bee31e6c7
@ -20,13 +20,14 @@ pub struct Key {
|
|||||||
|
|
||||||
impl Key {
|
impl Key {
|
||||||
pub fn create_from_value(value: Value) -> Result<Self> {
|
pub fn create_from_value(value: Value) -> Result<Self> {
|
||||||
let description = value
|
let description = match value.get("description") {
|
||||||
.get("description")
|
Some(Value::Null) => None,
|
||||||
.map(|des| {
|
Some(des) => Some(
|
||||||
from_value(des.clone())
|
from_value(des.clone())
|
||||||
.map_err(|_| AuthControllerError::InvalidApiKeyDescription(des.clone()))
|
.map_err(|_| AuthControllerError::InvalidApiKeyDescription(des.clone()))?,
|
||||||
})
|
),
|
||||||
.transpose()?;
|
None => None,
|
||||||
|
};
|
||||||
|
|
||||||
let id = generate_id();
|
let id = generate_id();
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::common::Server;
|
use crate::common::Server;
|
||||||
use assert_json_diff::assert_json_include;
|
use assert_json_diff::assert_json_include;
|
||||||
use serde_json::json;
|
use serde_json::{json, Value};
|
||||||
use std::{thread, time};
|
use std::{thread, time};
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
@ -155,6 +155,41 @@ async fn add_valid_api_key_no_description() {
|
|||||||
assert_eq!(code, 201);
|
assert_eq!(code, 201);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn add_valid_api_key_null_description() {
|
||||||
|
let mut server = Server::new_auth().await;
|
||||||
|
server.use_api_key("MASTER_KEY");
|
||||||
|
|
||||||
|
let content = json!({
|
||||||
|
"description": Value::Null,
|
||||||
|
"indexes": ["products"],
|
||||||
|
"actions": [
|
||||||
|
"documents.add"
|
||||||
|
],
|
||||||
|
"expiresAt": "2050-11-13T00:00:00"
|
||||||
|
});
|
||||||
|
|
||||||
|
let (response, code) = server.add_api_key(content).await;
|
||||||
|
|
||||||
|
assert!(response["key"].is_string());
|
||||||
|
assert!(response["expiresAt"].is_string());
|
||||||
|
assert!(response["createdAt"].is_string());
|
||||||
|
assert!(response["updatedAt"].is_string());
|
||||||
|
|
||||||
|
let expected_response = json!({
|
||||||
|
"actions": [
|
||||||
|
"documents.add"
|
||||||
|
],
|
||||||
|
"indexes": [
|
||||||
|
"products"
|
||||||
|
],
|
||||||
|
"expiresAt": "2050-11-13T00:00:00Z"
|
||||||
|
});
|
||||||
|
|
||||||
|
assert_json_include!(actual: response, expected: expected_response);
|
||||||
|
assert_eq!(code, 201);
|
||||||
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn error_add_api_key_no_header() {
|
async fn error_add_api_key_no_header() {
|
||||||
let server = Server::new_auth().await;
|
let server = Server::new_auth().await;
|
||||||
|
Loading…
Reference in New Issue
Block a user