mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Refactor LFS SSH and internal routers (#32473)
Gitea instance keeps reporting a lot of errors like "LFS SSH transfer connection denied, pure SSH protocol is disabled". When starting debugging the problem, there are more problems found. Try to address most of them: * avoid unnecessary server side error logs (change `fail()` to not log them) * figure out the broken tests/user2/lfs.git (added comments) * avoid `migratePushMirrors` failure when a repository doesn't exist (ignore them) * avoid "Authorization" (internal&lfs) header conflicts, remove the tricky "swapAuth" and use "X-Gitea-Internal-Auth" * make internal token comparing constant time (it wasn't a serous problem because in a real world it's nearly impossible to timing-attack the token, but good to fix and backport) * avoid duplicate routers (introduce AddOwnerRepoGitLFSRoutes) * avoid "internal (private)" routes using session/web context (they should use private context) * fix incorrect "path" usages (use "filepath") * fix incorrect mocked route point handling (need to check func nil correctly) * split some tests from "git general tests" to "git misc tests" (to keep "git_general_test.go" simple) Still no correct result for Git LFS SSH tests. So the code is kept there (`tests/integration/git_lfs_ssh_test.go`) and a FIXME explains the details.
This commit is contained in:
@@ -1,4 +1,11 @@
|
||||
# These are the LFS objects in user2/lfs.git
|
||||
# user2/lfs is an INVALID repository
|
||||
#
|
||||
# commit e9c32647bab825977942598c0efa415de300304b (HEAD -> master)
|
||||
# Author: Rowan Bohde <rowan.bohde@gmail.com>
|
||||
# Date: Thu Aug 1 14:38:23 2024 -0500
|
||||
#
|
||||
# add invalid lfs file
|
||||
-
|
||||
|
||||
id: 1
|
||||
@@ -11,7 +18,7 @@
|
||||
|
||||
id: 2
|
||||
oid: 2eccdb43825d2a49d99d542daa20075cff1d97d9d2349a8977efe9c03661737c
|
||||
size: 107
|
||||
size: 107 # real size is 2048
|
||||
repository_id: 54
|
||||
created_unix: 1671607299
|
||||
|
||||
@@ -30,3 +37,12 @@
|
||||
size: 25
|
||||
repository_id: 54
|
||||
created_unix: 1671607299
|
||||
|
||||
# this file is missing
|
||||
# -
|
||||
#
|
||||
# id: 5
|
||||
# oid: 9d178b5f15046343fd32f451df93acc2bdd9e6373be478b968e4cad6b6647351
|
||||
# size: 25
|
||||
# repository_id: 54
|
||||
# created_unix: 1671607299
|
||||
|
@@ -12,6 +12,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
giturl "code.gitea.io/gitea/modules/git/url"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
@@ -163,7 +164,9 @@ func migratePushMirrors(x *xorm.Engine) error {
|
||||
|
||||
func getRemoteAddress(ownerName, repoName, remoteName string) (string, error) {
|
||||
repoPath := filepath.Join(setting.RepoRootPath, strings.ToLower(ownerName), strings.ToLower(repoName)+".git")
|
||||
|
||||
if exist, _ := util.IsExist(repoPath); !exist {
|
||||
return "", nil
|
||||
}
|
||||
remoteURL, err := git.GetRemoteAddress(context.Background(), repoPath, remoteName)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("get remote %s's address of %s/%s failed: %v", remoteName, ownerName, repoName, err)
|
||||
|
Reference in New Issue
Block a user