summaryrefslogtreecommitdiff
path: root/libpod/container_path_resolution_test.go
diff options
context:
space:
mode:
authorGiuseppe Scrivano <gscrivan@redhat.com>2022-09-14 13:01:43 +0200
committerGiuseppe Scrivano <gscrivan@redhat.com>2022-09-14 17:09:04 +0200
commit14e5d1c15da82f7eb315c320765aeca69f4b58af (patch)
tree4d1b162552e80c1c5a267110310dfc2bc1638679 /libpod/container_path_resolution_test.go
parent92dc61d5edb1b5ce85f7e4563d400cc861a28359 (diff)
downloadpodman-14e5d1c15da82f7eb315c320765aeca69f4b58af.tar.gz
podman-14e5d1c15da82f7eb315c320765aeca69f4b58af.tar.bz2
podman-14e5d1c15da82f7eb315c320765aeca69f4b58af.zip
libpod: fix lookup for subpath in volumes
a subdirectory that is below a mount destination is detected as a subpath. Closes: https://github.com/containers/podman/issues/15789 Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Diffstat (limited to 'libpod/container_path_resolution_test.go')
-rw-r--r--libpod/container_path_resolution_test.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/libpod/container_path_resolution_test.go b/libpod/container_path_resolution_test.go
new file mode 100644
index 000000000..f906c752d
--- /dev/null
+++ b/libpod/container_path_resolution_test.go
@@ -0,0 +1,28 @@
+package libpod
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestIsSubDir(t *testing.T) {
+ assert.True(t, isSubDir("/foo", "/foo"))
+ assert.True(t, isSubDir("/foo/bar", "/foo"))
+ assert.True(t, isSubDir("/foo/bar", "/foo/"))
+ assert.True(t, isSubDir("/foo/bar", "/foo//"))
+ assert.True(t, isSubDir("/foo/bar/", "/foo"))
+ assert.True(t, isSubDir("/foo/bar/baz/", "/foo"))
+ assert.True(t, isSubDir("/foo/bar/baz/", "/foo/bar"))
+ assert.True(t, isSubDir("/foo/bar/baz/", "/foo/bar/"))
+ assert.False(t, isSubDir("/foo/bar/baz/", "/foobar/"))
+ assert.False(t, isSubDir("/foo/bar/baz/../../", "/foobar/"))
+ assert.False(t, isSubDir("/foo/bar/baz/", "../foo/bar"))
+ assert.False(t, isSubDir("/foo/bar/baz/", "../foo/"))
+ assert.False(t, isSubDir("/foo/bar/baz/", "../foo"))
+ assert.False(t, isSubDir("/", ".."))
+ assert.False(t, isSubDir("//", ".."))
+ assert.False(t, isSubDir("//", "../"))
+ assert.False(t, isSubDir("//", "..//"))
+ assert.True(t, isSubDir("/foo/bar/baz/../../", "/foo/"))
+}