MCPcopy
hub / github.com/opencontainers/runc / TestIsLexicallyInRoot

Function TestIsLexicallyInRoot

internal/pathrs/path_test.go:23–53  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

21import "testing"
22
23func TestIsLexicallyInRoot(t *testing.T) {
24 for _, test := range []struct {
25 name string
26 root, path string
27 expected bool
28 }{
29 {"Equal1", "/foo", "/foo", true},
30 {"Equal2", "/bar/baz", "/bar/baz", true},
31 {"Equal3", "/bar/baz/", "/bar/baz/", true},
32 {"Root", "/", "/foo/bar", true},
33 {"Root-Equal", "/", "/", true},
34 {"InRoot-Basic1", "/foo/bar", "/foo/bar/baz/abcd", true},
35 {"InRoot-Basic2", "/a/b/c/d", "/a/b/c/d/e/f/g/h", true},
36 {"InRoot-Long", "/var/lib/docker/container/1234abcde/rootfs", "/var/lib/docker/container/1234abcde/rootfs/a/b/c", true},
37 {"InRoot-TrailingSlash1", "/foo/bar/", "/foo/bar", true},
38 {"InRoot-TrailingSlash2", "/foo/", "/foo/bar/baz/boop", true},
39 {"NotInRoot-Basic1", "/foo", "/bar", false},
40 {"NotInRoot-Basic2", "/foo", "/bar", false},
41 {"NotInRoot-Basic3", "/foo/bar/baz", "/foo/boo/baz/abc", false},
42 {"NotInRoot-Long", "/var/lib/docker/container/1234abcde/rootfs", "/a/b/c", false},
43 {"NotInRoot-Tricky1", "/foo/bar", "/foo/bara", false},
44 {"NotInRoot-Tricky2", "/foo/bar", "/foo/ba/r", false},
45 } {
46 t.Run(test.name, func(t *testing.T) {
47 got := IsLexicallyInRoot(test.root, test.path)
48 if test.expected != got {
49 t.Errorf("IsLexicallyInRoot(%q, %q) = %v (expected %v)", test.root, test.path, got, test.expected)
50 }
51 })
52 }
53}
54
55func TestLexicallyCleanPath(t *testing.T) {
56 path := LexicallyCleanPath("")

Callers

nothing calls this directly

Calls 2

IsLexicallyInRootFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…