| 1 | package thintest |
| 2 | |
| 3 | import ( |
| 4 | "net/http" |
| 5 | "net/url" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | ) |
| 9 | |
| 10 | func TestPagesAutonomyOwnerOnly(t *testing.T) { |
| 11 | r := &toolRig{rig: newRig(t)} |
| 12 | owner := r.inst.Cookie() |
| 13 | principal, err := r.inst.Store.AuthenticateRunner(r.ctx, r.rig.runner) |
| 14 | if err != nil { |
| 15 | t.Fatal(err) |
| 16 | } |
| 17 | if err := r.inst.DB.G.Exec("INSERT INTO chat_projects(id,repo,state,revision) VALUES ('autonomy-project','amadan.net/oficina/sample','active',1)").Error; err != nil { |
| 18 | t.Fatal(err) |
| 19 | } |
| 20 | page := r.get(owner, "/conversation/settings/autonomy", 200) |
| 21 | for _, want := range []string{`data-settings-link="autonomy" aria-current="page"`, `What Equipo can do on its own`, `name="auto_merge_ci"`, `name="public_previews"`, `name="auto_merge_sensitive"`, `name="revision" value="0"`, `href="/conversation/settings" rel="up"`} { |
| 22 | if !strings.Contains(page, want) { |
| 23 | t.Fatalf("missing %s", want) |
| 24 | } |
| 25 | } |
| 26 | form := url.Values{"project": {"autonomy-project"}, "revision": {"0"}, "auto_merge_ci": {"on"}, "public_previews": {"on"}, "auto_merge_sensitive": {"on"}, "person": {"forged@example.com"}} |
| 27 | if code, loc := r.post(owner, "/settings/autonomy", form); code != http.StatusSeeOther || loc != "/conversation/settings/autonomy" { |
| 28 | t.Fatalf("save %d %s", code, loc) |
| 29 | } |
| 30 | var who string |
| 31 | if err := r.inst.DB.G.Raw("SELECT autonomy_owner FROM chat_projects WHERE id='autonomy-project'").Scan(&who).Error; err != nil { |
| 32 | t.Fatal(err) |
| 33 | } |
| 34 | if who != principal.Person { |
| 35 | t.Fatalf("submitted actor trusted: %s", who) |
| 36 | } |
| 37 | page = r.get(owner, "/conversation/settings/autonomy", 200) |
| 38 | if !strings.Contains(page, `name="auto_merge_ci" checked`) || !strings.Contains(page, `name="public_previews" checked`) || !strings.Contains(page, `name="auto_merge_sensitive" checked`) { |
| 39 | t.Fatal("saved choices missing") |
| 40 | } |
| 41 | if err := r.inst.DB.G.Exec("UPDATE members SET role='member' WHERE address=?", principal.Person).Error; err != nil { |
| 42 | t.Fatal(err) |
| 43 | } |
| 44 | r.get(owner, "/conversation/settings/autonomy", 403) |
| 45 | form.Set("revision", "1") |
| 46 | if code, _ := r.post(owner, "/settings/autonomy", form); code != 403 { |
| 47 | t.Fatalf("member save %d", code) |
| 48 | } |
| 49 | if strings.Contains(r.get(owner, "/conversation/settings", 200), `data-settings-link="autonomy"`) { |
| 50 | t.Fatal("member sees owner setting link") |
| 51 | } |
| 52 | } |
| 53 | |