aboutsummaryrefslogtreecommitdiff
path: root/libpod/container_path_resolution_test.go
blob: f906c752d2784fd5dcd0ed869737215ef7248944 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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/"))
}