summaryrefslogtreecommitdiffstats
path: root/utils/path_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'utils/path_test.go')
-rw-r--r--utils/path_test.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/utils/path_test.go b/utils/path_test.go
new file mode 100644
index 000000000..70b7c24fc
--- /dev/null
+++ b/utils/path_test.go
@@ -0,0 +1,31 @@
+// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package utils
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestPathTraversesUpward(t *testing.T) {
+ cases := []struct {
+ input string
+ expected bool
+ }{
+ {"../test/path", true},
+ {"../../test/path", true},
+ {"../../test/../path", true},
+ {"test/../../path", true},
+ {"test/path/../../", false},
+ {"test", false},
+ {"test/path", false},
+ {"test/path/", false},
+ {"test/path/file.ext", false},
+ }
+
+ for _, c := range cases {
+ assert.Equal(t, c.expected, PathTraversesUpward(c.input), c.input)
+ }
+}