From 95dcf132f821bcd46c2e125d075806b92455b3a0 Mon Sep 17 00:00:00 2001 From: yandu Date: Tue, 11 Feb 2025 14:09:01 -0500 Subject: [PATCH] Test tweaks --- pkg/api/cached.go | 9 ++++++++- test/cached_csi_test.go | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/pkg/api/cached.go b/pkg/api/cached.go index ec5376a..ef7dd75 100644 --- a/pkg/api/cached.go +++ b/pkg/api/cached.go @@ -75,6 +75,13 @@ func (c *Cached) Prepare(ctx context.Context) error { return err } + // Once we've prepared the cache make it read-only for + // everyone except the user running the daemon + err = os.Chmod(c.GetCachePath(), 0755) + if err != nil { + return fmt.Errorf("failed to change permissions of cache path %s: %v", c.GetCachePath(), err) + } + c.currentVersion = version logger.Info(ctx, c.GetCachePath()) @@ -222,7 +229,7 @@ func (s *Cached) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublish // Unmount the overlay err := execCommand("umount", targetPath) if err != nil { - return nil, fmt.Errorf("failed to unmount overlay: %s", err) + return nil, fmt.Errorf("failed to unmount overlay at %s: %v", targetPath, err) } // Clean up upper and work directories from the overlay diff --git a/test/cached_csi_test.go b/test/cached_csi_test.go index f1f5ca6..32cfd63 100644 --- a/test/cached_csi_test.go +++ b/test/cached_csi_test.go @@ -101,6 +101,12 @@ func TestCachedCSIDriverMountsCache(t *testing.T) { cacheFileInfo, err := os.Stat(path.Join(targetDir, fmt.Sprintf("objects/%v/pack/a/1", aHash))) require.NoError(t, err) require.Equal(t, formatFileMode(os.FileMode(0755)), formatFileMode(cacheFileInfo.Mode()&os.ModePerm)) + + _, err = cached.NodeUnpublishVolume(tc.Context(), &csi.NodeUnpublishVolumeRequest{ + VolumeId: "foobar", + TargetPath: targetDir, + }) + require.NoError(t, err) } func TestCachedCSIDriverMountsCacheAtSuffix(t *testing.T) { @@ -124,6 +130,8 @@ func TestCachedCSIDriverMountsCacheAtSuffix(t *testing.T) { require.NoError(t, err, "cached.Prepare must succeed") targetDir := path.Join(tmpDir, "vol-target") + require.NoError(t, os.Chmod(targetDir, 0777)) + stagingDir := path.Join(tmpDir, "vol-staging-target") _, err = cached.NodePublishVolume(tc.Context(), &csi.NodePublishVolumeRequest{ VolumeId: "foobar", @@ -157,6 +165,13 @@ func TestCachedCSIDriverMountsCacheAtSuffix(t *testing.T) { cacheFileInfo, err = os.Stat(path.Join(targetDir, fmt.Sprintf("dl_cache/objects/%v/pack/a/1", aHash))) require.NoError(t, err) require.Equal(t, formatFileMode(os.FileMode(0755)), formatFileMode(cacheFileInfo.Mode())) + require.Equal(t, targetDir, path.Join(tmpDir, "vol-target")) + + _, err = cached.NodeUnpublishVolume(tc.Context(), &csi.NodeUnpublishVolumeRequest{ + VolumeId: "foobar", + TargetPath: targetDir, + }) + require.NoError(t, err) } func TestCachedCSIDriverProbeFailsUntilPrepared(t *testing.T) {