Skip to content

Commit cda9df1

Browse files
committed
Store all necessary information for roundtrip in APIBinding annotations
On-behalf-of: SAP <[email protected]> Signed-off-by: Marvin Beckers <[email protected]>
1 parent e44c468 commit cda9df1

File tree

3 files changed

+490
-18
lines changed

3 files changed

+490
-18
lines changed

sdk/apis/apis/fuzzer/fuzzer.go

Lines changed: 222 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ import (
3030
)
3131

3232
// Funcs returns the fuzzer functions for the apiserverinternal api group.
33-
func Funcs(codecs runtimeserializer.CodecFactory) []interface{} {
34-
return []interface{}{
33+
func Funcs(codecs runtimeserializer.CodecFactory) []any {
34+
return []any{
3535
func(r *metav1.ManagedFieldsEntry, c fuzz.Continue) {
3636
// match the fuzzer default content for runtime.Object
3737
r.APIVersion = "v1"
@@ -91,6 +91,226 @@ func Funcs(codecs runtimeserializer.CodecFactory) []interface{} {
9191
})
9292
}
9393
},
94+
func(r *v1alpha2.APIBinding, c fuzz.Continue) {
95+
c.FuzzNoCustom(r)
96+
r.TypeMeta = metav1.TypeMeta{}
97+
r.Kind = ""
98+
r.APIVersion = ""
99+
},
100+
func(r *v1alpha1.APIBinding, c fuzz.Continue) {
101+
c.FuzzNoCustom(r)
102+
r.TypeMeta = metav1.TypeMeta{}
103+
r.Kind = ""
104+
r.APIVersion = ""
105+
},
106+
func(r *v1alpha1.APIBindingSpec, c fuzz.Continue) {
107+
c.FuzzNoCustom(r)
108+
109+
r.PermissionClaims = nil
110+
for range c.Intn(5) {
111+
group := nonEmptyString(c.RandString)
112+
resource := nonEmptyString(c.RandString)
113+
identityHash := nonEmptyString(c.RandString)
114+
115+
apc := v1alpha1.AcceptablePermissionClaim{
116+
PermissionClaim: v1alpha1.PermissionClaim{
117+
GroupResource: v1alpha1.GroupResource{
118+
Group: group,
119+
Resource: resource,
120+
},
121+
IdentityHash: identityHash,
122+
All: c.RandBool(),
123+
},
124+
}
125+
126+
if !apc.All {
127+
apc.ResourceSelector = []v1alpha1.ResourceSelector{}
128+
for range c.Intn(5) + 1 {
129+
apc.ResourceSelector = append(apc.ResourceSelector, v1alpha1.ResourceSelector{Name: nonEmptyString(c.RandString), Namespace: nonEmptyString(c.RandString)})
130+
}
131+
}
132+
133+
r.PermissionClaims = append(r.PermissionClaims, apc)
134+
}
135+
},
136+
func(r *v1alpha1.APIBindingStatus, c fuzz.Continue) {
137+
c.FuzzNoCustom(r)
138+
r.AppliedPermissionClaims = nil
139+
for range c.Intn(5) {
140+
group := nonEmptyString(c.RandString)
141+
resource := nonEmptyString(c.RandString)
142+
identityHash := nonEmptyString(c.RandString)
143+
144+
pc := v1alpha1.PermissionClaim{
145+
GroupResource: v1alpha1.GroupResource{
146+
Group: group,
147+
Resource: resource,
148+
},
149+
IdentityHash: identityHash,
150+
All: c.RandBool(),
151+
}
152+
153+
if !pc.All {
154+
pc.ResourceSelector = []v1alpha1.ResourceSelector{}
155+
for range c.Intn(5) + 1 {
156+
pc.ResourceSelector = append(pc.ResourceSelector, v1alpha1.ResourceSelector{Name: nonEmptyString(c.RandString), Namespace: nonEmptyString(c.RandString)})
157+
}
158+
}
159+
160+
r.AppliedPermissionClaims = append(r.AppliedPermissionClaims, pc)
161+
}
162+
r.ExportPermissionClaims = nil
163+
for range c.Intn(5) {
164+
group := nonEmptyString(c.RandString)
165+
resource := nonEmptyString(c.RandString)
166+
identityHash := nonEmptyString(c.RandString)
167+
168+
pc := v1alpha1.PermissionClaim{
169+
GroupResource: v1alpha1.GroupResource{
170+
Group: group,
171+
Resource: resource,
172+
},
173+
IdentityHash: identityHash,
174+
All: c.RandBool(),
175+
}
176+
177+
if !pc.All {
178+
pc.ResourceSelector = []v1alpha1.ResourceSelector{}
179+
for range c.Intn(5) + 1 {
180+
pc.ResourceSelector = append(pc.ResourceSelector, v1alpha1.ResourceSelector{Name: nonEmptyString(c.RandString), Namespace: nonEmptyString(c.RandString)})
181+
}
182+
}
183+
r.ExportPermissionClaims = append(r.ExportPermissionClaims, pc)
184+
}
185+
},
186+
func(r *v1alpha2.APIBindingSpec, c fuzz.Continue) {
187+
c.FuzzNoCustom(r)
188+
r.PermissionClaims = nil
189+
for range c.Intn(5) {
190+
group := nonEmptyString(c.RandString)
191+
resource := nonEmptyString(c.RandString)
192+
identityHash := nonEmptyString(c.RandString)
193+
verbs := []string{}
194+
numVerbs := c.Intn(5) + 1 // the lower bound is 0, but 0 verbs is not a valid combination
195+
for range numVerbs {
196+
verbs = append(verbs, nonEmptyString(c.RandString))
197+
}
198+
199+
selector := v1alpha2.PermissionClaimSelector{}
200+
201+
switch c.Intn(3) {
202+
case 0:
203+
selector.MatchAll = true
204+
case 1:
205+
labels := make(map[string]string)
206+
numLabels := c.Intn(5) + 1
207+
for range numLabels {
208+
labels[nonEmptyString(c.RandString)] = nonEmptyString(c.RandString)
209+
}
210+
selector.MatchLabels = labels
211+
default:
212+
numExpressions := c.Intn(5) + 1
213+
expressions := make([]metav1.LabelSelectorRequirement, numExpressions)
214+
for range numExpressions {
215+
expressions = append(expressions, metav1.LabelSelectorRequirement{
216+
Key: nonEmptyString(c.RandString),
217+
Operator: metav1.LabelSelectorOpIn,
218+
Values: []string{
219+
nonEmptyString(c.RandString),
220+
},
221+
})
222+
}
223+
selector.MatchExpressions = expressions
224+
}
225+
226+
r.PermissionClaims = append(r.PermissionClaims, v1alpha2.AcceptablePermissionClaim{
227+
ScopedPermissionClaim: v1alpha2.ScopedPermissionClaim{
228+
PermissionClaim: v1alpha2.PermissionClaim{
229+
GroupResource: v1alpha2.GroupResource{
230+
Group: group,
231+
Resource: resource,
232+
},
233+
IdentityHash: identityHash,
234+
Verbs: verbs,
235+
},
236+
Selector: selector,
237+
},
238+
State: v1alpha2.ClaimAccepted,
239+
})
240+
}
241+
},
242+
func(r *v1alpha2.APIBindingStatus, c fuzz.Continue) {
243+
c.FuzzNoCustom(r)
244+
r.AppliedPermissionClaims = nil
245+
for range c.Intn(5) {
246+
group := nonEmptyString(c.RandString)
247+
resource := nonEmptyString(c.RandString)
248+
identityHash := nonEmptyString(c.RandString)
249+
verbs := []string{}
250+
numVerbs := c.Intn(5) + 1 // the lower bound is 0, but 0 verbs is not a valid combination
251+
for range numVerbs {
252+
verbs = append(verbs, nonEmptyString(c.RandString))
253+
}
254+
255+
selector := v1alpha2.PermissionClaimSelector{}
256+
257+
switch c.Intn(3) {
258+
case 0:
259+
selector.MatchAll = true
260+
case 1:
261+
labels := make(map[string]string)
262+
numLabels := c.Intn(5) + 1
263+
for range numLabels {
264+
labels[nonEmptyString(c.RandString)] = nonEmptyString(c.RandString)
265+
}
266+
selector.MatchLabels = labels
267+
default:
268+
numExpressions := c.Intn(5) + 1
269+
expressions := make([]metav1.LabelSelectorRequirement, numExpressions)
270+
for range numExpressions {
271+
expressions = append(expressions, metav1.LabelSelectorRequirement{
272+
Key: nonEmptyString(c.RandString),
273+
Operator: metav1.LabelSelectorOpIn,
274+
Values: []string{
275+
nonEmptyString(c.RandString),
276+
},
277+
})
278+
}
279+
selector.MatchExpressions = expressions
280+
}
281+
282+
r.AppliedPermissionClaims = append(r.AppliedPermissionClaims, v1alpha2.ScopedPermissionClaim{
283+
PermissionClaim: v1alpha2.PermissionClaim{
284+
GroupResource: v1alpha2.GroupResource{
285+
Group: group,
286+
Resource: resource,
287+
},
288+
IdentityHash: identityHash,
289+
Verbs: verbs,
290+
},
291+
Selector: selector,
292+
})
293+
}
294+
r.ExportPermissionClaims = nil
295+
for range c.Intn(5) {
296+
group := nonEmptyString(c.RandString)
297+
resource := nonEmptyString(c.RandString)
298+
identityHash := nonEmptyString(c.RandString)
299+
verbs := []string{}
300+
numVerbs := c.Intn(5) + 1 // the lower bound is 0, but 0 verbs is not a valid combination
301+
for range numVerbs {
302+
verbs = append(verbs, nonEmptyString(c.RandString))
303+
}
304+
r.ExportPermissionClaims = append(r.ExportPermissionClaims, v1alpha2.PermissionClaim{
305+
GroupResource: v1alpha2.GroupResource{
306+
Group: group,
307+
Resource: resource,
308+
},
309+
IdentityHash: identityHash,
310+
Verbs: verbs,
311+
})
312+
}
313+
},
94314
func(r *v1alpha1.Identity, c fuzz.Continue) {
95315
c.FuzzNoCustom(r)
96316

0 commit comments

Comments
 (0)