Skip to content

Commit

Permalink
Update tests to use routeRuleCondition Predicates
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Cattermole <acatterm@redhat.com>
  • Loading branch information
adam-cattermole committed Nov 1, 2024
1 parent 1b7a370 commit fc2a5af
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 195 deletions.
16 changes: 4 additions & 12 deletions pkg/wasm/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,8 @@ func TestConfigEqual(t *testing.T) {
Name: "5755da0b3c275ba6b8f553890eb32b04768a703b60ab9a5d7f4e0948e23ef0ab",
RouteRuleConditions: RouteRuleConditions{
Hostnames: []string{"other.example.com"},
Predicates: []Condition{
{
Selector: "request.url_path",
Operator: "startswith",
Value: "/",
},
Predicates: []string{
"request.url_path.startsWith('/')",
},
},
Actions: []Action{
Expand Down Expand Up @@ -125,12 +121,8 @@ func TestConfigEqual(t *testing.T) {
Name: "5755da0b3c275ba6b8f553890eb32b04768a703b60ab9a5d7f4e0948e23ef0ab",
RouteRuleConditions: RouteRuleConditions{
Hostnames: []string{"other.example.com"},
Predicates: []Condition{
{
Operator: "startswith",
Selector: "request.url_path",
Value: "/",
},
Predicates: []string{
"request.url_path.startsWith('/')",
},
},
},
Expand Down
40 changes: 11 additions & 29 deletions pkg/wasm/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,8 @@ var (
Name: "5755da0b3c275ba6b8f553890eb32b04768a703b60ab9a5d7f4e0948e23ef0ab",
RouteRuleConditions: RouteRuleConditions{
Hostnames: []string{"other.example.com"},
Predicates: []Condition{
{
Selector: "request.url_path",
Operator: "startswith",
Value: "/",
},
Predicates: []string{
"request.url_path.startsWith('/')",
},
},
Actions: []Action{
Expand Down Expand Up @@ -67,17 +63,9 @@ var (
Name: "21cb3adc608c09a360d62a03fd1afd7cc6f8720999a51d7916927fff26a34ef8",
RouteRuleConditions: RouteRuleConditions{
Hostnames: []string{"*"},
Predicates: []Condition{
{
Selector: "request.method",
Operator: "eq",
Value: "GET",
},
{
Selector: "request.url_path",
Operator: "startswith",
Value: "/",
},
Predicates: []string{
"request.method == 'GET'",
"request.url_path.startsWith('/')",
},
},
Actions: []Action{
Expand Down Expand Up @@ -124,7 +112,7 @@ var (
},
},
}
testBasicConfigJSON = `{"services":{"auth-service":{"endpoint":"kuadrant-auth-service","type":"auth","failureMode":"deny"},"ratelimit-service":{"endpoint":"kuadrant-ratelimit-service","type":"ratelimit","failureMode":"allow"}},"actionSets":[{"name":"5755da0b3c275ba6b8f553890eb32b04768a703b60ab9a5d7f4e0948e23ef0ab","routeRuleConditions":{"hostnames":["other.example.com"],"matches":[{"operator":"startswith","selector":"request.url_path","value":"/"}]},"actions":[{"service":"ratelimit-service","scope":"default/other","conditions":[{"operator":"neq","selector":"source.address","value":"127.0.0.1"}],"data":[{"static":{"key":"limit.global__f63bec56","value":"1"}}]}]},{"name":"21cb3adc608c09a360d62a03fd1afd7cc6f8720999a51d7916927fff26a34ef8","routeRuleConditions":{"hostnames":["*"],"matches":[{"operator":"eq","selector":"request.method","value":"GET"},{"operator":"startswith","selector":"request.url_path","value":"/"}]},"actions":[{"service":"auth-service","scope":"e2db39952dd3bc72e152330a2eb15abbd9675c7ac6b54a1a292f07f25f09f138"},{"service":"ratelimit-service","scope":"default/toystore","data":[{"static":{"key":"limit.specific__69ea4d2d","value":"1"}}]},{"service":"ratelimit-service","scope":"default/toystore","conditions":[{"operator":"neq","selector":"source.address","value":"127.0.0.1"}],"data":[{"static":{"key":"limit.global__f63bec56","value":"1"}}]}]}]}`
testBasicConfigJSON = `{"services":{"auth-service":{"endpoint":"kuadrant-auth-service","type":"auth","failureMode":"deny"},"ratelimit-service":{"endpoint":"kuadrant-ratelimit-service","type":"ratelimit","failureMode":"allow"}},"actionSets":[{"name":"5755da0b3c275ba6b8f553890eb32b04768a703b60ab9a5d7f4e0948e23ef0ab","routeRuleConditions":{"hostnames":["other.example.com"],"predicates":["request.url_path.startsWith('/')"]},"actions":[{"service":"ratelimit-service","scope":"default/other","conditions":[{"operator":"neq","selector":"source.address","value":"127.0.0.1"}],"data":[{"static":{"key":"limit.global__f63bec56","value":"1"}}]}]},{"name":"21cb3adc608c09a360d62a03fd1afd7cc6f8720999a51d7916927fff26a34ef8","routeRuleConditions":{"hostnames":["*"],"predicates":["request.method == 'GET'","request.url_path.startsWith('/')"]},"actions":[{"service":"auth-service","scope":"e2db39952dd3bc72e152330a2eb15abbd9675c7ac6b54a1a292f07f25f09f138"},{"service":"ratelimit-service","scope":"default/toystore","data":[{"static":{"key":"limit.specific__69ea4d2d","value":"1"}}]},{"service":"ratelimit-service","scope":"default/toystore","conditions":[{"operator":"neq","selector":"source.address","value":"127.0.0.1"}],"data":[{"static":{"key":"limit.global__f63bec56","value":"1"}}]}]}]}`
testBasicConfigYAML = `
services:
auth-service:
Expand All @@ -140,10 +128,8 @@ actionSets:
routeRuleConditions:
hostnames:
- other.example.com
matches:
- operator: startswith
selector: request.url_path
value: /
predicates:
- request.url_path.startsWith('/')
actions:
- service: ratelimit-service
scope: default/other
Expand All @@ -159,13 +145,9 @@ actionSets:
routeRuleConditions:
hostnames:
- "*"
matches:
- operator: eq
selector: request.method
value: GET
- operator: startswith
selector: request.url_path
value: /
predicates:
- request.method == 'GET'
- request.url_path.startsWith('/')
actions:
- service: auth-service
scope: e2db39952dd3bc72e152330a2eb15abbd9675c7ac6b54a1a292f07f25f09f138
Expand Down
196 changes: 42 additions & 154 deletions tests/istio/extension_reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,9 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
Name: wasm.ActionSetNameForPath(pathID, 0, "*.example.com"),
RouteRuleConditions: wasm.RouteRuleConditions{
Hostnames: []string{"*.example.com"},
Predicates: []wasm.Condition{
{
Selector: "request.method",
Operator: wasm.PatternOperator(kuadrantv1beta3.EqualOperator),
Value: "GET",
},
{
Selector: "request.url_path",
Operator: wasm.PatternOperator(kuadrantv1beta3.StartsWithOperator),
Value: "/toy",
},
Predicates: []string{
"request.method == 'GET'",
"request.url_path.startsWith('/toy')",
},
},
Actions: []wasm.Action{
Expand Down Expand Up @@ -758,17 +750,9 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
Name: wasm.ActionSetNameForPath(pathID, 0, "*.example.com"),
RouteRuleConditions: wasm.RouteRuleConditions{
Hostnames: []string{"*.example.com"},
Predicates: []wasm.Condition{
{
Selector: "request.method",
Operator: wasm.PatternOperator(kuadrantv1beta3.EqualOperator),
Value: "GET",
},
{
Selector: "request.url_path",
Operator: wasm.PatternOperator(kuadrantv1beta3.StartsWithOperator),
Value: "/toy",
},
Predicates: []string{
"request.method == 'GET'",
"request.url_path.startsWith('/toy')",
},
},
Actions: []wasm.Action{
Expand Down Expand Up @@ -987,17 +971,9 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
Name: wasm.ActionSetNameForPath(pathID, 0, "*.example.com"),
RouteRuleConditions: wasm.RouteRuleConditions{
Hostnames: []string{"*.example.com"},
Predicates: []wasm.Condition{
{
Selector: "request.method",
Operator: wasm.PatternOperator(kuadrantv1beta3.EqualOperator),
Value: "GET",
},
{
Selector: "request.url_path",
Operator: wasm.PatternOperator(kuadrantv1beta3.StartsWithOperator),
Value: "/toy",
},
Predicates: []string{
"request.method == 'GET'",
"request.url_path.startsWith('/toy')",
},
},
Actions: []wasm.Action{
Expand Down Expand Up @@ -1205,17 +1181,9 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
Name: wasm.ActionSetNameForPath(pathID, 0, "*.example.com"),
RouteRuleConditions: wasm.RouteRuleConditions{
Hostnames: []string{"*.example.com"},
Predicates: []wasm.Condition{
{
Selector: "request.method",
Operator: wasm.PatternOperator(kuadrantv1beta3.EqualOperator),
Value: "GET",
},
{
Selector: "request.url_path",
Operator: wasm.PatternOperator(kuadrantv1beta3.StartsWithOperator),
Value: "/toy",
},
Predicates: []string{
"request.method == 'GET'",
"request.url_path.startsWith('/toy')",
},
},
Actions: []wasm.Action{
Expand Down Expand Up @@ -1341,17 +1309,9 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
Name: wasm.ActionSetNameForPath(pathID, 0, "*.example.com"),
RouteRuleConditions: wasm.RouteRuleConditions{
Hostnames: []string{"*.example.com"},
Predicates: []wasm.Condition{
{
Selector: "request.method",
Operator: wasm.PatternOperator(kuadrantv1beta3.EqualOperator),
Value: "GET",
},
{
Selector: "request.url_path",
Operator: wasm.PatternOperator(kuadrantv1beta3.StartsWithOperator),
Value: "/toy",
},
Predicates: []string{
"request.method == 'GET'",
"request.url_path.startsWith('/toy')",
},
},
Actions: []wasm.Action{
Expand Down Expand Up @@ -1549,17 +1509,9 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
Name: wasm.ActionSetNameForPath(pathID, 0, "*.a.example.com"),
RouteRuleConditions: wasm.RouteRuleConditions{
Hostnames: []string{"*.a.example.com"},
Predicates: []wasm.Condition{
{
Selector: "request.method",
Operator: wasm.PatternOperator(kuadrantv1beta3.EqualOperator),
Value: "GET",
},
{
Selector: "request.url_path",
Operator: wasm.PatternOperator(kuadrantv1beta3.StartsWithOperator),
Value: "/routeA",
},
Predicates: []string{
"request.method == 'GET'",
"request.url_path.startsWith('/routeA')",
},
},
Actions: []wasm.Action{
Expand Down Expand Up @@ -1648,17 +1600,9 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
Name: wasm.ActionSetNameForPath(pathID, 0, "*.b.example.com"),
RouteRuleConditions: wasm.RouteRuleConditions{
Hostnames: []string{"*.b.example.com"},
Predicates: []wasm.Condition{
{
Selector: "request.method",
Operator: wasm.PatternOperator(kuadrantv1beta3.EqualOperator),
Value: "GET",
},
{
Selector: "request.url_path",
Operator: wasm.PatternOperator(kuadrantv1beta3.StartsWithOperator),
Value: "/routeB",
},
Predicates: []string{
"request.method == 'GET'",
"request.url_path.startsWith('/routeB')",
},
},
Actions: []wasm.Action{
Expand Down Expand Up @@ -1831,17 +1775,9 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
Name: wasm.ActionSetNameForPath(pathID, 0, "*.a.example.com"),
RouteRuleConditions: wasm.RouteRuleConditions{
Hostnames: []string{"*.a.example.com"},
Predicates: []wasm.Condition{
{
Selector: "request.method",
Operator: wasm.PatternOperator(kuadrantv1beta3.EqualOperator),
Value: "GET",
},
{
Selector: "request.url_path",
Operator: wasm.PatternOperator(kuadrantv1beta3.StartsWithOperator),
Value: "/routeA",
},
Predicates: []string{
"request.method == 'GET'",
"request.url_path.startsWith('/routeA')",
},
},
Actions: []wasm.Action{
Expand Down Expand Up @@ -1948,17 +1884,9 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
Name: wasm.ActionSetNameForPath(pathID, 0, "*.a.example.com"),
RouteRuleConditions: wasm.RouteRuleConditions{
Hostnames: []string{"*.a.example.com"},
Predicates: []wasm.Condition{
{
Selector: "request.method",
Operator: wasm.PatternOperator(kuadrantv1beta3.EqualOperator),
Value: "GET",
},
{
Selector: "request.url_path",
Operator: wasm.PatternOperator(kuadrantv1beta3.StartsWithOperator),
Value: "/routeA",
},
Predicates: []string{
"request.method == 'GET'",
"request.url_path.startsWith('/routeA')",
},
},
Actions: []wasm.Action{
Expand Down Expand Up @@ -2167,17 +2095,9 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
Name: wasm.ActionSetNameForPath(pathID, 0, "*.a.example.com"),
RouteRuleConditions: wasm.RouteRuleConditions{
Hostnames: []string{"*.a.example.com"},
Predicates: []wasm.Condition{
{
Selector: "request.method",
Operator: wasm.PatternOperator(kuadrantv1beta3.EqualOperator),
Value: "GET",
},
{
Selector: "request.url_path",
Operator: wasm.PatternOperator(kuadrantv1beta3.StartsWithOperator),
Value: "/routeA",
},
Predicates: []string{
"request.method == 'GET'",
"request.url_path.startsWith('/routeA')",
},
},
Actions: []wasm.Action{
Expand Down Expand Up @@ -2281,17 +2201,9 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
Name: wasm.ActionSetNameForPath(pathID, 0, "*.a.example.com"),
RouteRuleConditions: wasm.RouteRuleConditions{
Hostnames: []string{"*.a.example.com"},
Predicates: []wasm.Condition{
{
Selector: "request.method",
Operator: wasm.PatternOperator(kuadrantv1beta3.EqualOperator),
Value: "GET",
},
{
Selector: "request.url_path",
Operator: wasm.PatternOperator(kuadrantv1beta3.StartsWithOperator),
Value: "/routeA",
},
Predicates: []string{
"request.method == 'GET'",
"request.url_path.startsWith('/routeA')",
},
},
Actions: []wasm.Action{
Expand All @@ -2315,17 +2227,9 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
Name: wasm.ActionSetNameForPath(pathID_B, 0, "*.b.example.com"),
RouteRuleConditions: wasm.RouteRuleConditions{
Hostnames: []string{"*.b.example.com"},
Predicates: []wasm.Condition{
{
Selector: "request.method",
Operator: wasm.PatternOperator(kuadrantv1beta3.EqualOperator),
Value: "GET",
},
{
Selector: "request.url_path",
Operator: wasm.PatternOperator(kuadrantv1beta3.StartsWithOperator),
Value: "/routeB",
},
Predicates: []string{
"request.method == 'GET'",
"request.url_path.startsWith('/routeB')",
},
},
Actions: []wasm.Action{
Expand Down Expand Up @@ -2462,17 +2366,9 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
Name: wasm.ActionSetNameForPath(pathID, 0, gwHostname),
RouteRuleConditions: wasm.RouteRuleConditions{
Hostnames: []string{gwHostname},
Predicates: []wasm.Condition{
{
Selector: "request.method",
Operator: wasm.PatternOperator(kuadrantv1beta3.EqualOperator),
Value: "GET",
},
{
Selector: "request.url_path",
Operator: wasm.PatternOperator(kuadrantv1beta3.StartsWithOperator),
Value: "/toy",
},
Predicates: []string{
"request.method == 'GET'",
"request.url_path.startsWith('/toy')",
},
},
Actions: []wasm.Action{
Expand Down Expand Up @@ -2546,17 +2442,9 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
Name: wasm.ActionSetNameForPath(pathID, 0, hostname),
RouteRuleConditions: wasm.RouteRuleConditions{
Hostnames: []string{hostname},
Predicates: []wasm.Condition{
{
Selector: "request.method",
Operator: wasm.PatternOperator(kuadrantv1beta3.EqualOperator),
Value: "GET",
},
{
Selector: "request.url_path",
Operator: wasm.PatternOperator(kuadrantv1beta3.StartsWithOperator),
Value: "/toy",
},
Predicates: []string{
"request.method == 'GET'",
"request.url_path.startsWith('/toy')",
},
},
Actions: []wasm.Action{
Expand Down

0 comments on commit fc2a5af

Please sign in to comment.