133728e barerepo 1mo
1
package e2e
133728e barerepo 1mo
3
import (
133728e barerepo 1mo
4
"net/http"
133728e barerepo 1mo
5
"os/exec"
133728e barerepo 1mo
6
"strings"
133728e barerepo 1mo
7
"testing"
133728e barerepo 1mo
10
// Chapter 14: a malformed config falls back to the last version that parsed, not to the defaults.
133728e barerepo 1mo
11
func TestABrokenConfigKeepsTheSettingsThatWorked(t *testing.T) {
133728e barerepo 1mo
12
if _, err := exec.LookPath("git"); err != nil {
133728e barerepo 1mo
13
t.Skip("git is not installed")
133728e barerepo 1mo
15
in := newInstance(t)
133728e barerepo 1mo
16
john := in.account("john")
133728e barerepo 1mo
17
lisa := in.account("lisa")
133728e barerepo 1mo
18
work := seed(t, in, john, "john", "johnbot")
133728e barerepo 1mo
20
write(t, work, ".barerepo/config", "[repo]\nvisibility = \"public\"\n\n[access]\npush = [\"john\", \"lisa\"]\n")
133728e barerepo 1mo
21
run(t, work, "git", "add", "-A")
133728e barerepo 1mo
22
run(t, work, "git", "commit", "-qm", "open it up and let lisa push")
133728e barerepo 1mo
23
run(t, work, "git", "push", "-q", in.url(john, "/john/johnbot"), "master")
133728e barerepo 1mo
25
// A stranger can read it and lisa can push, which is what the good file bought.
133728e barerepo 1mo
26
if code, _, _ := get(t, in.http.URL+"/john/johnbot"); code != http.StatusOK {
133728e barerepo 1mo
27
t.Fatalf("the repository is not public yet, so the test proves nothing later")
133728e barerepo 1mo
30
// One unclosed bracket, which is the shape of every real config typo.
133728e barerepo 1mo
31
write(t, work, ".barerepo/config", "[repo\nvisibility = \"public\"\n")
133728e barerepo 1mo
32
run(t, work, "git", "add", "-A")
133728e barerepo 1mo
33
run(t, work, "git", "commit", "-qm", "a typo in the config")
133728e barerepo 1mo
34
out := run(t, work, "git", "push", in.url(john, "/john/johnbot"), "master")
133728e barerepo 1mo
36
// The push that makes the typo is the one that reports it, not whoever pushes next.
133728e barerepo 1mo
37
if !strings.Contains(out, "does not parse") {
133728e barerepo 1mo
38
t.Errorf("the push that broke the file said nothing about it:\n%s", out)
133728e barerepo 1mo
41
// And every later push says which older version is doing the deciding.
133728e barerepo 1mo
42
write(t, work, "conn.go", "package irc\n")
133728e barerepo 1mo
43
run(t, work, "git", "add", "-A")
133728e barerepo 1mo
44
run(t, work, "git", "commit", "-qm", "an unrelated change")
133728e barerepo 1mo
45
later := run(t, work, "git", "push", in.url(john, "/john/johnbot"), "master")
133728e barerepo 1mo
46
if !strings.Contains(later, "does not parse") {
133728e barerepo 1mo
47
t.Errorf("a later push said nothing about the broken file:\n%s", later)
133728e barerepo 1mo
49
if !strings.Contains(later, "still in force") {
133728e barerepo 1mo
50
t.Errorf("a later push did not name the settings that are deciding:\n%s", later)
133728e barerepo 1mo
53
// The defaults are private, so a public repository is proof the old file is still being read.
133728e barerepo 1mo
54
if code, _, _ := get(t, in.http.URL+"/john/johnbot"); code != http.StatusOK {
133728e barerepo 1mo
55
t.Errorf("a typo in the config took the repository private, and chapter 14 forbids that")
133728e barerepo 1mo
58
// And the access list survived, which is the clause about not locking anyone out.
133728e barerepo 1mo
59
mineDir := clone(t, in, lisa, "/john/johnbot")
133728e barerepo 1mo
60
commit(t, mineDir, "package main\n\nfunc main() {}\n", "lisa can still push")
133728e barerepo 1mo
61
if _, err := try(t, mineDir, "git", "push", in.url(lisa, "/john/johnbot"), "master"); err != nil {
133728e barerepo 1mo
62
t.Errorf("lisa lost her push access to a typo: %v", err)
133728e barerepo 1mo
65
// A reader of the config page is reading the broken file and must be told it is not in force.
133728e barerepo 1mo
66
code, _, body := get(t, in.http.URL+"/john/johnbot/config")
133728e barerepo 1mo
67
if code != http.StatusOK {
133728e barerepo 1mo
68
t.Fatalf("the config page answered %d", code)
133728e barerepo 1mo
70
if !strings.Contains(body, "does not parse") {
133728e barerepo 1mo
71
t.Errorf("the config page shows the broken file as though it were in force:\n%s", body)