-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CEL Interperter for Conditions #354
Closed
Closed
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9801078
Quick and dirty CEL support
alexsnaps 5007c15
Bring back the original simple parsing, and only enable cel expressio…
chirino c063001
Don’t change the simple key encoding so that redis keys don’t change.
chirino c8ad128
Drop dead code, and cargo fmt.
chirino d42e6d2
Add feature cel_conditions feature flag.
chirino ff6d4ce
Fix clippy warnings.
chirino 954485f
Add more cel tests, handle cases where the var variable name conflict…
chirino bb0278e
Use an assert_false! Macro for better test readability
chirino 4f70031
cel: reserve _* identifiers for future internal use like adding
chirino 4ab013f
Pickup updates cel 0.7.0 (patched) version.
chirino 93795b1
Improve assert_false! Macro.
chirino 45958e0
Show an alternative way to access the cel variable.
chirino File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -886,6 +886,14 @@ mod conditions { | |
mod tests { | ||
use super::*; | ||
|
||
macro_rules! assert_false { | ||
($cond:expr $(,)?) => { | ||
paste::item! { | ||
assert!(!$cond) | ||
} | ||
}; | ||
} | ||
|
||
#[test] | ||
fn limit_can_have_an_optional_name() { | ||
let mut limit = Limit::new("test_namespace", 10, 60, vec!["x == \"5\""], vec!["y"]); | ||
|
@@ -915,7 +923,7 @@ mod tests { | |
values.insert("x".into(), "1".into()); | ||
values.insert("y".into(), "1".into()); | ||
|
||
assert!(!limit.applies(&values)) | ||
assert_false!(limit.applies(&values)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎉 ...
with the change above it'd be, I think clearer:
where now |
||
} | ||
|
||
#[test] | ||
|
@@ -927,9 +935,9 @@ mod tests { | |
values.insert("x".into(), "1".into()); | ||
values.insert("y".into(), "1".into()); | ||
|
||
assert!(!limit.applies(&values)); | ||
assert_false!(limit.applies(&values)); | ||
assert!(check_deprecated_syntax_usages_and_reset()); | ||
assert!(!check_deprecated_syntax_usages_and_reset()); | ||
assert_false!(check_deprecated_syntax_usages_and_reset()); | ||
|
||
let limit = Limit::new("test_namespace", 10, 60, vec!["x == foobar"], vec!["y"]); | ||
|
||
|
@@ -939,7 +947,7 @@ mod tests { | |
|
||
assert!(limit.applies(&values)); | ||
assert!(check_deprecated_syntax_usages_and_reset()); | ||
assert!(!check_deprecated_syntax_usages_and_reset()); | ||
assert_false!(check_deprecated_syntax_usages_and_reset()); | ||
} | ||
|
||
#[test] | ||
|
@@ -951,7 +959,7 @@ mod tests { | |
values.insert("a".into(), "1".into()); | ||
values.insert("y".into(), "1".into()); | ||
|
||
assert!(!limit.applies(&values)) | ||
assert_false!(limit.applies(&values)) | ||
} | ||
|
||
#[test] | ||
|
@@ -962,7 +970,7 @@ mod tests { | |
let mut values: HashMap<String, String> = HashMap::new(); | ||
values.insert("x".into(), "5".into()); | ||
|
||
assert!(!limit.applies(&values)) | ||
assert_false!(limit.applies(&values)) | ||
} | ||
|
||
#[test] | ||
|
@@ -998,7 +1006,7 @@ mod tests { | |
values.insert("y".into(), "2".into()); | ||
values.insert("z".into(), "1".into()); | ||
|
||
assert!(!limit.applies(&values)) | ||
assert_false!(limit.applies(&values)) | ||
} | ||
|
||
#[test] | ||
|
@@ -1091,7 +1099,7 @@ mod tests { | |
|
||
// we can't access complex variables via simple names.... | ||
let limit = limit_with_condition(vec![r#"cel: req.method == "GET" "#]); | ||
assert!(!limit.applies(&values)); | ||
assert_false!(limit.applies(&values)); | ||
|
||
// But we can access it via the vars map. | ||
let limit = limit_with_condition(vec![r#"cel: vars["req.method"] == "GET" "#]); | ||
|
@@ -1117,7 +1125,7 @@ mod tests { | |
|
||
// we can't access simple variables that conflict with built-ins | ||
let limit = limit_with_condition(vec![r#"cel: size == "50" "#]); | ||
assert!(!limit.applies(&values)); | ||
assert_false!(limit.applies(&values)); | ||
|
||
// But we can access it via the vars map. | ||
let limit = limit_with_condition(vec![r#"cel: vars["size"] == "50" "#]); | ||
|
@@ -1130,7 +1138,7 @@ mod tests { | |
|
||
// we can't access simple variables that conflict with built-ins (the vars map) | ||
let limit = limit_with_condition(vec![r#"cel: vars == "hello" "#]); | ||
assert!(!limit.applies(&values)); | ||
assert_false!(limit.applies(&values)); | ||
|
||
// But we can access it via the vars map. | ||
let limit = limit_with_condition(vec![r#"cel: vars["vars"] == "hello" "#]); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See below, so I'd change this to:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good to me. updated.