1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-06 10:37:20 +00:00

fix github migration error when using multiple tokens (#34144)

Git authorization was not taking into account multiple token feature,
leading to auth failures

Closes: https://github.com/go-gitea/gitea/issues/34141

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
TheFox0x7
2025-04-14 01:20:14 +02:00
committed by GitHub
parent bec9233c29
commit 8a6df00c53
2 changed files with 50 additions and 1 deletions

View File

@ -12,6 +12,7 @@ import (
base "code.gitea.io/gitea/modules/migration"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGitHubDownloadRepo(t *testing.T) {
@ -429,3 +430,36 @@ func TestGitHubDownloadRepo(t *testing.T) {
},
}, reviews)
}
func TestGithubMultiToken(t *testing.T) {
testCases := []struct {
desc string
token string
expectedCloneURL string
}{
{
desc: "Single Token",
token: "single_token",
expectedCloneURL: "https://oauth2:single_token@github.com",
},
{
desc: "Multi Token",
token: "token1,token2",
expectedCloneURL: "https://oauth2:token1@github.com",
},
}
factory := GithubDownloaderV3Factory{}
for _, tC := range testCases {
t.Run(tC.desc, func(t *testing.T) {
opts := base.MigrateOptions{CloneAddr: "https://github.com/go-gitea/gitea", AuthToken: tC.token}
client, err := factory.New(t.Context(), opts)
require.NoError(t, err)
cloneURL, err := client.FormatCloneURL(opts, "https://github.com")
require.NoError(t, err)
assert.Equal(t, tC.expectedCloneURL, cloneURL)
})
}
}