aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-11-12 10:38:22 +0800
committerGitHub <noreply@github.com>2024-11-12 02:38:22 +0000
commit580e21dd2e9dfb3a3f86f51c4eb188c1bbfa8b11 (patch)
treec09fe6839b5c2a8b1d829535a6faee4bb6d53774 /models
parentf35e2b0cd1aaee389e4efda5a54976520b9bd4cb (diff)
downloadgitea-580e21dd2e9dfb3a3f86f51c4eb188c1bbfa8b11.tar.gz
gitea-580e21dd2e9dfb3a3f86f51c4eb188c1bbfa8b11.zip
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.
Diffstat (limited to 'models')
-rw-r--r--models/fixtures/lfs_meta_object.yml18
-rw-r--r--models/migrations/v1_21/v276.go5
2 files changed, 21 insertions, 2 deletions
diff --git a/models/fixtures/lfs_meta_object.yml b/models/fixtures/lfs_meta_object.yml
index 1c29e02d44..5430506d70 100644
--- a/models/fixtures/lfs_meta_object.yml
+++ b/models/fixtures/lfs_meta_object.yml
@@ -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
diff --git a/models/migrations/v1_21/v276.go b/models/migrations/v1_21/v276.go
index ed1bc3bda5..15177bf040 100644
--- a/models/migrations/v1_21/v276.go
+++ b/models/migrations/v1_21/v276.go
@@ -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)