File: common_test.go

package info (click to toggle)
docker.io 26.1.5%2Bdfsg1-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 68,576 kB
  • sloc: sh: 5,748; makefile: 912; ansic: 664; asm: 228; python: 162
file content (31 lines) | stat: -rw-r--r-- 969 bytes parent folder | download
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
29
30
31
package safepath

import (
	"testing"

	"gotest.tools/v3/assert"
	is "gotest.tools/v3/assert/cmp"
)

func TestIsLocalTo(t *testing.T) {
	for _, tc := range []struct {
		name    string
		subpath string
		result  bool
	}{
		{name: "same", subpath: "/volume", result: true},
		{name: "1 level subpath", subpath: "/volume/sub", result: true},
		{name: "2 level subpath", subpath: "/volume/sub/path", result: true},
		{name: "absolute", subpath: "/etc/passwd", result: false},
		{name: "backtrack", subpath: "/volume/../", result: false},
		{name: "backtrack inside", subpath: "/volume/sub/../", result: true},
		{name: "relative path", subpath: "./rel", result: false},
		{name: "file with dots", subpath: "/volume/file..with.dots", result: true},
		{name: "file starting with dots", subpath: "/volume/..file", result: true},
	} {
		t.Run(tc.name, func(t *testing.T) {
			result := isLocalTo(tc.subpath, "/volume")
			assert.Check(t, is.Equal(result, tc.result))
		})
	}
}