From 11adae88ecd83b28751fc3090cb76c146bff602c Mon Sep 17 00:00:00 2001 From: Ben Swartzlander Date: Fri, 31 Aug 2018 11:50:45 -0400 Subject: [PATCH] Add tests for Unicode names Create 2 new tests, one for a volume with a Unicode name, and one for a snapshot with a Unicode name. These tests are intended to catch bugs where plugin authors use the value of the name field in a context where Unicode is not allowed. --- pkg/sanity/controller.go | 76 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/pkg/sanity/controller.go b/pkg/sanity/controller.go index 294a1e0d..9d47f8bb 100644 --- a/pkg/sanity/controller.go +++ b/pkg/sanity/controller.go @@ -443,6 +443,52 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) { Expect(err).NotTo(HaveOccurred()) cl.UnregisterVolume(name) }) + + It("should not fail when creating volume with a unicode name", func() { + + name := "sanity-unicode-\xF0\x9F\x92\xA9-name" + By("creating a volume") + size := TestVolumeSize(sc) + + vol, err := c.CreateVolume( + context.Background(), + &csi.CreateVolumeRequest{ + Name: name, + VolumeCapabilities: []*csi.VolumeCapability{ + { + AccessType: &csi.VolumeCapability_Mount{ + Mount: &csi.VolumeCapability_MountVolume{}, + }, + AccessMode: &csi.VolumeCapability_AccessMode{ + Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, + }, + }, + }, + CapacityRange: &csi.CapacityRange{ + RequiredBytes: size, + }, + ControllerCreateSecrets: sc.Secrets.CreateVolumeSecret, + }, + ) + Expect(err).NotTo(HaveOccurred()) + Expect(vol).NotTo(BeNil()) + Expect(vol.GetVolume()).NotTo(BeNil()) + Expect(vol.GetVolume().GetId()).NotTo(BeEmpty()) + cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.GetVolume().GetId()}) + Expect(vol.GetVolume().GetCapacityBytes()).To(BeNumerically(">=", size)) + + By("cleaning up deleting the volume") + + _, err = c.DeleteVolume( + context.Background(), + &csi.DeleteVolumeRequest{ + VolumeId: vol.GetVolume().GetId(), + ControllerDeleteSecrets: sc.Secrets.DeleteVolumeSecret, + }, + ) + Expect(err).NotTo(HaveOccurred()) + cl.UnregisterVolume(name) + }) }) Describe("DeleteVolume", func() { @@ -1557,6 +1603,36 @@ var _ = DescribeSanity("CreateSnapshot [Controller Server]", func(sc *SanityCont _, err = c.DeleteVolume(context.Background(), delVolReq) Expect(err).NotTo(HaveOccurred()) }) + + It("should not fail when creating snapshot with unicode name", func() { + + By("creating a volume") + volReq := MakeCreateVolumeReq(sc, "CreateSnapshot-volume-4") + volume, err := c.CreateVolume(context.Background(), volReq) + Expect(err).NotTo(HaveOccurred()) + + By("creating a snapshot") + snapReq1 := MakeCreateSnapshotReq(sc, "CreateSnapshot-snapshot-4-\xF0\x9F\x92\xA9", volume.GetVolume().GetId(), nil) + snap1, err := c.CreateSnapshot(context.Background(), snapReq1) + Expect(err).NotTo(HaveOccurred()) + Expect(snap1).NotTo(BeNil()) + verifySnapshotInfo(snap1.GetSnapshot()) + + snap2, err := c.CreateSnapshot(context.Background(), snapReq1) + Expect(err).NotTo(HaveOccurred()) + Expect(snap2).NotTo(BeNil()) + verifySnapshotInfo(snap2.GetSnapshot()) + + By("cleaning up deleting the snapshot") + delSnapReq := MakeDeleteSnapshotReq(sc, snap1.GetSnapshot().GetId()) + _, err = c.DeleteSnapshot(context.Background(), delSnapReq) + Expect(err).NotTo(HaveOccurred()) + + By("cleaning up deleting the volume") + delVolReq := MakeDeleteVolumeReq(sc, volume.GetVolume().GetId()) + _, err = c.DeleteVolume(context.Background(), delVolReq) + Expect(err).NotTo(HaveOccurred()) + }) }) func MakeCreateVolumeReq(sc *SanityContext, name string) *csi.CreateVolumeRequest {