diff --git a/projects/knative/Dockerfile b/projects/knative/Dockerfile index b576c04c8..2f14c21d3 100644 --- a/projects/knative/Dockerfile +++ b/projects/knative/Dockerfile @@ -19,9 +19,4 @@ RUN git clone --depth 1 https://github.com/cncf/cncf-fuzzing RUN git clone --depth 1 https://github.com/knative/pkg RUN git clone --depth 1 https://github.com/knative/serving WORKDIR $SRC/pkg -COPY build.sh \ - json_fuzzer.go \ - fuzz_activatornet.go \ - fuzz_pkg_metrics.go \ - fuzz_pkg_websocket.go \ - $SRC/ +COPY build.sh $SRC/ diff --git a/projects/knative/fuzz_activatornet.go b/projects/knative/fuzz_activatornet.go deleted file mode 100644 index ef35c58f4..000000000 --- a/projects/knative/fuzz_activatornet.go +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2022 Google LLC -// -// 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 -// -// http://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 net - -import ( - "context" - "os" - "testing" - - fuzz "github.com/AdaLogics/go-fuzz-headers" - "go.uber.org/zap" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/sets" - - pkgnet "knative.dev/networking/pkg/apis/networking" - "knative.dev/serving/pkg/queue" - - "knative.dev/pkg/injection" - "k8s.io/client-go/rest" - "k8s.io/client-go/tools/record" - - "knative.dev/pkg/controller" -) - -func NewFuzzLogger() *zap.SugaredLogger { - var config zap.Config - config = zap.NewProductionConfig() - // Config customization goes here if any - config.OutputPaths = []string{os.DevNull} - logger, err := config.Build() - if err != nil { - panic(err) - } - return logger.Named("knative-log").Sugar() -} - -func FuzzNewRevisionThrottler(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - ff := fuzz.NewConsumer(data) - - revName := types.NamespacedName{} - ff.GenerateStruct(&revName) - - containerConcurrency, err := ff.GetInt() - if err != nil { - t.Skip() - } - params := queue.BreakerParams{} - ff.GenerateStruct(¶ms) - if params.QueueDepth <= 0 { - t.Skip() - } - if params.MaxConcurrency < 0 { - t.Skip() - } - if params.InitialCapacity < 0 || params.InitialCapacity > params.MaxConcurrency { - t.Skip() - } - logger := NewFuzzLogger() - rt := newRevisionThrottler(revName, containerConcurrency%10, pkgnet.ServicePortNameHTTP1, params, logger) - - //ctx := context.Background() - ctx, cancel := SetupFakeContextWithCancel() - defer cancel() - throttler := newTestThrottler(ctx) - throttler.revisionThrottlers[revName] = rt - - update := revisionDestsUpdate{ - Rev: revName, - ClusterIPDest: "", - Dests: sets.NewString("ip3", "ip2", "ip1"), - } - throttler.handleUpdate(update) - }) -} - -func SetupFakeContextWithCancel() (context.Context, context.CancelFunc) { - ctx, c := context.WithCancel(context.Background()) - ctx = controller.WithEventRecorder(ctx, record.NewFakeRecorder(1000)) - ctx, _ = injection.Fake.SetupInformers(ctx, &rest.Config{}) - return ctx, c -} diff --git a/projects/knative/fuzz_pkg_metrics.go b/projects/knative/fuzz_pkg_metrics.go deleted file mode 100644 index f1354b151..000000000 --- a/projects/knative/fuzz_pkg_metrics.go +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2022 Google LLC -// -// 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 -// -// http://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 metrics - -import ( - fuzz "github.com/AdaLogics/go-fuzz-headers" - corev1 "k8s.io/api/core/v1" - "testing" -) - -func FuzzNewObservabilityConfigFromConfigMap(f *testing.F) { - f.Fuzz(func(t *testing.T, configMapData []byte) { - ff := fuzz.NewConsumer(configMapData) - cm := &corev1.ConfigMap{} - ff.GenerateStruct(cm) - _, _ = NewObservabilityConfigFromConfigMap(cm) - }) -} diff --git a/projects/knative/fuzz_pkg_websocket.go b/projects/knative/fuzz_pkg_websocket.go deleted file mode 100644 index 3e97cd14a..000000000 --- a/projects/knative/fuzz_pkg_websocket.go +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2022 Google LLC -// -// 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 -// -// http://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 websocket - -import ( - "github.com/gorilla/websocket" - "testing" -) - -func FuzzSendRawMessage(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - spy := &inspectableConnection{ - writeMessageCalls: make(chan struct{}, 1), - } - - conn := newConnection(staticConnFactory(spy), nil) - conn.connect() - - if got := conn.Status(); got != nil { - t.Skip() - } - - if got := conn.SendRaw(websocket.BinaryMessage, data); got != nil { - t.Skip() - } - if len(spy.writeMessageCalls) != 1 { - t.Fatalf("Expected 'WriteMessage' to be called once, but was called %v times", spy.writeMessageCalls) - } - }) -} diff --git a/projects/knative/json_fuzzer.go b/projects/knative/json_fuzzer.go deleted file mode 100644 index 1c3f694c1..000000000 --- a/projects/knative/json_fuzzer.go +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2022 Google LLC -// -// 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 -// -// http://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 json - -func FuzzJsonDecode(data []byte) int { - Decode(data, &fixture{}, false) - return 1 -}