e2e/webonly_test.go
93 lines · 3366 bytes
1package e2e
2
3import (
4 "os"
5 "path/filepath"
6 "strings"
7 "testing"
8)
9
10// The three reads that were reachable only in a browser: history at a
11// ref, an archive, and the public listing. Each existed as a web route
12// whose handler went around the registry, so no other surface had them.
13func TestWebOnlyReadsAreCommands(t *testing.T) {
14 inst := startInstance(t)
15 aliceKey := inst.newKey(t, "alice")
16 bobKey := inst.newKey(t, "bob")
17 inst.admin(t, "admin", "user", "create", "alice",
18 "--key", aliceKey+".pub", "--email", "alice@example.test", "--verified")
19 inst.admin(t, "admin", "user", "create", "bob", "--key", bobKey+".pub")
20
21 if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/app"); code != 0 {
22 t.Fatalf("repo create: %s", errOut)
23 }
24 work := t.TempDir()
25 env := inst.gitEnv(aliceKey)
26 mustGit(t, work, env, "clone", inst.sshURL("alice/app"), "w")
27 dir := filepath.Join(work, "w")
28
29 os.WriteFile(filepath.Join(dir, "f.txt"), []byte("main line\n"), 0o644)
30 mustGit(t, dir, env, "checkout", "-q", "-b", "main")
31 mustGit(t, dir, env, "add", ".")
32 mustGit(t, dir, env, "commit", "-q", "-m", "on main")
33 mustGit(t, dir, env, "push", "-q", "origin", "main")
34
35 mustGit(t, dir, env, "checkout", "-q", "-b", "side")
36 os.WriteFile(filepath.Join(dir, "f.txt"), []byte("side line\n"), 0o644)
37 mustGit(t, dir, env, "add", ".")
38 mustGit(t, dir, env, "commit", "-q", "-m", "only on side")
39 mustGit(t, dir, env, "push", "-q", "origin", "side")
40
41 // --- history at a ref ---
42 out, errOut, code := inst.ssh(t, aliceKey, "", "repo", "log", "alice/app", "--json")
43 if code != 0 {
44 t.Fatalf("repo log: %s", errOut)
45 }
46 if strings.Contains(out, "only on side") {
47 t.Error("the default branch log carried a side-branch commit")
48 }
49 out, errOut, code = inst.ssh(t, aliceKey, "", "repo", "log", "alice/app", "--ref", "side", "--json")
50 if code != 0 {
51 t.Fatalf("repo log --ref: %s", errOut)
52 }
53 if !strings.Contains(out, "only on side") {
54 t.Errorf("log at a ref missed its commit: %s", out)
55 }
56 if _, _, code := inst.ssh(t, aliceKey, "", "repo", "log", "alice/app", "--ref", "nope"); code == 0 {
57 t.Error("an unknown ref resolved")
58 }
59
60 // --- archive ---
61 out, errOut, code = inst.ssh(t, aliceKey, "", "repo", "download", "alice/app")
62 if code != 0 {
63 t.Fatalf("repo download: %s", errOut)
64 }
65 // A gzip stream, not an error page: magic bytes 0x1f 0x8b.
66 if len(out) < 2 || out[0] != 0x1f || out[1] != 0x8b {
67 t.Errorf("repo download did not produce gzip (%d bytes)", len(out))
68 }
69 if _, _, code := inst.ssh(t, aliceKey, "", "repo", "download", "alice/app", "--ref", "nope"); code == 0 {
70 t.Error("archived an unknown ref")
71 }
72
73 // --- the public listing ---
74 if _, _, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/hidden", "--private"); code != 0 {
75 t.Fatal("private repo create")
76 }
77 out, errOut, code = inst.ssh(t, bobKey, "", "explore", "--json")
78 if code != 0 {
79 t.Fatalf("explore: %s", errOut)
80 }
81 if !strings.Contains(out, `"path":"alice/app"`) {
82 t.Errorf("explore missed a public repository: %s", out)
83 }
84 if strings.Contains(out, "alice/hidden") {
85 t.Errorf("explore leaked a private repository: %s", out)
86 }
87
88 // Paginated like the other listings.
89 out, _, code = inst.ssh(t, bobKey, "", "explore", "--limit", "1", "--json")
90 if code != 0 || !strings.Contains(out, `"items"`) {
91 t.Fatalf("explore --limit: %s", out)
92 }
93}