Skip to content

Commit 3ad33cb

Browse files
committed
Check for negative size or inverted range
The CSI spec requires that callers must pass non-negative sizes. It is also impossible to honor a request where the RequiredSize is larger than the LimitSize. For both of these, check that we get either InvalidArgument or OutOfRange. Signed-off-by: Eric Blake <[email protected]>
1 parent a5b8eac commit 3ad33cb

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

Diff for: pkg/sanity/controller.go

+56
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,62 @@ var _ = DescribeSanity("Controller Service [Controller Server]", func(sc *TestCo
394394
ExpectErrorCode(rsp, err, codes.InvalidArgument)
395395
})
396396

397+
It("should fail with negative capacity", func() {
398+
399+
By("creating a volume")
400+
name := UniqueString("sanity-controller-create-single-with-negative-capacity")
401+
402+
vol, err := r.CreateVolume(
403+
context.Background(),
404+
&csi.CreateVolumeRequest{
405+
Name: name,
406+
VolumeCapabilities: []*csi.VolumeCapability{
407+
TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
408+
},
409+
CapacityRange: &csi.CapacityRange{
410+
RequiredBytes: -1 * TestVolumeSize(sc),
411+
},
412+
Secrets: sc.Secrets.CreateVolumeSecret,
413+
Parameters: sc.Config.TestVolumeParameters,
414+
},
415+
)
416+
Expect(err).To(HaveOccurred())
417+
Expect(vol).To(BeNil())
418+
419+
serverError, ok := status.FromError(err)
420+
Expect(ok).To(BeTrue())
421+
Expect(serverError.Code() == codes.OutOfRange || serverError.Code() == codes.InvalidArgument, "unexpected error: %s", serverError.Message())
422+
})
423+
424+
It("should fail with invalid capacity", func() {
425+
426+
By("creating a volume")
427+
name := UniqueString("sanity-controller-create-single-with-invalid-capacity")
428+
429+
vol, err := r.CreateVolume(
430+
context.Background(),
431+
&csi.CreateVolumeRequest{
432+
Name: name,
433+
VolumeCapabilities: []*csi.VolumeCapability{
434+
TestVolumeCapabilityWithAccessType(sc, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER),
435+
},
436+
CapacityRange: &csi.CapacityRange{
437+
// LimitBytes < RequiredBytes is impossible to honor
438+
RequiredBytes: TestVolumeExpandSize(sc),
439+
LimitBytes: TestVolumeSize(sc),
440+
},
441+
Secrets: sc.Secrets.CreateVolumeSecret,
442+
Parameters: sc.Config.TestVolumeParameters,
443+
},
444+
)
445+
Expect(err).To(HaveOccurred())
446+
Expect(vol).To(BeNil())
447+
448+
serverError, ok := status.FromError(err)
449+
Expect(ok).To(BeTrue())
450+
Expect(serverError.Code() == codes.OutOfRange || serverError.Code() == codes.InvalidArgument, "unexpected error: %s", serverError.Message())
451+
})
452+
397453
// whether CreateVolume request with no capacity should fail or not depends on driver implementation
398454
It("should return appropriate values SingleNodeWriter NoCapacity", func() {
399455

0 commit comments

Comments
 (0)