istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pilot/pkg/networking/core/fuzz_test.go (about)

     1  // Copyright Istio Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package core
    16  
    17  import (
    18  	"testing"
    19  
    20  	route "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
    21  
    22  	"istio.io/istio/pilot/pkg/model"
    23  	"istio.io/istio/pkg/fuzz"
    24  )
    25  
    26  func FuzzBuildGatewayListeners(f *testing.F) {
    27  	f.Fuzz(func(t *testing.T, patchCount int, hostname string, data []byte) {
    28  		defer fuzz.Finalize()
    29  		fg := fuzz.New(t, data)
    30  		proxy := fuzz.Struct[*model.Proxy](fg)
    31  		to := fuzz.Struct[TestOptions](fg)
    32  		lb := fuzz.Struct[*ListenerBuilder](fg)
    33  		cg := NewConfigGenTest(t, to)
    34  		lb.node = cg.SetupProxy(proxy)
    35  		lb.push = cg.PushContext()
    36  		cg.ConfigGen.buildGatewayListeners(lb)
    37  	})
    38  }
    39  
    40  func FuzzBuildSidecarOutboundHTTPRouteConfig(f *testing.F) {
    41  	f.Fuzz(func(t *testing.T, patchCount int, hostname string, data []byte) {
    42  		defer fuzz.Finalize()
    43  		fg := fuzz.New(t, data)
    44  		proxy := fuzz.Struct[*model.Proxy](fg)
    45  		to := fuzz.Struct[TestOptions](fg)
    46  		cg := NewConfigGenTest(t, to)
    47  		req := fuzz.Struct[*model.PushRequest](fg)
    48  		req.Push = cg.PushContext()
    49  		vHostCache := make(map[int][]*route.VirtualHost)
    50  		cg.ConfigGen.buildSidecarOutboundHTTPRouteConfig(cg.SetupProxy(proxy), req, "80", vHostCache, nil, nil)
    51  	})
    52  }
    53  
    54  func FuzzBuildSidecarOutboundListeners(f *testing.F) {
    55  	f.Fuzz(func(t *testing.T, patchCount int, hostname string, data []byte) {
    56  		defer fuzz.Finalize()
    57  		fg := fuzz.New(t, data)
    58  		proxy := fuzz.Struct[*model.Proxy](fg)
    59  		to := fuzz.Struct[TestOptions](fg)
    60  		cg := NewConfigGenTest(t, to)
    61  		req := fuzz.Struct[*model.PushRequest](fg)
    62  		req.Push = cg.PushContext()
    63  		NewListenerBuilder(proxy, cg.env.PushContext()).buildSidecarOutboundListeners(cg.SetupProxy(proxy), cg.env.PushContext())
    64  	})
    65  }