...

Source file src/github.com/linkerd/linkerd2/test/fuzzing/fuzzers.go

Documentation: github.com/linkerd/linkerd2/test/fuzzing

     1  package fuzzing
     2  
     3  import (
     4  	fuzz "github.com/AdaLogics/go-fuzz-headers"
     5  	"github.com/linkerd/linkerd2/pkg/healthcheck"
     6  	"github.com/linkerd/linkerd2/pkg/util"
     7  	corev1 "k8s.io/api/core/v1"
     8  )
     9  
    10  // FuzzParsePorts fuzzes the ParsePorts function.
    11  func FuzzParsePorts(data []byte) int {
    12  	_ = util.ParsePorts(string(data))
    13  	return 1
    14  }
    15  
    16  // FuzzParseContainerOpaquePorts fuzzes the ParseContainerOpaquePorts function.
    17  func FuzzParseContainerOpaquePorts(data []byte) int {
    18  	f := fuzz.NewConsumer(data)
    19  
    20  	qtyOfContainers, err := f.GetInt()
    21  	if err != nil {
    22  		return 0
    23  	}
    24  	qtyOfContainers %= 20
    25  
    26  	containers := make([]corev1.Container, 0)
    27  	for i := 0; i < qtyOfContainers; i++ {
    28  		newContainer := corev1.Container{}
    29  		err = f.GenerateStruct(&newContainer)
    30  		if err != nil {
    31  			return 0
    32  		}
    33  		containers = append(containers, newContainer)
    34  	}
    35  	override, err := f.GetString()
    36  	if err != nil {
    37  		return 0
    38  	}
    39  	_ = util.ParseContainerOpaquePorts(override, util.GetNamedPorts(containers))
    40  	return 1
    41  }
    42  
    43  // FuzzHealthCheck fuzzes the HealthCheck method for the healthchecker.
    44  func FuzzHealthCheck(data []byte) int {
    45  	f := fuzz.NewConsumer(data)
    46  	options := &healthcheck.Options{}
    47  	err := f.GenerateStruct(options)
    48  	if err != nil {
    49  		return 0
    50  	}
    51  	_ = healthcheck.NewHealthChecker([]healthcheck.CategoryID{healthcheck.KubernetesAPIChecks}, options)
    52  	return 1
    53  }
    54  

View as plain text