Skip to content

Commit

Permalink
fix misleading present/absent for headers
Browse files Browse the repository at this point in the history
  • Loading branch information
rboyer committed Jul 24, 2019
1 parent 26f9445 commit 53a1050
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
5 changes: 2 additions & 3 deletions agent/structs/config_entry_discoverychain.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,8 @@ func (e *ServiceRouterConfigEntry) Validate() error {
if hdr.Suffix != "" {
hdrParts++
}
// "absent" is the bare invert=true
if (hdrParts == 0 && !hdr.Invert) || (hdrParts > 1) {
return fmt.Errorf("Route[%d] Header[%d] should only contain one of Present, Exact, Prefix, Suffix, or Regex (or just Invert)", i, j)
if hdrParts != 1 {
return fmt.Errorf("Route[%d] Header[%d] should only contain one of Present, Exact, Prefix, Suffix, or Regex", i, j)
}
}

Expand Down
6 changes: 3 additions & 3 deletions agent/structs/config_entry_discoverychain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -883,9 +883,9 @@ func TestServiceRouterConfigEntry(t *testing.T) {
{
name: "route with header not present",
entry: makerouter(routeMatch(httpMatchHeader(ServiceRouteHTTPMatchHeader{
Name: "foo",
Invert: true,
//Present: false,
Name: "foo",
Present: true,
Invert: true,
}))),
},
{
Expand Down
6 changes: 0 additions & 6 deletions agent/xds/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,6 @@ func makeRouteMatchForDiscoveryRoute(discoveryRoute *structs.DiscoveryRoute, pro
eh.HeaderMatchSpecifier = &envoyroute.HeaderMatcher_PresentMatch{
PresentMatch: true,
}
case hdr.Invert: // THIS HAS TO BE LAST
eh.HeaderMatchSpecifier = &envoyroute.HeaderMatcher_PresentMatch{
// We set this to the misleading value of 'true' here
// because we'll generically invert it next.
PresentMatch: true,
}
default:
continue // skip this impossible situation
}
Expand Down
5 changes: 3 additions & 2 deletions agent/xds/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ func TestRoutesFromSnapshot(t *testing.T) {
},
{
Match: httpMatchHeader(structs.ServiceRouteHTTPMatchHeader{
Name: "x-debug",
Invert: true,
Name: "x-debug",
Present: true,
Invert: true,
}),
Destination: toService("hdr-not-present"),
},
Expand Down

0 comments on commit 53a1050

Please sign in to comment.