...

Source file src/k8s.io/kubernetes/pkg/apis/rbac/fuzzer/fuzzer.go

Documentation: k8s.io/kubernetes/pkg/apis/rbac/fuzzer

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

View as plain text