From 4d08a6bbdd8926bf3c8a11a83d2348dfd440c842 Mon Sep 17 00:00:00 2001 From: Alex Snaps Date: Wed, 13 Nov 2024 10:08:43 -0500 Subject: [PATCH] Adds a test to validate generated CEL works Signed-off-by: Alex Snaps --- src/data/cel.rs | 19 +++++++++++++++++++ src/data/property.rs | 5 ++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/data/cel.rs b/src/data/cel.rs index 68fe295..844c726 100644 --- a/src/data/cel.rs +++ b/src/data/cel.rs @@ -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¶m2=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(( diff --git a/src/data/property.rs b/src/data/property.rs index 06ad798..4bbb91c 100644 --- a/src/data/property.rs +++ b/src/data/property.rs @@ -47,7 +47,10 @@ pub(super) fn host_get_property(path: &Path) -> Result>, Status> #[cfg(test)] pub fn host_get_map(path: &Path) -> Result, 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)), } }