github.com/space0122/mattermost-server@v5.11.1+incompatible/utils/path_test.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package utils
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestPathTraversesUpward(t *testing.T) {
    13  	cases := []struct {
    14  		input    string
    15  		expected bool
    16  	}{
    17  		{"../test/path", true},
    18  		{"../../test/path", true},
    19  		{"../../test/../path", true},
    20  		{"test/../../path", true},
    21  		{"test/path/../../", false},
    22  		{"test", false},
    23  		{"test/path", false},
    24  		{"test/path/", false},
    25  		{"test/path/file.ext", false},
    26  	}
    27  
    28  	for _, c := range cases {
    29  		assert.Equal(t, c.expected, PathTraversesUpward(c.input), c.input)
    30  	}
    31  }