code.gitea.io/gitea@v1.21.7/routers/web/repo/githttp_test.go (about)

     1  // Copyright 2021 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package repo
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestContainsParentDirectorySeparator(t *testing.T) {
    13  	tests := []struct {
    14  		v string
    15  		b bool
    16  	}{
    17  		{
    18  			v: `user2/repo1/info/refs`,
    19  			b: false,
    20  		},
    21  		{
    22  			v: `user2/repo1/HEAD`,
    23  			b: false,
    24  		},
    25  		{
    26  			v: `user2/repo1/some.../strange_file...mp3`,
    27  			b: false,
    28  		},
    29  		{
    30  			v: `user2/repo1/../../custom/conf/app.ini`,
    31  			b: true,
    32  		},
    33  		{
    34  			v: `user2/repo1/objects/info/..\..\..\..\custom\conf\app.ini`,
    35  			b: true,
    36  		},
    37  	}
    38  
    39  	for i := range tests {
    40  		assert.EqualValues(t, tests[i].b, containsParentDirectorySeparator(tests[i].v))
    41  	}
    42  }