Welcome to mirror list, hosted at ThFree Co, Russian Federation.

security_test.go « helper « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9a8125dac612e1d673921665ab7937b881945627 (plain)
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
32
33
34
35
36
37
38
39
40
41
42
package helper

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestContainsPathTraversal(t *testing.T) {
	testCases := []struct {
		path              string
		containsTraversal bool
	}{
		{"../parent", true},
		{"subdir/../../parent", true},
		{"subdir/..", true},
		{"subdir", false},
		{"./subdir", false},
	}

	for _, tc := range testCases {
		assert.Equal(t, tc.containsTraversal, ContainsPathTraversal(tc.path))
	}
}

func TestSanitizeString(t *testing.T) {
	testCases := []struct {
		input  string
		output string
	}{
		{"https://foo_the_user@gitlab.com/foo/bar", "https://[FILTERED]@gitlab.com/foo/bar"},
		{"https://foo_the_user:hUntEr1@gitlab.com/foo/bar", "https://[FILTERED]@gitlab.com/foo/bar"},
		{"proto://user:password@gitlab.com", "proto://[FILTERED]@gitlab.com"},
		{"some message proto://user:password@gitlab.com", "some message proto://[FILTERED]@gitlab.com"},
		{"test", "test"},
		{"ssh://@gitlab.com", "ssh://@gitlab.com"},
	}

	for _, tc := range testCases {
		assert.Equal(t, tc.output, SanitizeString(tc.input))
	}
}