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]>
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package git
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"path/filepath"
|
|
"sync/atomic"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestRepoIsEmpty(t *testing.T) {
|
|
emptyRepo2Path := filepath.Join(testReposDir, "repo2_empty")
|
|
repo, err := OpenRepository(t.Context(), emptyRepo2Path)
|
|
assert.NoError(t, err)
|
|
defer repo.Close()
|
|
isEmpty, err := repo.IsEmpty()
|
|
assert.NoError(t, err)
|
|
assert.True(t, isEmpty)
|
|
}
|
|
|
|
// TestCloneRefusesRedirects ensures Clone never follows HTTP redirects, so a remote
|
|
// cannot redirect to an otherwise-blocked address (SSRF, e.g. during migration).
|
|
func TestCloneRefusesRedirects(t *testing.T) {
|
|
var targetHit atomic.Bool
|
|
target := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
targetHit.Store(true)
|
|
w.WriteHeader(http.StatusNotFound)
|
|
}))
|
|
defer target.Close()
|
|
|
|
redirect := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
http.Redirect(w, r, target.URL+r.URL.Path, http.StatusFound)
|
|
}))
|
|
defer redirect.Close()
|
|
|
|
err := Clone(t.Context(), redirect.URL, filepath.Join(t.TempDir(), "dst"), CloneRepoOptions{})
|
|
assert.Error(t, err)
|
|
assert.False(t, targetHit.Load(), "git must not follow the redirect to the target")
|
|
}
|