vole
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software:2222/vole.git
A free and open-source forge that lives in your Git repo.
|
701232cf
Keenan Nemetz
12d ago
|
1 | package server |
| 2 | ||
| 3 | // The LFS batch response tells a git-lfs client where to download from. That href | |
| 4 | // is followed by the client, so it must not be a host the caller chose. | |
| 5 | ||
| 6 | import ( | |
| 7 | "net/http/httptest" | |
| 8 | "strings" | |
| 9 | "testing" | |
| 10 | ||
|
d37d301f
Keenan Nemetz
19h ago
|
11 | "rodent.software/vole/forge/config" |
|
701232cf
Keenan Nemetz
12d ago
|
12 | ) |
| 13 | ||
| 14 | func TestLFSObjectBasePrefersTheConfiguredOrigin(t *testing.T) { | |
| 15 | t.Parallel() | |
| 16 | s := &Server{Cfg: &config.Config{PublicURL: "https://forge.example.com"}} | |
|
ed03b3d1
Keenan Nemetz
6h ago
|
17 | r := httptest.NewRequest("POST", "/demo.git"+objectShard+"objects/batch", nil) |
|
701232cf
Keenan Nemetz
12d ago
|
18 | r.Host = "evil.example" |
| 19 | r.Header.Set("X-Forwarded-Proto", "http") | |
| 20 | ||
| 21 | got := s.lfsObjectBase(r, "demo") | |
|
ed03b3d1
Keenan Nemetz
6h ago
|
22 | if !strings.HasPrefix(got, "https://forge.example.com/demo.git") { |
|
701232cf
Keenan Nemetz
12d ago
|
23 | t.Fatalf("lfsObjectBase = %q, want the configured origin", got) |
| 24 | } | |
| 25 | if strings.Contains(got, "evil.example") { | |
| 26 | t.Fatalf("lfsObjectBase followed the request Host: %q", got) | |
| 27 | } | |
| 28 | } | |
| 29 | ||
| 30 | func TestLFSObjectBaseHonoursForwardedHeadersOnlyBehindAProxy(t *testing.T) { | |
| 31 | t.Parallel() | |
|
ed03b3d1
Keenan Nemetz
6h ago
|
32 | r := httptest.NewRequest("POST", "/demo.git"+objectShard+"objects/batch", nil) |
|
701232cf
Keenan Nemetz
12d ago
|
33 | r.Host = "127.0.0.1:8080" |
| 34 | r.Header.Set("X-Forwarded-Proto", "https") | |
| 35 | ||
| 36 | s := &Server{Cfg: &config.Config{}} | |
| 37 | if got := s.lfsObjectBase(r, "demo"); !strings.HasPrefix(got, "http://127.0.0.1:8080/") { | |
| 38 | t.Fatalf("without a declared proxy lfsObjectBase = %q", got) | |
| 39 | } | |
| 40 | s = &Server{Cfg: &config.Config{GitHTTPClientIPHeader: "X-Forwarded-For"}} | |
| 41 | if got := s.lfsObjectBase(r, "demo"); !strings.HasPrefix(got, "https://127.0.0.1:8080/") { | |
| 42 | t.Fatalf("behind a declared proxy lfsObjectBase = %q", got) | |
| 43 | } | |
| 44 | } |