test: consolidate Go tests (#39962)

Consolidate all Go tests. Coverage is identical to before. Go tests are
around 5% faster while being 7% smaller. No non-test code is touched.
This commit is contained in:
silverwind authored and GitHub committed 2026-10-24 13:48:19 +00:00
1 parent ce7364e215
commit 8abda62312
388 files changed
+18410 -29561

No files matched your search

+22 -24
View File
@@ -130,28 +130,26 @@ func TestMirrorPull(t *testing.T) {
mirror = unittest.AssertExistsAndLoadBean(t, &repo_model.Mirror{RepoID: mirrorRepo.ID})
assert.Equal(t, lastMirrorSync, mirror.LastSyncUnix)
}
// TestMirrorPullSSRFRevalidation ensures a pull mirror re-validates its remote URL against
// the migration allow/block list on every sync, so a mirror whose (network) remote now
// points at a disallowed internal host is never fetched.
func TestMirrorPullSSRFRevalidation(t *testing.T) {
defer tests.PrepareTestEnv(t)()
ctx := t.Context()
var requests atomic.Int32
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
requests.Add(1)
http.Redirect(w, r, "http://"+strings.Replace(r.Host, "127.0.0.1", "0.0.0.0", 1)+r.URL.RequestURI(), http.StatusFound)
}))
defer server.Close()
mirror := unittest.AssertExistsAndLoadBean(t, &repo_model.Mirror{RepoID: 5})
require.NoError(t, mirror_service.UpdateAddress(ctx, mirror, server.URL+"/repo.git"))
assert.False(t, mirror_service.SyncPullMirror(ctx, mirror.RepoID))
assert.EqualValues(t, 1, requests.Load(), "the git proxy must deny the redirect to a reserved address")
defer test.MockVariableValue(&setting.Migrations.AllowedHostList, "")()
assert.False(t, mirror_service.SyncPullMirror(ctx, mirror.RepoID))
assert.EqualValues(t, 1, requests.Load(), "the disallowed internal remote must not be reached")
// TestMirrorPullSSRFRevalidation ensures a pull mirror re-validates its remote URL against
// the migration allow/block list on every sync, so a mirror whose (network) remote now
// points at a disallowed internal host is never fetched.
t.Run("SSRFRevalidation", func(t *testing.T) {
ctx := t.Context()
var requests atomic.Int32
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
requests.Add(1)
http.Redirect(w, r, "http://"+strings.Replace(r.Host, "127.0.0.1", "0.0.0.0", 1)+r.URL.RequestURI(), http.StatusFound)
}))
defer server.Close()
mirror := unittest.AssertExistsAndLoadBean(t, &repo_model.Mirror{RepoID: 5})
require.NoError(t, mirror_service.UpdateAddress(ctx, mirror, server.URL+"/repo.git"))
assert.False(t, mirror_service.SyncPullMirror(ctx, mirror.RepoID))
assert.EqualValues(t, 1, requests.Load(), "the git proxy must deny the redirect to a reserved address")
defer test.MockVariableValue(&setting.Migrations.AllowedHostList, "")()
assert.False(t, mirror_service.SyncPullMirror(ctx, mirror.RepoID))
assert.EqualValues(t, 1, requests.Load(), "the disallowed internal remote must not be reached")
})
}