Skip to content
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

fix: fault injection regex #734

Merged
merged 2 commits into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/xds/envoy/listeners/fault_injection_configurer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ var _ = Describe("FaultInjectionConfigurer", func() {
safeRegexMatch:
googleRe2:
maxProgramSize: 500
regex: '&tag1=[^&]*value1[,&].*&tag2=[^&]*value2[,&].*'
regex: '.*&tag1=[^&]*value1[,&].*&tag2=[^&]*value2[,&].*'
- name: envoy.router
statPrefix: stats`,
}),
Expand Down Expand Up @@ -114,7 +114,7 @@ var _ = Describe("FaultInjectionConfigurer", func() {
safeRegexMatch:
googleRe2:
maxProgramSize: 500
regex: '(&tag1=[^&]*value1m1[,&].*&tag2=[^&]*value2m1[,&].*|&tag1=[^&]*value1m2[,&].*&tag2=[^&]*value2m2[,&].*)'
regex: '(.*&tag1=[^&]*value1m1[,&].*&tag2=[^&]*value2m1[,&].*|.*&tag1=[^&]*value1m2[,&].*&tag2=[^&]*value2m2[,&].*)'
- name: envoy.router
statPrefix: stats`,
}),
Expand Down
1 change: 1 addition & 0 deletions pkg/xds/envoy/tags/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func MatchingRegex(tags mesh_proto.SingleValueTagSet) (re string) {
expr := keyIsEqual + value + `.*`
re += expr
}
re = `.*` + re
return
}

Expand Down
24 changes: 22 additions & 2 deletions pkg/xds/envoy/tags/match_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ import (
"github.com/Kong/kuma/pkg/xds/envoy/tags"
)

func strictMatch(re *regexp.Regexp, s string) bool {
idx := re.FindStringIndex(s)
if idx == nil {
return false
}
return idx[0] == 0 && idx[1] == len(s)
}

var _ = Describe("MatchingRegex", func() {

type testCase struct {
Expand All @@ -27,7 +35,7 @@ var _ = Describe("MatchingRegex", func() {
// then
Expect(err).ToNot(HaveOccurred())
// when
matched := re.MatchString(tags.Serialize(given.serviceTags))
matched := strictMatch(re, tags.Serialize(given.serviceTags))
// then
Expect(matched).To(Equal(given.expected))
},
Expand All @@ -42,6 +50,18 @@ var _ = Describe("MatchingRegex", func() {
},
expected: true,
}),
Entry("match 3 one-value tags", testCase{
serviceTags: mesh_proto.MultiValueTagSet{
"tag1": {"value1": true},
"tag2": {"value2": true},
"tag3": {"value3": true},
},
selector: mesh_proto.SingleValueTagSet{
"tag2": "value2",
"tag3": "value3",
},
expected: true,
}),
Entry("match without middle tag2", testCase{
serviceTags: mesh_proto.MultiValueTagSet{
"tag1": {"value1": true, "value2": true},
Expand Down Expand Up @@ -142,7 +162,7 @@ var _ = Describe("RegexOR", func() {
Expect(err).ToNot(HaveOccurred())

for i, service := range given.servicesTags {
matched := re.MatchString(tags.Serialize(service))
matched := strictMatch(re, tags.Serialize(service))
Expect(matched).To(Equal(given.expected[i]))
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ resources:
safeRegexMatch:
googleRe2:
maxProgramSize: 500
regex: '&service=[^&]*frontend[,&].*'
regex: '.*&service=[^&]*frontend[,&].*'
- name: envoy.router
routeConfig:
name: inbound:backend1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ resources:
safeRegexMatch:
googleRe2:
maxProgramSize: 500
regex: '&service=[^&]*frontend[,&].*'
regex: '.*&service=[^&]*frontend[,&].*'
- name: envoy.router
routeConfig:
name: inbound:backend1
Expand Down