Skip to content

Commit

Permalink
[bugfix] add target length validation for each grpc client exection m…
Browse files Browse the repository at this point in the history
…ethod (#1939)

Signed-off-by: kpango <[email protected]>
  • Loading branch information
kpango authored Feb 7, 2023
1 parent f529cbd commit c83a852
Show file tree
Hide file tree
Showing 26 changed files with 2,043 additions and 1,503 deletions.
382 changes: 115 additions & 267 deletions apis/grpc/v1/payload/payload_vtproto.pb.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions example/client/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ replace (
golang.org/x/crypto => golang.org/x/crypto v0.5.0
golang.org/x/net => golang.org/x/net v0.5.0
golang.org/x/text => golang.org/x/text v0.6.0
google.golang.org/genproto => google.golang.org/genproto v0.0.0-20230123190316-2c411cf9d197
google.golang.org/grpc => google.golang.org/grpc v1.52.0
google.golang.org/genproto => google.golang.org/genproto v0.0.0-20230202175211-008b39050e57
google.golang.org/grpc => google.golang.org/grpc v1.52.3
google.golang.org/protobuf => google.golang.org/protobuf v1.28.1
gopkg.in/yaml.v2 => gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 => gopkg.in/yaml.v3 v3.0.1
Expand Down
8 changes: 4 additions & 4 deletions example/client/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gonum.org/v1/hdf5 v0.0.0-20210714002203-8c5d23bc6946 h1:vJpL69PeUullhJyKtTjHjENEmZU3BkO4e+fod7nKzgM=
gonum.org/v1/hdf5 v0.0.0-20210714002203-8c5d23bc6946/go.mod h1:BQUWDHIAygjdt1HnUPQ0eWqLN2n5FwJycrpYUVUOx2I=
google.golang.org/genproto v0.0.0-20230123190316-2c411cf9d197 h1:BwjeHhu4HS48EZmu1nS7flldBIDPC3qn+HqaSQ1K4x8=
google.golang.org/genproto v0.0.0-20230123190316-2c411cf9d197/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM=
google.golang.org/grpc v1.52.0 h1:kd48UiU7EHsV4rnLyOJRuP/Il/UHE7gdDAQ+SZI7nZk=
google.golang.org/grpc v1.52.0/go.mod h1:pu6fVzoFb+NBYNAvQL08ic+lvB2IojljRYuun5vorUY=
google.golang.org/genproto v0.0.0-20230202175211-008b39050e57 h1:vArvWooPH749rNHpBGgVl+U9B9dATjiEhJzcWGlovNs=
google.golang.org/genproto v0.0.0-20230202175211-008b39050e57/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM=
google.golang.org/grpc v1.52.3 h1:pf7sOysg4LdgBqduXveGKrcEwbStiK2rtfghdzlUYDQ=
google.golang.org/grpc v1.52.3/go.mod h1:pu6fVzoFb+NBYNAvQL08ic+lvB2IojljRYuun5vorUY=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
176 changes: 62 additions & 114 deletions go.mod

Large diffs are not rendered by default.

169 changes: 82 additions & 87 deletions go.sum

Large diffs are not rendered by default.

51 changes: 1 addition & 50 deletions hack/go.mod.default
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ replace (
github.com/ajstarks/deck => github.com/ajstarks/deck latest
github.com/ajstarks/deck/generate => github.com/ajstarks/deck/generate latest
github.com/ajstarks/svgo => github.com/ajstarks/svgo latest
github.com/alecthomas/units => github.com/alecthomas/units latest
github.com/alexflint/go-filemutex => github.com/alexflint/go-filemutex latest
github.com/antihax/optional => github.com/antihax/optional latest
github.com/armon/circbuf => github.com/armon/circbuf latest
github.com/armon/go-metrics => github.com/armon/go-metrics latest
Expand Down Expand Up @@ -100,8 +98,6 @@ replace (
github.com/chzyer/logex => github.com/chzyer/logex latest
github.com/chzyer/readline => github.com/chzyer/readline latest
github.com/chzyer/test => github.com/chzyer/test latest
github.com/cilium/ebpf => github.com/cilium/ebpf latest
github.com/circonus-labs/circonus-gometrics => github.com/circonus-labs/circonus-gometrics latest
github.com/cncf/udpa/go => github.com/cncf/udpa/go latest
github.com/cncf/xds/go => github.com/cncf/xds/go latest
github.com/cockroachdb/apd => github.com/cockroachdb/apd latest
Expand Down Expand Up @@ -139,9 +135,6 @@ replace (
github.com/dennwc/varint => github.com/dennwc/varint latest
github.com/devigned/tab => github.com/devigned/tab latest
github.com/dgryski/go-rendezvous => github.com/dgryski/go-rendezvous latest
github.com/dgryski/go-sip13 => github.com/dgryski/go-sip13 latest
github.com/digitalocean/godo => github.com/digitalocean/godo latest
github.com/dimchansky/utfbom => github.com/dimchansky/utfbom latest
github.com/dnaeon/go-vcr => github.com/dnaeon/go-vcr latest
github.com/docker/cli => github.com/docker/cli latest
github.com/docker/distribution => github.com/docker/distribution latest
Expand All @@ -153,22 +146,18 @@ replace (
github.com/docker/go-units => github.com/docker/go-units latest
github.com/docopt/docopt-go => github.com/docopt/docopt-go latest
github.com/dustin/go-humanize => github.com/dustin/go-humanize latest
github.com/dvyukov/go-fuzz => github.com/dvyukov/go-fuzz latest
github.com/edsrzf/mmap-go => github.com/edsrzf/mmap-go latest
github.com/elazarl/goproxy => github.com/elazarl/goproxy latest
github.com/emicklei/go-restful => github.com/emicklei/go-restful latest
github.com/emicklei/go-restful/v3 => github.com/emicklei/go-restful/v3 latest
github.com/envoyproxy/go-control-plane => github.com/envoyproxy/go-control-plane latest
github.com/envoyproxy/protoc-gen-validate => github.com/envoyproxy/protoc-gen-validate latest
github.com/evanphx/json-patch => github.com/evanphx/json-patch latest
github.com/fatih/color => github.com/fatih/color latest
github.com/felixge/httpsnoop => github.com/felixge/httpsnoop latest
github.com/fogleman/gg => github.com/fogleman/gg latest
github.com/form3tech-oss/jwt-go => github.com/form3tech-oss/jwt-go latest
github.com/fortytw2/leaktest => github.com/fortytw2/leaktest latest
github.com/frankban/quicktest => github.com/frankban/quicktest latest
github.com/fsnotify/fsnotify => github.com/fsnotify/fsnotify latest
github.com/ghodss/yaml => github.com/ghodss/yaml latest
github.com/gin-contrib/sse => github.com/gin-contrib/sse latest
github.com/gin-gonic/gin => github.com/gin-gonic/gin latest
github.com/go-errors/errors => github.com/go-errors/errors latest
Expand All @@ -185,8 +174,6 @@ replace (
github.com/go-logr/logr => github.com/go-logr/logr latest
github.com/go-logr/stdr => github.com/go-logr/stdr latest
github.com/go-logr/zapr => github.com/go-logr/zapr latest
github.com/go-openapi/analysis => github.com/go-openapi/analysis latest
github.com/go-openapi/errors => github.com/go-openapi/errors latest
github.com/go-openapi/jsonpointer => github.com/go-openapi/jsonpointer latest
github.com/go-openapi/jsonreference => github.com/go-openapi/jsonreference latest
github.com/go-openapi/loads => github.com/go-openapi/loads latest
Expand Down Expand Up @@ -245,10 +232,6 @@ replace (
github.com/google/uuid => github.com/google/uuid latest
github.com/google/wire => github.com/google/wire latest
github.com/googleapis/gax-go/v2 => github.com/googleapis/gax-go/v2 latest
github.com/googleapis/go-type-adapters => github.com/googleapis/go-type-adapters latest
github.com/gophercloud/gophercloud => github.com/gophercloud/gophercloud latest
github.com/gopherjs/gopherjs => github.com/gopherjs/gopherjs latest
github.com/gorilla/context => github.com/gorilla/context latest
github.com/gorilla/mux => github.com/gorilla/mux latest
github.com/gorilla/websocket => github.com/gorilla/websocket latest
github.com/grafana/regexp => github.com/grafana/regexp latest
Expand Down Expand Up @@ -300,7 +283,6 @@ replace (
github.com/jmespath/go-jmespath/internal/testify => github.com/jmespath/go-jmespath/internal/testify latest
github.com/jmoiron/sqlx => github.com/jmoiron/sqlx latest
github.com/joho/godotenv => github.com/joho/godotenv latest
github.com/jonboulle/clockwork => github.com/jonboulle/clockwork latest
github.com/josharian/intern => github.com/josharian/intern latest
github.com/json-iterator/go => github.com/json-iterator/go latest
github.com/jstemmer/go-junit-report => github.com/jstemmer/go-junit-report latest
Expand Down Expand Up @@ -333,10 +315,6 @@ replace (
github.com/mattn/go-shellwords => github.com/mattn/go-shellwords latest
github.com/mattn/go-sqlite3 => github.com/mattn/go-sqlite3 latest
github.com/matttproud/golang_protobuf_extensions => github.com/matttproud/golang_protobuf_extensions latest
github.com/miekg/dns => github.com/miekg/dns latest
github.com/miekg/pkcs11 => github.com/miekg/pkcs11 latest
github.com/mistifyio/go-zfs => github.com/mistifyio/go-zfs latest
github.com/mitchellh/cli => github.com/mitchellh/cli latest
github.com/mitchellh/colorstring => github.com/mitchellh/colorstring latest
github.com/mitchellh/go-homedir => github.com/mitchellh/go-homedir latest
github.com/mitchellh/go-wordwrap => github.com/mitchellh/go-wordwrap latest
Expand All @@ -355,22 +333,12 @@ replace (
github.com/morikuni/aec => github.com/morikuni/aec latest
github.com/mrunalp/fileutils => github.com/mrunalp/fileutils latest
github.com/munnerz/goautoneg => github.com/munnerz/goautoneg latest
github.com/mwitkow/go-conntrack => github.com/mwitkow/go-conntrack latest
github.com/mxk/go-flowrate => github.com/mxk/go-flowrate latest
github.com/niemeyer/pretty => github.com/niemeyer/pretty latest
github.com/nxadm/tail => github.com/nxadm/tail latest
github.com/oklog/run => github.com/oklog/run latest
github.com/oklog/ulid => github.com/oklog/ulid latest
github.com/onsi/ginkgo => github.com/onsi/ginkgo latest
github.com/onsi/gomega => github.com/onsi/gomega latest
github.com/opencontainers/go-digest => github.com/opencontainers/go-digest latest
github.com/opencontainers/image-spec => github.com/opencontainers/image-spec latest
github.com/opencontainers/runc => github.com/opencontainers/runc latest
github.com/opencontainers/runtime-spec => github.com/opencontainers/runtime-spec latest
github.com/opencontainers/selinux => github.com/opencontainers/selinux latest
github.com/opentracing/opentracing-go => github.com/opentracing/opentracing-go latest
github.com/pascaldekloe/goe => github.com/pascaldekloe/goe latest
github.com/pelletier/go-toml => github.com/pelletier/go-toml latest
github.com/peterbourgon/diskv => github.com/peterbourgon/diskv latest
github.com/phpdave11/gofpdf => github.com/phpdave11/gofpdf latest
github.com/phpdave11/gofpdi => github.com/phpdave11/gofpdi latest
Expand Down Expand Up @@ -426,18 +394,10 @@ replace (
github.com/spf13/cast => github.com/spf13/cast latest
github.com/spf13/cobra => github.com/spf13/cobra latest
github.com/spf13/pflag => github.com/spf13/pflag latest
github.com/stefanberger/go-pkcs11uri => github.com/stefanberger/go-pkcs11uri latest
github.com/stoewer/go-strcase => github.com/stoewer/go-strcase latest
github.com/stretchr/objx => github.com/stretchr/objx latest
github.com/stretchr/testify => github.com/stretchr/testify latest
github.com/syndtr/gocapability => github.com/syndtr/gocapability latest
github.com/tchap/go-patricia => github.com/tchap/go-patricia latest
github.com/tidwall/pretty => github.com/tidwall/pretty latest
github.com/tmc/grpc-websocket-proxy => github.com/tmc/grpc-websocket-proxy latest
github.com/tv42/httpunix => github.com/tv42/httpunix latest
github.com/ugorji/go => github.com/ugorji/go latest
github.com/ugorji/go/codec => github.com/ugorji/go/codec latest
github.com/urfave/cli => github.com/urfave/cli latest
github.com/vdaas/vald-client-go => github.com/vdaas/vald-client-go latest
github.com/vishvananda/netlink => github.com/vishvananda/netlink latest
github.com/vishvananda/netns => github.com/vishvananda/netns latest
Expand All @@ -449,8 +409,6 @@ replace (
github.com/xeipuuv/gojsonschema => github.com/xeipuuv/gojsonschema latest
github.com/xiang90/probing => github.com/xiang90/probing latest
github.com/xlab/treeprint => github.com/xlab/treeprint latest
github.com/youmark/pkcs8 => github.com/youmark/pkcs8 latest
github.com/yuin/goldmark => github.com/yuin/goldmark latest
github.com/zeebo/assert => github.com/zeebo/assert latest
github.com/zeebo/xxh3 => github.com/zeebo/xxh3 latest
go.etcd.io/bbolt => go.etcd.io/bbolt latest
Expand All @@ -464,7 +422,7 @@ replace (
go.mongodb.org/mongo-driver => go.mongodb.org/mongo-driver latest
go.mozilla.org/pkcs7 => go.mozilla.org/pkcs7 latest
go.opencensus.io => go.opencensus.io latest
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc => go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc latest
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc => go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.37.0
go.opentelemetry.io/otel => go.opentelemetry.io/otel v1.11.1
go.opentelemetry.io/otel/exporters/otlp/internal/retry => go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.11.1
go.opentelemetry.io/otel/exporters/otlp/otlpmetric => go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.33.0
Expand All @@ -482,8 +440,6 @@ replace (
go.uber.org/goleak => go.uber.org/goleak latest
go.uber.org/multierr => go.uber.org/multierr latest
go.uber.org/zap => go.uber.org/zap latest
go4.org/intern => go4.org/intern latest
go4.org/unsafe/assume-no-moving-gc => go4.org/unsafe/assume-no-moving-gc latest
gocloud.dev => gocloud.dev latest
golang.org/x/crypto => golang.org/x/crypto latest
golang.org/x/exp => golang.org/x/exp latest
Expand Down Expand Up @@ -516,17 +472,12 @@ replace (
gopkg.in/gcfg.v1 => gopkg.in/gcfg.v1 latest
gopkg.in/inconshreveable/log15.v2 => gopkg.in/inconshreveable/log15.v2 latest
gopkg.in/inf.v0 => gopkg.in/inf.v0 latest
gopkg.in/ini.v1 => gopkg.in/ini.v1 latest
gopkg.in/natefinch/lumberjack.v2 => gopkg.in/natefinch/lumberjack.v2 latest
gopkg.in/square/go-jose.v2 => gopkg.in/square/go-jose.v2 latest
gopkg.in/telebot.v3 => gopkg.in/telebot.v3 latest
gopkg.in/tomb.v1 => gopkg.in/tomb.v1 latest
gopkg.in/warnings.v0 => gopkg.in/warnings.v0 latest
gopkg.in/yaml.v2 => gopkg.in/yaml.v2 latest
gopkg.in/yaml.v3 => gopkg.in/yaml.v3 latest
gotest.tools/v3 => gotest.tools/v3 latest
honnef.co/go/tools => honnef.co/go/tools latest
inet.af/netaddr => inet.af/netaddr latest
k8s.io/api => k8s.io/api v0.26.0
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.26.0
k8s.io/apimachinery => k8s.io/apimachinery v0.26.0
Expand Down
5 changes: 5 additions & 0 deletions internal/errors/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,9 @@ var (

// ErrCAPINotImplemented represents an error that the function is not implemented in C API.
ErrCAPINotImplemented = New("not implemented in C API")

// ErrObjectNotFound represents a function to generate an error that the object is not found.
ErrObjectNotFound = func(err error, uuid string) error {
return Wrapf(err, "uuid %s's object not found", uuid)
}
)
109 changes: 109 additions & 0 deletions internal/errors/agent_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
//
// Copyright (C) 2019-2023 vdaas.org vald team <[email protected]>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

// Package errors
package errors

import (
"testing"
)

func TestErrObjectNotFound(t *testing.T) {
type args struct {
err error
uuid string
}
type want struct {
want error
}
type test struct {
name string
args args
want want
checkFunc func(want, error) error
beforeFunc func(args)
afterFunc func(args)
}
defaultCheckFunc := func(w want, got error) error {
if !Is(got, w.want) {
return Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want)
}
return nil
}
tests := []test{
{
name: "return a wrapped ErrObjectNotFound error when err is agent error and uuid is 550e8400-e29b-41d4",
args: args{
err: New("agent error"),
uuid: "550e8400-e29b-41d4",
},
want: want{
want: New("uuid 550e8400-e29b-41d4's object not found: agent error"),
},
},
{
name: "return a wrapped ErrObjectNotFound error when err is agent error and uuid is empty",
args: args{
err: New("agent error"),
uuid: "",
},
want: want{
want: New("uuid 's object not found: agent error"),
},
},
{
name: "return an ErrObjectNotFound error when err is nil and uuid is 550e8400-e29b-41d4",
args: args{
err: nil,
uuid: "550e8400-e29b-41d4",
},
want: want{
want: New("uuid 550e8400-e29b-41d4's object not found"),
},
},
{
name: "return an ErrObjectNotFound error when err is nil and uuid is empty",
args: args{
err: nil,
uuid: "",
},
want: want{
want: New("uuid 's object not found"),
},
},
}

for _, tc := range tests {
test := tc
t.Run(test.name, func(tt *testing.T) {
if test.beforeFunc != nil {
test.beforeFunc(test.args)
}
if test.afterFunc != nil {
defer test.afterFunc(test.args)
}
checkFunc := test.checkFunc
if test.checkFunc == nil {
checkFunc = defaultCheckFunc
}

got := ErrObjectNotFound(test.args.err, test.args.uuid)
if err := checkFunc(test.want, got); err != nil {
tt.Errorf("error = %v", err)
}
})
}
}
5 changes: 0 additions & 5 deletions internal/errors/ngt.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ var (
return Errorf("ngt uuid %s's object id not found", uuid)
}

// ErrObjectNotFound represents a function to generate an error that the object is not found.
ErrObjectNotFound = func(err error, uuid string) error {
return Wrapf(err, "ngt uuid %s's object not found", uuid)
}

// ErrRemoveRequestedBeforeIndexing represents a function to generate an error that the object is not indexed so can not remove it.
ErrRemoveRequestedBeforeIndexing = func(oid uint) error {
return Errorf("object id %d is not indexed we cannot remove it", oid)
Expand Down
Loading

0 comments on commit c83a852

Please sign in to comment.