From a04e3ac4f7e66c3d3d7277010cbff6c2305185f0 Mon Sep 17 00:00:00 2001 From: Christopher Desiniotis Date: Wed, 16 Oct 2024 16:37:12 -0700 Subject: [PATCH] Write failing test case for create-symlinks hook Signed-off-by: Christopher Desiniotis --- .../create-symlinks/create-symlinks_test.go | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/cmd/nvidia-cdi-hook/create-symlinks/create-symlinks_test.go b/cmd/nvidia-cdi-hook/create-symlinks/create-symlinks_test.go index 7a832759..be5ee5f0 100644 --- a/cmd/nvidia-cdi-hook/create-symlinks/create-symlinks_test.go +++ b/cmd/nvidia-cdi-hook/create-symlinks/create-symlinks_test.go @@ -108,6 +108,31 @@ func TestCreateLinkAlreadyExistsDifferentTarget(t *testing.T) { require.Equal(t, "different-target", target) } +func TestCreateLinkOutOfBounds(t *testing.T) { + tmpDir := t.TempDir() + hostRoot := filepath.Join(tmpDir, "/host-root/") + containerRoot := filepath.Join(tmpDir, "/container-root") + + require.NoError(t, makeFs(hostRoot)) + require.NoError(t, + makeFs(containerRoot, + dirOrLink{path: "/lib"}, + dirOrLink{path: "/lib/foo", target: hostRoot}, + ), + ) + + path, err := symlinks.Resolve(filepath.Join(containerRoot, "/lib/foo")) + require.NoError(t, err) + require.Equal(t, hostRoot, path) + + // nvidia-cdi-hook create-symlinks --link ../libfoo.so.1::/lib/foo/libfoo.so + _ = getTestCommand().createLink(containerRoot, "../libfoo.so.1", "/lib/foo/libfoo.so") + // TODO: We need to enabled this check once we have updated the implementation. + // require.Error(t, err) + _, err = os.Lstat(filepath.Join(hostRoot, "libfoo.so")) + require.ErrorIs(t, err, os.ErrNotExist) +} + type dirOrLink struct { path string target string