Skip to content

Commit

Permalink
Merge pull request #146 from Kuadrant/cel_generated
Browse files Browse the repository at this point in the history
Adds a test to validate generated CEL works
  • Loading branch information
alexsnaps authored Nov 14, 2024
2 parents 3c8fc45 + 4d08a6b commit e88f73e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/data/cel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,25 @@ mod tests {
assert!(predicate.test().expect("This must evaluate properly!"));
}

#[test]
fn kuadrant_generated_predicates() {
property::test::TEST_PROPERTY_VALUE.set(Some((
"request.query".into(),
"param1=%F0%9F%91%BE%20&param2=Exterminate%21&%F0%9F%91%BE=123&%F0%9F%91%BE=456&%F0%9F%91%BE"
.bytes()
.collect(),
)));
let predicate = Predicate::route_rule(
"'👾' in queryMap(request.query) ? queryMap(request.query)['👾'] == '123' : false",
)
.expect("This is valid!");
assert_eq!(predicate.test(), Ok(true));

let predicate =
Predicate::route_rule("request.headers.exists(h, h.lowerAscii() == 'x-auth' && request.headers[h] == 'kuadrant')").expect("This is valid!");
assert_eq!(predicate.test(), Ok(true));
}

#[test]
fn attribute_resolve() {
property::test::TEST_PROPERTY_VALUE.set(Some((
Expand Down
5 changes: 4 additions & 1 deletion src/data/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ pub(super) fn host_get_property(path: &Path) -> Result<Option<Vec<u8>>, Status>
#[cfg(test)]
pub fn host_get_map(path: &Path) -> Result<HashMap<String, String>, String> {
match *path.tokens() {
["request", "headers"] => Ok(HashMap::default()),
["request", "headers"] => Ok(HashMap::from([(
"X-Auth".to_string(),
"kuadrant".to_string(),
)])),
_ => Err(format!("Unknown map requested {:?}", path)),
}
}
Expand Down

0 comments on commit e88f73e

Please sign in to comment.