vole
Clone
Read only, no credentials:
https://rodent.software/git/vole.git
Write over SSH with a registered key:
git clone ssh://git@0.0.0.0:2222/vole.git
A free and open-source forge that lives in your Git repo.
|
ed03b3d1
Keenan Nemetz
3h ago
|
1 | package server_test |
| 2 | ||
| 3 | // A repository owns the root of the URL space: /<name> is its page and | |
| 4 | // /<name>.git is its Git transport. The forge's own pages live under /-/, a | |
| 5 | // prefix no repository name can start with, so the two never compete. | |
| 6 | ||
| 7 | import ( | |
| 8 | "net/http" | |
| 9 | "strings" | |
| 10 | "testing" | |
| 11 | ||
| 12 | "rodent.software/vole/forge/config" | |
| 13 | ) | |
| 14 | ||
| 15 | func TestRepositoryOwnsTheRootOfTheURLSpace(t *testing.T) { | |
| 16 | t.Parallel() | |
| 17 | f := newFixture(t) | |
| 18 | f.publish(f.repo) | |
| 19 | ||
| 20 | code, body := f.get("/" + f.repo) | |
| 21 | if code != http.StatusOK { | |
| 22 | t.Fatalf("/%s = %d", f.repo, code) | |
| 23 | } | |
| 24 | if !strings.Contains(body, f.repo) || !strings.Contains(body, `class="repohead"`) { | |
| 25 | t.Fatalf("/%s is not the repository page:\n%s", f.repo, body) | |
| 26 | } | |
| 27 | ||
| 28 | // The transport is the same name with .git, so the page a person opens and | |
| 29 | // the URL a clone uses agree. | |
| 30 | code, _ = f.get("/" + f.repo + ".git/info/refs?service=git-upload-pack") | |
| 31 | if code != http.StatusOK { | |
| 32 | t.Fatalf("/%s.git/info/refs = %d, want a clone advertisement", f.repo, code) | |
| 33 | } | |
| 34 | // A bare .git names no repository and is not a page either. | |
| 35 | if code, _ := f.get("/" + f.repo + ".git"); code != http.StatusNotFound { | |
| 36 | t.Fatalf("/%s.git = %d, want 404", f.repo, code) | |
| 37 | } | |
| 38 | ||
| 39 | // The forge's own pages answer under /-/. | |
| 40 | if code, _ := f.get("/-/healthz"); code != http.StatusOK { | |
| 41 | t.Fatalf("/-/healthz = %d", code) | |
| 42 | } | |
| 43 | if code, _ := f.get("/-/static/vole.css"); code != http.StatusOK { | |
| 44 | t.Fatalf("/-/static/vole.css = %d", code) | |
| 45 | } | |
| 46 | ||
| 47 | // The paths this layout replaced are gone rather than aliased. | |
| 48 | for _, path := range []string{ | |
| 49 | "/r/" + f.repo, | |
| 50 | "/git/" + f.repo + ".git/info/refs?service=git-upload-pack", | |
| 51 | "/static/vole.css", | |
| 52 | "/u/" + f.ownerID, | |
| 53 | "/login", | |
| 54 | } { | |
| 55 | if code, _ := f.get(path); code != http.StatusNotFound { | |
| 56 | t.Fatalf("%s = %d, want 404", path, code) | |
| 57 | } | |
| 58 | } | |
| 59 | } | |
| 60 | ||
| 61 | // A repository named like a forge page is an ordinary repository: nothing has to | |
| 62 | // avoid the forge's vocabulary, only the four root paths the forge keeps. | |
| 63 | func TestRepositoryNameNeedNotAvoidTheForge(t *testing.T) { | |
| 64 | t.Parallel() | |
| 65 | f := newFixture(t) | |
| 66 | m, err := f.srv.Repos.Create("admin", f.ownerID, "an ordinary repository") | |
| 67 | if err != nil { | |
| 68 | t.Fatal(err) | |
| 69 | } | |
| 70 | if err := f.srv.Index.Upsert(m); err != nil { | |
| 71 | t.Fatal(err) | |
| 72 | } | |
| 73 | f.publish("admin") | |
| 74 | ||
| 75 | code, body := f.get("/admin") | |
| 76 | if code != http.StatusOK { | |
| 77 | t.Fatalf("/admin = %d, want the repository page", code) | |
| 78 | } | |
| 79 | if !strings.Contains(body, "an ordinary repository") { | |
| 80 | t.Fatalf("/admin is not the repository:\n%s", body) | |
| 81 | } | |
| 82 | // The forge's own surface is still its own URL. | |
| 83 | if code, _ := f.get("/-/u/" + f.ownerID); code != http.StatusOK { | |
| 84 | t.Fatalf("/-/u/%s = %d", f.ownerID, code) | |
| 85 | } | |
| 86 | } | |
| 87 | ||
| 88 | // With the anonymous transport off, <name>.git is not a transport at all; the | |
| 89 | // path falls through to the router and answers like any unknown URL. | |
| 90 | func TestGitTransportIsAbsentWhenGitHTTPIsOff(t *testing.T) { | |
| 91 | t.Parallel() | |
| 92 | f := newFixtureWith(t, func(c *config.Config) { c.GitHTTP = false }) | |
| 93 | f.publish(f.repo) | |
| 94 | for _, path := range []string{ | |
| 95 | "/" + f.repo + ".git/info/refs?service=git-upload-pack", | |
| 96 | "/" + f.repo + ".git/git-upload-pack", | |
| 97 | } { | |
| 98 | if code, _ := f.get(path); code != http.StatusNotFound { | |
| 99 | t.Fatalf("%s = %d, want 404", path, code) | |
| 100 | } | |
| 101 | } | |
| 102 | } |