@@ -20,6 +20,8 @@ import (
20
20
"context"
21
21
"testing"
22
22
23
+ "k8s.io/apimachinery/pkg/apis/meta/internalversion"
24
+ "k8s.io/apimachinery/pkg/apis/meta/internalversion/validation"
23
25
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24
26
"k8s.io/apimachinery/pkg/runtime"
25
27
"k8s.io/apiserver/pkg/apis/example"
@@ -192,3 +194,56 @@ func TestCalculateDigest(t *testing.T) {
192
194
})
193
195
}
194
196
}
197
+
198
+ func TestValidateUndelegatedListOptions (t * testing.T ) {
199
+ opts := []storage.ListOptions {}
200
+ keyPrefix := "/pods/"
201
+ continueOnRV1 , err := storage .EncodeContinue ("/pods/a" , keyPrefix , 1 )
202
+ if err != nil {
203
+ t .Fatalf ("Unexpected error: %v" , err )
204
+ }
205
+ continueOnNegativeRV , err := storage .EncodeContinue ("/pods/a" , keyPrefix , - 1 )
206
+ if err != nil {
207
+ t .Fatalf ("Unexpected error: %v" , err )
208
+ }
209
+ for _ , rv := range []string {"" , "0" , "1" } {
210
+ for _ , match := range []metav1.ResourceVersionMatch {"" , metav1 .ResourceVersionMatchExact , metav1 .ResourceVersionMatchNotOlderThan } {
211
+ for _ , c := range []string {"" , continueOnRV1 , continueOnNegativeRV } {
212
+ for _ , limit := range []int64 {0 , 100 } {
213
+ for _ , recursive := range []bool {true , false } {
214
+ opt := storage.ListOptions {
215
+ ResourceVersion : rv ,
216
+ ResourceVersionMatch : match ,
217
+ Predicate : storage.SelectionPredicate {
218
+ Limit : limit ,
219
+ Continue : c ,
220
+ },
221
+ Recursive : recursive ,
222
+ }
223
+ // Skip requests that will not pass apiserver validation
224
+ if errs := validation .ValidateListOptions (& internalversion.ListOptions {
225
+ ResourceVersion : opt .ResourceVersion ,
226
+ ResourceVersionMatch : opt .ResourceVersionMatch ,
227
+ Limit : opt .Predicate .Limit ,
228
+ Continue : opt .Predicate .Continue ,
229
+ }, false ); len (errs ) != 0 {
230
+ continue
231
+ }
232
+ // Skip requests sent directly to etcd
233
+ if delegateList , _ := shouldDelegateList (opt ); delegateList {
234
+ continue
235
+ }
236
+ opts = append (opts , opt )
237
+ }
238
+
239
+ }
240
+ }
241
+ }
242
+ }
243
+ for _ , opt := range opts {
244
+ _ , _ , err := storage .ValidateListOptions (keyPrefix , storage.APIObjectVersioner {}, opt )
245
+ if err != nil {
246
+ t .Errorf ("Expected List requests %+v to pass validation, got: %v" , opt , err )
247
+ }
248
+ }
249
+ }
0 commit comments