diff --git a/agent/discovery/query_fetcher_v1.go b/agent/discovery/query_fetcher_v1.go index da76d744dd..1b39f020b5 100644 --- a/agent/discovery/query_fetcher_v1.go +++ b/agent/discovery/query_fetcher_v1.go @@ -424,6 +424,7 @@ RPC: } func (f *V1DataFetcher) ValidateRequest(_ Context, req *QueryPayload) error { + f.logger.Debug(fmt.Sprintf("req %+v", req)) if req.EnableFailover { return ErrNotSupported } diff --git a/agent/discovery/query_fetcher_v1_ce.go b/agent/discovery/query_fetcher_v1_ce.go index 090db0e5f7..5d500644a3 100644 --- a/agent/discovery/query_fetcher_v1_ce.go +++ b/agent/discovery/query_fetcher_v1_ce.go @@ -15,7 +15,7 @@ func (f *V1DataFetcher) NormalizeRequest(req *QueryPayload) { } func validateEnterpriseTenancy(req QueryTenancy) error { - if req.Namespace != "" || req.Partition != acl.DefaultPartitionName { + if !(req.Namespace == "" || req.Namespace == acl.DefaultNamespaceName) || !(req.Partition == acl.DefaultPartitionName || req.Partition == "default") { return ErrNotSupported } return nil diff --git a/agent/discovery/query_fetcher_v1_ce_test.go b/agent/discovery/query_fetcher_v1_ce_test.go index 717475c9dc..69cd2dea98 100644 --- a/agent/discovery/query_fetcher_v1_ce_test.go +++ b/agent/discovery/query_fetcher_v1_ce_test.go @@ -5,7 +5,60 @@ package discovery +import ( + "github.com/stretchr/testify/require" + "testing" +) + const ( defaultTestNamespace = "" defaultTestPartition = "" ) + +func Test_validateEnterpriseTenancy(t *testing.T) { + testCases := []struct { + name string + req QueryTenancy + expected error + }{ + { + name: "empty namespace and partition returns no error", + req: QueryTenancy{ + Namespace: defaultTestNamespace, + Partition: defaultTestPartition, + }, + expected: nil, + }, + { + name: "namespace and partition set to 'default' returns no error", + req: QueryTenancy{ + Namespace: "default", + Partition: "default", + }, + expected: nil, + }, + { + name: "namespace set to something other than empty string or `default` returns not supported error", + req: QueryTenancy{ + Namespace: "namespace-1", + Partition: "default", + }, + expected: ErrNotSupported, + }, + { + name: "partition set to something other than empty string or `default` returns not supported error", + req: QueryTenancy{ + Namespace: "default", + Partition: "partition-1", + }, + expected: ErrNotSupported, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + err := validateEnterpriseTenancy(tc.req) + require.Equal(t, tc.expected, err) + }) + } +}