Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.24.0
require (
fortio.org/fortio v1.68.0
fortio.org/log v1.17.1
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24
github.com/Masterminds/semver/v3 v3.3.1
github.com/andybalholm/brotli v1.1.1
github.com/avast/retry-go v3.0.0+incompatible
Expand Down Expand Up @@ -107,7 +108,6 @@ require (
fortio.org/version v1.0.4 // indirect
github.com/4meepo/tagalign v1.4.1 // indirect
github.com/Abirdcfly/dupword v0.1.3 // indirect
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
github.com/Antonboom/errname v1.0.0 // indirect
github.com/Antonboom/nilnil v1.0.1 // indirect
github.com/Antonboom/testifylint v1.5.2 // indirect
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/egctl/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func translate(w io.Writer, inFile, inType string, outTypes []string, output, re
result.Xds = res
}
if outType == irType {
res, err := translateGatewayAPIToIR(resources)
res, err := TranslateGatewayAPIToIR(resources)
if err != nil {
return err
}
Expand All @@ -265,7 +265,7 @@ func translate(w io.Writer, inFile, inType string, outTypes []string, output, re
return fmt.Errorf("unable to find translate from input type %s to output type %s", inType, outTypes)
}

func translateGatewayAPIToIR(resources *resource.Resources) (*gatewayapi.TranslateResult, error) {
func TranslateGatewayAPIToIR(resources *resource.Resources) (*gatewayapi.TranslateResult, error) {
if resources.GatewayClass == nil {
return nil, fmt.Errorf("the GatewayClass resource is required")
}
Expand Down
42 changes: 42 additions & 0 deletions test/fuzz/ir_fuzz_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright Envoy Gateway Authors
// SPDX-License-Identifier: Apache-2.0
// The full text of the Apache license is available in the LICENSE file at
// the root of the repo.

package fuzz

import (
"testing"

fuzz "github.com/AdaLogics/go-fuzz-headers"
"sigs.k8s.io/yaml"

"github.com/envoyproxy/gateway/internal/cmd/egctl"
"github.com/envoyproxy/gateway/internal/gatewayapi/resource"
)

func FuzzGatewayAPIToIR(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fc := fuzz.NewConsumer(data)
resources := &resource.Resources{}
if err := fc.GenerateStruct(resources); err != nil {
return
}
addMissingResources, err := fc.GetBool()
if err != nil {
return
}

// Populate default values
yamlBytes, err := yaml.Marshal(resources)
if err != nil {
return
}
rs, err := resource.LoadResourcesFromYAMLBytes(yamlBytes, addMissingResources)
if err != nil {
return
}

_, _ = egctl.TranslateGatewayAPIToIR(rs)
})
}
5 changes: 5 additions & 0 deletions tools/make/env.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ IMAGE_NAME ?= gateway-dev
IMAGE ?= ${REGISTRY}/${IMAGE_NAME}
# Tag is the tag to use for build and push image targets.
TAG ?= $(REV)

# Fuzzing variables

# FUZZ_TIME is the time to run the fuzzer for
FUZZ_TIME ?= 5s
9 changes: 9 additions & 0 deletions tools/make/golang.mk
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ go.build: $(addprefix go.build., $(addprefix $(PLATFORM)., $(BINS)))
.PHONY: go.build.multiarch
go.build.multiarch: $(foreach p,$(PLATFORMS),$(addprefix go.build., $(addprefix $(p)., $(BINS))))

.PHONY: go.test.fuzz
go.test.fuzz: ## Run all fuzzers in the test/fuzz folder one by one
@$(LOG_TARGET)
@for dir in $$(go list -f '{{.Dir}}' ./test/fuzz/...); do \
for test in $$(go test -list=Fuzz.* $$dir | grep ^Fuzz); do \
echo "go test -fuzz=$$test -fuzztime=$(FUZZ_TIME)"; \
(cd $$dir && go test -fuzz=$$test -fuzztime=$(FUZZ_TIME)) || exit 1; \
done; \
done

.PHONY: go.test.unit
go.test.unit: ## Run go unit tests
Expand Down
Loading