From c690c4fec4f7eda2f32037aaa1ac2c038e4d8fb4 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Wed, 8 Feb 2023 18:19:51 +0100 Subject: [PATCH] Added and modified the current API Key and Tenant Token tests --- meilisearch/tests/auth/tenant_token.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/meilisearch/tests/auth/tenant_token.rs b/meilisearch/tests/auth/tenant_token.rs index af3e7c2a5..81e161b5a 100644 --- a/meilisearch/tests/auth/tenant_token.rs +++ b/meilisearch/tests/auth/tenant_token.rs @@ -82,6 +82,11 @@ static ACCEPTED_KEYS: Lazy> = Lazy::new(|| { "actions": ["search"], "expiresAt": (OffsetDateTime::now_utc() + Duration::days(1)).format(&Rfc3339).unwrap() }), + json!({ + "indexes": ["sal*", "prod*"], + "actions": ["search"], + "expiresAt": (OffsetDateTime::now_utc() + Duration::days(1)).format(&Rfc3339).unwrap() + }), ] }); @@ -104,6 +109,11 @@ static REFUSED_KEYS: Lazy> = Lazy::new(|| { "actions": ["*"], "expiresAt": (OffsetDateTime::now_utc() + Duration::days(1)).format(&Rfc3339).unwrap() }), + json!({ + "indexes": ["prod*", "p*"], + "actions": ["*"], + "expiresAt": (OffsetDateTime::now_utc() + Duration::days(1)).format(&Rfc3339).unwrap() + }), json!({ "indexes": ["products"], "actions": ["search"], @@ -245,6 +255,10 @@ async fn search_authorized_simple_token() { "searchRules" => json!(["sales"]), "exp" => Value::Null }, + hashmap! { + "searchRules" => json!(["sa*"]), + "exp" => Value::Null + }, ]; compute_authorized_search!(tenant_tokens, {}, 5); @@ -351,11 +365,19 @@ async fn filter_search_authorized_filter_token() { }), "exp" => json!((OffsetDateTime::now_utc() + Duration::hours(1)).unix_timestamp()) }, + hashmap! { + "searchRules" => json!({ + "*": {}, + "sal*": {"filter": ["color = blue"]} + }), + "exp" => json!((OffsetDateTime::now_utc() + Duration::hours(1)).unix_timestamp()) + }, ]; compute_authorized_search!(tenant_tokens, "color = yellow", 1); } +/// Tests that those Tenant Token are incompatible with the REFUSED_KEYS defined above. #[actix_rt::test] async fn error_search_token_forbidden_parent_key() { let tenant_tokens = vec![ @@ -383,6 +405,10 @@ async fn error_search_token_forbidden_parent_key() { "searchRules" => json!(["sales"]), "exp" => json!((OffsetDateTime::now_utc() + Duration::hours(1)).unix_timestamp()) }, + hashmap! { + "searchRules" => json!(["sali*", "s*", "sales*"]), + "exp" => json!((OffsetDateTime::now_utc() + Duration::hours(1)).unix_timestamp()) + }, ]; compute_forbidden_search!(tenant_tokens, REFUSED_KEYS);