Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c690c4f

Browse files
committed
Added and modified the current API Key and Tenant Token tests
1 parent 7b4b57e commit c690c4f

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

meilisearch/tests/auth/tenant_token.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ static ACCEPTED_KEYS: Lazy<Vec<Value>> = Lazy::new(|| {
8282
"actions": ["search"],
8383
"expiresAt": (OffsetDateTime::now_utc() + Duration::days(1)).format(&Rfc3339).unwrap()
8484
}),
85+
json!({
86+
"indexes": ["sal*", "prod*"],
87+
"actions": ["search"],
88+
"expiresAt": (OffsetDateTime::now_utc() + Duration::days(1)).format(&Rfc3339).unwrap()
89+
}),
8590
]
8691
});
8792

@@ -104,6 +109,11 @@ static REFUSED_KEYS: Lazy<Vec<Value>> = Lazy::new(|| {
104109
"actions": ["*"],
105110
"expiresAt": (OffsetDateTime::now_utc() + Duration::days(1)).format(&Rfc3339).unwrap()
106111
}),
112+
json!({
113+
"indexes": ["prod*", "p*"],
114+
"actions": ["*"],
115+
"expiresAt": (OffsetDateTime::now_utc() + Duration::days(1)).format(&Rfc3339).unwrap()
116+
}),
107117
json!({
108118
"indexes": ["products"],
109119
"actions": ["search"],
@@ -245,6 +255,10 @@ async fn search_authorized_simple_token() {
245255
"searchRules" => json!(["sales"]),
246256
"exp" => Value::Null
247257
},
258+
hashmap! {
259+
"searchRules" => json!(["sa*"]),
260+
"exp" => Value::Null
261+
},
248262
];
249263

250264
compute_authorized_search!(tenant_tokens, {}, 5);
@@ -351,11 +365,19 @@ async fn filter_search_authorized_filter_token() {
351365
}),
352366
"exp" => json!((OffsetDateTime::now_utc() + Duration::hours(1)).unix_timestamp())
353367
},
368+
hashmap! {
369+
"searchRules" => json!({
370+
"*": {},
371+
"sal*": {"filter": ["color = blue"]}
372+
}),
373+
"exp" => json!((OffsetDateTime::now_utc() + Duration::hours(1)).unix_timestamp())
374+
},
354375
];
355376

356377
compute_authorized_search!(tenant_tokens, "color = yellow", 1);
357378
}
358379

380+
/// Tests that those Tenant Token are incompatible with the REFUSED_KEYS defined above.
359381
#[actix_rt::test]
360382
async fn error_search_token_forbidden_parent_key() {
361383
let tenant_tokens = vec![
@@ -383,6 +405,10 @@ async fn error_search_token_forbidden_parent_key() {
383405
"searchRules" => json!(["sales"]),
384406
"exp" => json!((OffsetDateTime::now_utc() + Duration::hours(1)).unix_timestamp())
385407
},
408+
hashmap! {
409+
"searchRules" => json!(["sali*", "s*", "sales*"]),
410+
"exp" => json!((OffsetDateTime::now_utc() + Duration::hours(1)).unix_timestamp())
411+
},
386412
];
387413

388414
compute_forbidden_search!(tenant_tokens, REFUSED_KEYS);

0 commit comments

Comments
 (0)