Skip to content

Commit

Permalink
[tests] Using predicates instead of matches
Browse files Browse the repository at this point in the history
Signed-off-by: dd di cesare <didi@posteo.net>
  • Loading branch information
didierofrivia committed Oct 28, 2024
1 parent 83a5354 commit 21c8b1e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 62 deletions.
45 changes: 17 additions & 28 deletions tests/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,11 @@ const CONFIG: &str = r#"{
"name": "some-name",
"routeRuleConditions": {
"hostnames": ["*.toystore.com", "example.com"],
"matches": [
{
"selector": "request.url_path",
"operator": "startswith",
"value": "/admin/toy"
},
{
"selector": "request.host",
"operator": "eq",
"value": "cars.toystore.com"
},
{
"selector": "request.method",
"operator": "eq",
"value": "POST"
}]
"predicates" : [
"request.url_path.startsWith('/admin/toy')",
"request.host == 'cars.toystore.com'",
"request.method == 'POST'"
]
},
"actions": [
{
Expand Down Expand Up @@ -189,12 +178,12 @@ fn it_auths() {
10, 220, 1, 10, 25, 10, 23, 10, 21, 18, 15, 49, 50, 55, 46, 48, 46, 48, 46, 49, 58,
52, 53, 48, 48, 48, 24, 200, 223, 2, 18, 23, 10, 21, 10, 19, 18, 14, 49, 50, 55,
46, 48, 46, 48, 46, 49, 58, 56, 48, 48, 48, 24, 192, 62, 34, 141, 1, 10, 0, 18,
136, 1, 18, 3, 71, 69, 84, 26, 30, 10, 10, 58, 97, 117, 116, 104, 111, 114, 105,
116, 121, 18, 16, 97, 98, 105, 95, 116, 101, 115, 116, 95, 104, 97, 114, 110, 101,
115, 115, 26, 14, 10, 7, 58, 109, 101, 116, 104, 111, 100, 18, 3, 71, 69, 84, 26,
38, 10, 5, 58, 112, 97, 116, 104, 18, 29, 47, 100, 101, 102, 97, 117, 108, 116, 47,
114, 101, 113, 117, 101, 115, 116, 47, 104, 101, 97, 100, 101, 114, 115, 47, 112,
97, 116, 104, 34, 10, 47, 97, 100, 109, 105, 110, 47, 116, 111, 121, 42, 17, 99,
136, 1, 18, 3, 71, 69, 84, 26, 38, 10, 5, 58, 112, 97, 116, 104, 18, 29, 47, 100,
101, 102, 97, 117, 108, 116, 47, 114, 101, 113, 117, 101, 115, 116, 47, 104, 101,
97, 100, 101, 114, 115, 47, 112, 97, 116, 104, 26, 14, 10, 7, 58, 109, 101, 116,
104, 111, 100, 18, 3, 71, 69, 84, 26, 30, 10, 10, 58, 97, 117, 116, 104, 111, 114,
105, 116, 121, 18, 16, 97, 98, 105, 95, 116, 101, 115, 116, 95, 104, 97, 114, 110,
101, 115, 115, 34, 10, 47, 97, 100, 109, 105, 110, 47, 116, 111, 121, 42, 17, 99,
97, 114, 115, 46, 116, 111, 121, 115, 116, 111, 114, 101, 46, 99, 111, 109, 50, 4,
104, 116, 116, 112, 82, 4, 72, 84, 84, 80, 82, 20, 10, 4, 104, 111, 115, 116, 18,
12, 97, 117, 116, 104, 99, 111, 110, 102, 105, 103, 45, 65, 90, 0,
Expand Down Expand Up @@ -385,12 +374,12 @@ fn it_denies() {
10, 220, 1, 10, 25, 10, 23, 10, 21, 18, 15, 49, 50, 55, 46, 48, 46, 48, 46, 49, 58,
52, 53, 48, 48, 48, 24, 200, 223, 2, 18, 23, 10, 21, 10, 19, 18, 14, 49, 50, 55,
46, 48, 46, 48, 46, 49, 58, 56, 48, 48, 48, 24, 192, 62, 34, 141, 1, 10, 0, 18,
136, 1, 18, 3, 71, 69, 84, 26, 30, 10, 10, 58, 97, 117, 116, 104, 111, 114, 105,
116, 121, 18, 16, 97, 98, 105, 95, 116, 101, 115, 116, 95, 104, 97, 114, 110, 101,
115, 115, 26, 14, 10, 7, 58, 109, 101, 116, 104, 111, 100, 18, 3, 71, 69, 84, 26,
38, 10, 5, 58, 112, 97, 116, 104, 18, 29, 47, 100, 101, 102, 97, 117, 108, 116, 47,
114, 101, 113, 117, 101, 115, 116, 47, 104, 101, 97, 100, 101, 114, 115, 47, 112,
97, 116, 104, 34, 10, 47, 97, 100, 109, 105, 110, 47, 116, 111, 121, 42, 17, 99,
136, 1, 18, 3, 71, 69, 84, 26, 38, 10, 5, 58, 112, 97, 116, 104, 18, 29, 47, 100,
101, 102, 97, 117, 108, 116, 47, 114, 101, 113, 117, 101, 115, 116, 47, 104, 101,
97, 100, 101, 114, 115, 47, 112, 97, 116, 104, 26, 14, 10, 7, 58, 109, 101, 116,
104, 111, 100, 18, 3, 71, 69, 84, 26, 30, 10, 10, 58, 97, 117, 116, 104, 111, 114,
105, 116, 121, 18, 16, 97, 98, 105, 95, 116, 101, 115, 116, 95, 104, 97, 114, 110,
101, 115, 115, 34, 10, 47, 97, 100, 109, 105, 110, 47, 116, 111, 121, 42, 17, 99,
97, 114, 115, 46, 116, 111, 121, 115, 116, 111, 114, 101, 46, 99, 111, 109, 50, 4,
104, 116, 116, 112, 82, 4, 72, 84, 84, 80, 82, 20, 10, 4, 104, 111, 115, 116, 18,
12, 97, 117, 116, 104, 99, 111, 110, 102, 105, 103, 45, 65, 90, 0,
Expand Down
45 changes: 17 additions & 28 deletions tests/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,11 @@ const CONFIG: &str = r#"{
"name": "some-name",
"routeRuleConditions": {
"hostnames": ["*.toystore.com", "example.com"],
"matches": [
{
"selector": "request.url_path",
"operator": "startswith",
"value": "/admin/toy"
},
{
"selector": "request.host",
"operator": "eq",
"value": "cars.toystore.com"
},
{
"selector": "request.method",
"operator": "eq",
"value": "POST"
}]
"predicates" : [
"request.url_path.startsWith('/admin/toy')",
"request.host == 'cars.toystore.com'",
"request.method == 'POST'"
]
},
"actions": [
{
Expand Down Expand Up @@ -207,12 +196,12 @@ fn it_performs_authenticated_rate_limiting() {
10, 220, 1, 10, 25, 10, 23, 10, 21, 18, 15, 49, 50, 55, 46, 48, 46, 48, 46, 49, 58,
52, 53, 48, 48, 48, 24, 200, 223, 2, 18, 23, 10, 21, 10, 19, 18, 14, 49, 50, 55,
46, 48, 46, 48, 46, 49, 58, 56, 48, 48, 48, 24, 192, 62, 34, 141, 1, 10, 0, 18,
136, 1, 18, 3, 71, 69, 84, 26, 30, 10, 10, 58, 97, 117, 116, 104, 111, 114, 105,
116, 121, 18, 16, 97, 98, 105, 95, 116, 101, 115, 116, 95, 104, 97, 114, 110, 101,
115, 115, 26, 14, 10, 7, 58, 109, 101, 116, 104, 111, 100, 18, 3, 71, 69, 84, 26,
38, 10, 5, 58, 112, 97, 116, 104, 18, 29, 47, 100, 101, 102, 97, 117, 108, 116, 47,
114, 101, 113, 117, 101, 115, 116, 47, 104, 101, 97, 100, 101, 114, 115, 47, 112,
97, 116, 104, 34, 10, 47, 97, 100, 109, 105, 110, 47, 116, 111, 121, 42, 17, 99,
136, 1, 18, 3, 71, 69, 84, 26, 38, 10, 5, 58, 112, 97, 116, 104, 18, 29, 47, 100,
101, 102, 97, 117, 108, 116, 47, 114, 101, 113, 117, 101, 115, 116, 47, 104, 101,
97, 100, 101, 114, 115, 47, 112, 97, 116, 104, 26, 14, 10, 7, 58, 109, 101, 116,
104, 111, 100, 18, 3, 71, 69, 84, 26, 30, 10, 10, 58, 97, 117, 116, 104, 111, 114,
105, 116, 121, 18, 16, 97, 98, 105, 95, 116, 101, 115, 116, 95, 104, 97, 114, 110,
101, 115, 115, 34, 10, 47, 97, 100, 109, 105, 110, 47, 116, 111, 121, 42, 17, 99,
97, 114, 115, 46, 116, 111, 121, 115, 116, 111, 114, 101, 46, 99, 111, 109, 50, 4,
104, 116, 116, 112, 82, 4, 72, 84, 84, 80, 82, 20, 10, 4, 104, 111, 115, 116, 18,
12, 97, 117, 116, 104, 99, 111, 110, 102, 105, 103, 45, 65, 90, 0,
Expand Down Expand Up @@ -420,12 +409,12 @@ fn unauthenticated_does_not_ratelimit() {
10, 220, 1, 10, 25, 10, 23, 10, 21, 18, 15, 49, 50, 55, 46, 48, 46, 48, 46, 49, 58,
52, 53, 48, 48, 48, 24, 200, 223, 2, 18, 23, 10, 21, 10, 19, 18, 14, 49, 50, 55,
46, 48, 46, 48, 46, 49, 58, 56, 48, 48, 48, 24, 192, 62, 34, 141, 1, 10, 0, 18,
136, 1, 18, 3, 71, 69, 84, 26, 30, 10, 10, 58, 97, 117, 116, 104, 111, 114, 105,
116, 121, 18, 16, 97, 98, 105, 95, 116, 101, 115, 116, 95, 104, 97, 114, 110, 101,
115, 115, 26, 14, 10, 7, 58, 109, 101, 116, 104, 111, 100, 18, 3, 71, 69, 84, 26,
38, 10, 5, 58, 112, 97, 116, 104, 18, 29, 47, 100, 101, 102, 97, 117, 108, 116, 47,
114, 101, 113, 117, 101, 115, 116, 47, 104, 101, 97, 100, 101, 114, 115, 47, 112,
97, 116, 104, 34, 10, 47, 97, 100, 109, 105, 110, 47, 116, 111, 121, 42, 17, 99,
136, 1, 18, 3, 71, 69, 84, 26, 38, 10, 5, 58, 112, 97, 116, 104, 18, 29, 47, 100,
101, 102, 97, 117, 108, 116, 47, 114, 101, 113, 117, 101, 115, 116, 47, 104, 101,
97, 100, 101, 114, 115, 47, 112, 97, 116, 104, 26, 14, 10, 7, 58, 109, 101, 116,
104, 111, 100, 18, 3, 71, 69, 84, 26, 30, 10, 10, 58, 97, 117, 116, 104, 111, 114,
105, 116, 121, 18, 16, 97, 98, 105, 95, 116, 101, 115, 116, 95, 104, 97, 114, 110,
101, 115, 115, 34, 10, 47, 97, 100, 109, 105, 110, 47, 116, 111, 121, 42, 17, 99,
97, 114, 115, 46, 116, 111, 121, 115, 116, 111, 114, 101, 46, 99, 111, 109, 50, 4,
104, 116, 116, 112, 82, 4, 72, 84, 84, 80, 82, 20, 10, 4, 104, 111, 115, 116, 18,
12, 97, 117, 116, 104, 99, 111, 110, 102, 105, 103, 45, 65, 90, 0,
Expand Down
8 changes: 2 additions & 6 deletions tests/remote_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,8 @@ fn it_limits_based_on_source_address() {
"name": "some-name",
"routeRuleConditions": {
"hostnames": ["*.example.com"],
"matches": [
{
"selector": "source.remote_address",
"operator": "neq",
"value": "50.0.0.1"
}
"predicates" : [
"source.remote_address != '50.0.0.1'"
]
},
"actions": [
Expand Down

0 comments on commit 21c8b1e

Please sign in to comment.