Skip to content

Commit

Permalink
Fix header present match (istio#47704)
Browse files Browse the repository at this point in the history
* Fix header present match

* add release note

* Add ut

* fix lint
  • Loading branch information
hzxuzhonghu authored Nov 3, 2023
1 parent 327e266 commit 0945c97
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pilot/pkg/networking/core/v1alpha3/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ func translateQueryParamMatch(name string, in *networking.StringMatch) *route.Qu
// isCatchAllStringMatch determines if the given matcher is matched with all strings or not.
// Currently, if the regex has "*" value, it returns true
func isCatchAllStringMatch(in *networking.StringMatch) bool {
if in == nil {
if in == nil || in.MatchType == nil {
return true
}

Expand Down
37 changes: 37 additions & 0 deletions pilot/pkg/networking/core/v1alpha3/route/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,15 @@ func TestBuildHTTPRoutes(t *testing.T) {
g.Expect(routes[0].GetMatch().GetHeaders()[0].GetName()).To(Equal("FOO-HEADER"))
g.Expect(routes[0].GetMatch().GetHeaders()[0].GetPresentMatch()).To(Equal(true))
g.Expect(routes[0].GetMatch().GetHeaders()[0].GetInvertMatch()).To(Equal(false))

routes, err = route.BuildHTTPRoutesForVirtualService(node(cg), virtualServiceWithPresentMatchingOnHeader2,
serviceRegistry, nil, 8080, gatewayNames, route.RouteOptions{})
g.Expect(err).NotTo(HaveOccurred())
xdstest.ValidateRoutes(t, routes)
g.Expect(len(routes)).To(Equal(1))
g.Expect(routes[0].GetMatch().GetHeaders()[0].GetName()).To(Equal("FOO-HEADER"))
g.Expect(routes[0].GetMatch().GetHeaders()[0].GetPresentMatch()).To(Equal(true))
g.Expect(routes[0].GetMatch().GetHeaders()[0].GetInvertMatch()).To(Equal(false))
})

t.Run("for virtual service with presence matching on header and without_header", func(t *testing.T) {
Expand Down Expand Up @@ -2217,6 +2226,34 @@ var virtualServiceWithPresentMatchingOnHeader = config.Config{
},
}

var virtualServiceWithPresentMatchingOnHeader2 = config.Config{
Meta: config.Meta{
GroupVersionKind: gvk.VirtualService,
Name: "acme",
},
Spec: &networking.VirtualService{
Hosts: []string{},
Gateways: []string{"some-gateway"},
Http: []*networking.HTTPRoute{
{
Match: []*networking.HTTPMatchRequest{
{
Name: "presence",
Headers: map[string]*networking.StringMatch{
"FOO-HEADER": {},
},
},
},
Redirect: &networking.HTTPRedirect{
Uri: "example.org",
Authority: "some-authority.default.svc.cluster.local",
RedirectCode: 308,
},
},
},
},
}

var virtualServiceWithPresentMatchingOnWithoutHeader = config.Config{
Meta: config.Meta{
GroupVersionKind: gvk.VirtualService,
Expand Down
8 changes: 8 additions & 0 deletions releasenotes/notes/header-present.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: release-notes/v2
kind: bug-fix
area: traffic-management
issue:
- 47341
releaseNotes:
- |
**Fixed** VirtualService http header present match does not work with `header-name: {}` set.

0 comments on commit 0945c97

Please sign in to comment.