mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
Source files keep their SPDX-License-Identifier and Hanzo copyright line; the Gitea, Gogs and LFS Test Server copyrights they used to repeat now live once in NOTICE, alongside LICENSE. The header lint accepts any copyright line above the SPDX line, so it no longer demands an upstream one. Co-authored-by: Hanzo Dev <[email protected]>
108 lines
2.9 KiB
Go
108 lines
2.9 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package util
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestSanitizeErrorCredentialURLs(t *testing.T) {
|
|
err := errors.New("error with https://[email protected]")
|
|
se := SanitizeErrorCredentialURLs(err)
|
|
assert.Equal(t, "error with https://"+userInfoPlaceholder+"@b.com", se.Error())
|
|
}
|
|
|
|
func TestSanitizeCredentialURLs(t *testing.T) {
|
|
cases := []struct {
|
|
input string
|
|
expected string
|
|
}{
|
|
{
|
|
"https://github.com/hanzoai/test_repo.git",
|
|
"https://github.com/hanzoai/test_repo.git",
|
|
},
|
|
{
|
|
"https://[email protected]/hanzoai/test_repo.git",
|
|
"https://" + userInfoPlaceholder + "@github.com/hanzoai/test_repo.git",
|
|
},
|
|
{
|
|
"https://user:[email protected]/hanzoai/test_repo.git",
|
|
"https://" + userInfoPlaceholder + "@github.com/hanzoai/test_repo.git",
|
|
},
|
|
{
|
|
"https://user:password@[::]/hanzoai/test_repo.git",
|
|
"https://" + userInfoPlaceholder + "@[::]/hanzoai/test_repo.git",
|
|
},
|
|
{
|
|
"https://user:password@[2001:db8::1]:8080/hanzoai/test_repo.git",
|
|
"https://" + userInfoPlaceholder + "@[2001:db8::1]:8080/hanzoai/test_repo.git",
|
|
},
|
|
{
|
|
"see https://u:p@[::1]/x and https://u2:p2@h2",
|
|
"see https://" + userInfoPlaceholder + "@[::1]/x and https://" + userInfoPlaceholder + "@h2",
|
|
},
|
|
{
|
|
"https://user:secret@[unclosed-ipv6",
|
|
"https://user:secret@[unclosed-ipv6",
|
|
},
|
|
{
|
|
"https://user:secret@[invalid-ipv6]",
|
|
"https://user:secret@[invalid-ipv6]",
|
|
},
|
|
{
|
|
"ftp://x@",
|
|
"ftp://x@",
|
|
},
|
|
{
|
|
"ftp://x/@",
|
|
"ftp://x/@",
|
|
},
|
|
{
|
|
"ftp://u@x/@", // test multiple @ chars
|
|
"ftp://" + userInfoPlaceholder + "@x/@",
|
|
},
|
|
{
|
|
"😊ftp://u@x😊", // test unicode
|
|
"😊ftp://" + userInfoPlaceholder + "@x😊",
|
|
},
|
|
{
|
|
"://@",
|
|
"://@",
|
|
},
|
|
{
|
|
"//u:p@h",
|
|
"//" + userInfoPlaceholder + "@h",
|
|
},
|
|
{
|
|
"s://u@h",
|
|
"s://" + userInfoPlaceholder + "@h",
|
|
},
|
|
{
|
|
"URLs in log https://u:b@h and https://u:b@h:80/, with https://h.com and [email protected]",
|
|
"URLs in log https://" + userInfoPlaceholder + "@h and https://" + userInfoPlaceholder + "@h:80/, with https://h.com and [email protected]",
|
|
},
|
|
{
|
|
"fatal: unable to look up username:[email protected] (port 9418)",
|
|
"fatal: unable to look up " + userInfoPlaceholder + "@github.com (port 9418)",
|
|
},
|
|
{
|
|
"git failed for user:[email protected]/hanzoai/test_repo.git",
|
|
"git failed for " + userInfoPlaceholder + "@github.com/hanzoai/test_repo.git",
|
|
},
|
|
{
|
|
// SSH-form git URL ("git@host:path") must not let a later credential URL through
|
|
"failed remote [email protected]:foo, retried via https://user:[email protected]/foo",
|
|
"failed remote [email protected]:foo, retried via https://" + userInfoPlaceholder + "@github.com/foo",
|
|
},
|
|
}
|
|
|
|
for n, c := range cases {
|
|
result := SanitizeCredentialURLs(c.input)
|
|
assert.Equal(t, c.expected, result, "case %d: error should match", n)
|
|
}
|
|
}
|