Skip to content

Commit

Permalink
cert rotation fuzzer: sequence CRUD ops
Browse files Browse the repository at this point in the history
  • Loading branch information
vrutkovs committed Apr 8, 2024
1 parent 959a514 commit 50517d1
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions pkg/operator/certrotation/cert_rotation_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,27 @@ type secretwrapped struct {
}

func (w secretwrapped) Create(ctx context.Context, secret *corev1.Secret, opts metav1.CreateOptions) (*corev1.Secret, error) {
w.d.Sequence(w.name, fmt.Sprintf("create-%s", secret.Name))
w.t.Logf("[%s] op=Create, secret=%s/%s", w.name, secret.Namespace, secret.Name)
return w.SecretInterface.Create(ctx, secret, opts)
}
func (w secretwrapped) Update(ctx context.Context, secret *corev1.Secret, opts metav1.UpdateOptions) (*corev1.Secret, error) {
w.d.Sequence(w.name, fmt.Sprintf("update-%s", secret.Name))
w.t.Logf("[%s] op=Update, secret=%s/%s", w.name, secret.Namespace, secret.Name)
return w.SecretInterface.Update(ctx, secret, opts)
}
func (w secretwrapped) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error {
w.t.Logf("[%s] op=Delete, secret=%s", w.name, name)
w.d.Sequence(w.name, fmt.Sprintf("delete-%s", name))
defer func() {
if w.hook != nil {
w.hook(w.name, operation(w.t, opts))
}
}()
w.t.Logf("[%s] op=Delete, secret=%s", w.name, name)
return w.SecretInterface.Delete(ctx, name, opts)
}
func (w secretwrapped) Get(ctx context.Context, name string, opts metav1.GetOptions) (*corev1.Secret, error) {
w.d.Sequence(w.name, fmt.Sprintf("get-%s", name))
if w.hook != nil {
w.hook(w.name, operation(w.t, opts))
}
Expand Down Expand Up @@ -140,15 +144,13 @@ func (d *dispatcher) Run() {
}
return 1
})
d.t.Logf("queue %v", waiting)
if len(choices) == 0 {
choices = d.choices
}
choice := int(choices[0])
if choice > len(waiting)-1 {
choice = choice % len(waiting)
}
d.t.Logf("choice %v", choice)

var w request
var newWaiting []request
Expand All @@ -159,11 +161,8 @@ func (d *dispatcher) Run() {
newWaiting = append(newWaiting, v)
}
}
d.t.Logf("w %v", w)

choices = choices[1:]
waiting = newWaiting
d.t.Logf("new queue %v", waiting)
d.t.Logf("dispatching %q by %q", w.what, w.who)
close(w.when)
}
Expand Down Expand Up @@ -365,19 +364,17 @@ func NewSecretControllerFuzzer(name string) SecretControllerFuzzer {

func (c SecretControllerFuzzer) Run(f *testing.F) {
existing := c.prepareSecretFn(f, c.secretNamespace, c.secretName)
f.Add([]byte{1, 2, 3}, 3)
f.Fuzz(func(t *testing.T, choices []byte, workers int) {
if len(choices) == 0 {
t.Skip()
}
if workers < 1 || workers > 10 {
f.Add([]byte{0, 1, 2})
f.Fuzz(func(t *testing.T, choices []byte) {
if len(choices) == 0 || len(choices) > 10 {
t.Skip()
}
workers := len(choices)
t.Logf("choices: %v, workers: %d", choices, workers)
d := &dispatcher{
t: t,
choices: choices,
requests: make(chan request, workers),
requests: make(chan request, workers*3),
}
go d.Run()
defer d.Stop()
Expand All @@ -390,7 +387,7 @@ func (c SecretControllerFuzzer) Run(f *testing.F) {

var wg sync.WaitGroup
for i := 1; i <= workers; i++ {
controllerName := fmt.Sprintf("controller-%d", i)
controllerName := fmt.Sprintf("controller-fuzz-%d", i)
wg.Add(1)
d.Join(controllerName)

Expand Down Expand Up @@ -420,13 +417,13 @@ func (c SecretControllerFuzzer) Run(f *testing.F) {
})
}

func FuzzRotatedSigningCASecretDefault(f *testing.F) {
c := NewSecretControllerFuzzer("RotatedSigningCASecret")
c.prepareSecretFn = prepareSigningSecret
c.prepareSecretControllerFn = prepareSecretController
c.verifySecretFn = verifySecret
c.Run(f)
}
// func FuzzRotatedSigningCASecretDefault(f *testing.F) {
// c := NewSecretControllerFuzzer("RotatedSigningCASecret")
// c.prepareSecretFn = prepareSigningSecret
// c.prepareSecretControllerFn = prepareSecretController
// c.verifySecretFn = verifySecret
// c.Run(f)
// }

func FuzzRotatedSigningCASecretUseSecretUpdateOnly(f *testing.F) {
c := NewSecretControllerFuzzer("RotatedSigningCASecretUseSecretUpdateOnly")
Expand Down

0 comments on commit 50517d1

Please sign in to comment.