mirror of https://github.com/grpc/grpc-go.git
xds: reject RDS response containing match with case-sensitive false (#3592)
This commit is contained in:
parent
a906ca0441
commit
e7557c8282
|
@ -95,9 +95,18 @@ func getClusterFromRouteConfiguration(rc *xdspb.RouteConfiguration, host string)
|
|||
return "", fmt.Errorf("matched virtual host has no routes")
|
||||
}
|
||||
dr := vh.Routes[len(vh.Routes)-1]
|
||||
if match := dr.GetMatch(); match == nil || (match.GetPrefix() != "" && match.GetPrefix() != "/") {
|
||||
match := dr.GetMatch()
|
||||
if match == nil {
|
||||
return "", fmt.Errorf("matched virtual host's default route doesn't have a match")
|
||||
}
|
||||
if prefix := match.GetPrefix(); prefix != "" && prefix != "/" {
|
||||
// The matched virtual host is invalid. Match is not "" or "/".
|
||||
return "", fmt.Errorf("matched virtual host is invalid")
|
||||
return "", fmt.Errorf("matched virtual host's default route is %v, want Prefix empty string or /", match)
|
||||
}
|
||||
if caseSensitive := match.GetCaseSensitive(); caseSensitive != nil && !caseSensitive.Value {
|
||||
// The case sensitive is set to false. Not set or set to true are both
|
||||
// valid.
|
||||
return "", fmt.Errorf("matches virtual host's default route set case-sensitive to false")
|
||||
}
|
||||
if route := dr.GetRoute(); route != nil {
|
||||
return route.GetCluster(), nil
|
||||
|
|
|
@ -25,6 +25,7 @@ import (
|
|||
xdspb "github.com/envoyproxy/go-control-plane/envoy/api/v2"
|
||||
routepb "github.com/envoyproxy/go-control-plane/envoy/api/v2/route"
|
||||
"github.com/golang/protobuf/proto"
|
||||
wrapperspb "github.com/golang/protobuf/ptypes/wrappers"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"google.golang.org/grpc/xds/internal/testutils/fakeserver"
|
||||
)
|
||||
|
@ -141,6 +142,25 @@ func (s) TestRDSGetClusterFromRouteConfiguration(t *testing.T) {
|
|||
wantCluster: "",
|
||||
wantError: true,
|
||||
},
|
||||
{
|
||||
// default route's match sets case-sensitive to false.
|
||||
name: "good-route-config-but-with-casesensitive-false",
|
||||
rc: &xdspb.RouteConfiguration{
|
||||
Name: goodRouteName1,
|
||||
VirtualHosts: []*routepb.VirtualHost{{
|
||||
Domains: []string{goodLDSTarget1},
|
||||
Routes: []*routepb.Route{{
|
||||
Match: &routepb.RouteMatch{
|
||||
PathSpecifier: &routepb.RouteMatch_Prefix{Prefix: "/"},
|
||||
CaseSensitive: &wrapperspb.BoolValue{Value: false},
|
||||
},
|
||||
Action: &routepb.Route_Route{
|
||||
Route: &routepb.RouteAction{
|
||||
ClusterSpecifier: &routepb.RouteAction_Cluster{Cluster: goodClusterName1},
|
||||
}}}}}}},
|
||||
wantCluster: "",
|
||||
wantError: true,
|
||||
},
|
||||
{
|
||||
name: "good-route-config-with-empty-string-route",
|
||||
rc: goodRouteConfig1,
|
||||
|
|
Loading…
Reference in New Issue