fuzzer.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. Copyright 2017 The Kubernetes Authors.
  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. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package fuzzer
  14. import (
  15. fuzz "github.com/google/gofuzz"
  16. runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
  17. "k8s.io/kubernetes/pkg/apis/rbac"
  18. )
  19. // Funcs returns the fuzzer functions for the rbac api group.
  20. var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
  21. return []interface{}{
  22. func(r *rbac.RoleRef, c fuzz.Continue) {
  23. c.FuzzNoCustom(r) // fuzz self without calling this function again
  24. // match defaulter
  25. if len(r.APIGroup) == 0 {
  26. r.APIGroup = rbac.GroupName
  27. }
  28. },
  29. func(r *rbac.Subject, c fuzz.Continue) {
  30. switch c.Int31n(3) {
  31. case 0:
  32. r.Kind = rbac.ServiceAccountKind
  33. r.APIGroup = ""
  34. c.FuzzNoCustom(&r.Name)
  35. c.FuzzNoCustom(&r.Namespace)
  36. case 1:
  37. r.Kind = rbac.UserKind
  38. r.APIGroup = rbac.GroupName
  39. c.FuzzNoCustom(&r.Name)
  40. // user "*" won't round trip because we convert it to the system:authenticated group. try again.
  41. for r.Name == "*" {
  42. c.FuzzNoCustom(&r.Name)
  43. }
  44. case 2:
  45. r.Kind = rbac.GroupKind
  46. r.APIGroup = rbac.GroupName
  47. c.FuzzNoCustom(&r.Name)
  48. }
  49. },
  50. }
  51. }