-
Notifications
You must be signed in to change notification settings - Fork 750
Expand file tree
/
Copy pathxds_fuzz_test.go
More file actions
130 lines (119 loc) · 2.7 KB
/
xds_fuzz_test.go
File metadata and controls
130 lines (119 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// 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 (
"strings"
"testing"
"github.com/envoyproxy/gateway/internal/cmd/egctl"
"github.com/envoyproxy/gateway/internal/gatewayapi/resource"
)
func FuzzGatewayAPIToXDS(f *testing.F) {
baseYAML := `apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
name: eg
spec:
controllerName: gateway.envoyproxy.io/gatewayclass-controller
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: eg
namespace: default
spec:
gatewayClassName: eg
listeners:
- name: http
protocol: HTTP
port: 80
`
backendYAML := `---
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: Backend
metadata:
name: provided-backend
namespace: default
spec:
endpoints:
- ip:
address: 0.0.0.0
port: 8000
`
grpcRoute := `---
apiVersion: gateway.networking.k8s.io/v1
kind: GRPCRoute
metadata:
name: backend
namespace: default
spec:
parentRefs:
- name: eg
sectionName: grpc
hostnames:
- "www.grpc-example.com"
rules:
- matches:
- method:
service: com.example.Things
method: DoThing
headers:
- name: com.example.Header
value: foobar
backendRefs:
- name: provided-backend
port: 9000
`
httpRoute := `---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: backend
namespace: default
spec:
parentRefs:
- name: eg
hostnames:
- "www.example.com"
rules:
- backendRefs:
- name: provided-backend
port: 8000
`
udpRoute := `---
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: UDPRoute
metadata:
name: backend
namespace: default
spec:
parentRefs:
- name: eg
sectionName: udp
rules:
- backendRefs:
- name: provided-backend
port: 3000
`
// Add seed corpus for golang native fuzzing. OSS-Fuzz will not take these corpus into consideration.
f.Add([]byte(baseYAML + grpcRoute + backendYAML))
f.Add([]byte(baseYAML + httpRoute + backendYAML))
f.Add([]byte(baseYAML + udpRoute + backendYAML))
f.Fuzz(func(t *testing.T, b []byte) {
rs, err := resource.LoadResourcesFromYAMLBytes(b, true, nil)
if err != nil {
return
}
opts := &egctl.TranslationOptions{
GlobalRateLimitEnabled: true,
EndpointRoutingDisabled: true,
EnvoyPatchPolicyEnabled: true,
BackendEnabled: true,
}
_, err = egctl.TranslateGatewayAPIToXds("default", "cluster.local", "all", rs, opts)
if err != nil && strings.Contains(err.Error(), "failed to translate xds") {
t.Fatalf("%v", err)
}
})
}