1
// Copyright 2021 The Gitea Authors. All rights reserved.
2
// SPDX-License-Identifier: MIT
10
"github.com/stretchr/testify/assert"
13
func TestSanitizeErrorCredentialURLs(t *testing.T) {
14
err := errors.New("error with https://a@b.com")
15
se := SanitizeErrorCredentialURLs(err)
16
assert.Equal(t, "error with https://"+userPlaceholder+"@b.com", se.Error())
19
func TestSanitizeCredentialURLs(t *testing.T) {
25
"https://github.com/go-gitea/test_repo.git",
26
"https://github.com/go-gitea/test_repo.git",
29
"https://mytoken@github.com/go-gitea/test_repo.git",
30
"https://" + userPlaceholder + "@github.com/go-gitea/test_repo.git",
33
"https://user:password@github.com/go-gitea/test_repo.git",
34
"https://" + userPlaceholder + "@github.com/go-gitea/test_repo.git",
38
"ftp://" + userPlaceholder + "@",
45
"ftp://u@x/@", // test multiple @ chars
46
"ftp://" + userPlaceholder + "@x/@",
49
"😊ftp://u@x😊", // test unicode
50
"😊ftp://" + userPlaceholder + "@x😊",
57
"//u:p@h", // do not process URLs without explicit scheme, they are not treated as "valid" URLs because there is no scheme context in string
61
"s://u@h", // the minimal pattern to be sanitized
62
"s://" + userPlaceholder + "@h",
65
"URLs in log https://u:b@h and https://u:b@h:80/, with https://h.com and u@h.com",
66
"URLs in log https://" + userPlaceholder + "@h and https://" + userPlaceholder + "@h:80/, with https://h.com and u@h.com",
70
for n, c := range cases {
71
result := SanitizeCredentialURLs(c.input)
72
assert.Equal(t, c.expected, result, "case %d: error should match", n)