github.com/secure-build/gitlab-runner@v12.5.0+incompatible/helpers/archives/path_check_helper_test.go (about)

     1  package archives
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestDoesPathsListContainGitDirectory(t *testing.T) {
    11  	examples := []struct {
    12  		path   string
    13  		unsafe bool
    14  	}{
    15  		{".git", true},
    16  		{".git/", true},
    17  		{"././././.git/", true},
    18  		{"././.git/.././.git/", true},
    19  		{".git/test", true},
    20  		{"./.git/test", true},
    21  		{"test/.git", false},
    22  		{"test/.git/test", false},
    23  	}
    24  
    25  	for id, example := range examples {
    26  		t.Run(fmt.Sprintf("example-%d", id), func(t *testing.T) {
    27  			unsafe := isPathAGitDirectory(example.path)
    28  			assert.Equal(t, example.unsafe, unsafe)
    29  		})
    30  	}
    31  }