e2e/runnerweb_test.go
52 lines · 2070 bytes
1package e2e
2
3import (
4 "net/url"
5 "os"
6 "strings"
7 "testing"
8)
9
10// The settings page attaches and detaches runners through the same
11// commands the CLI uses, and lists what is attached.
12func TestRunnerSettingsWeb(t *testing.T) {
13 t.Parallel()
14 inst := startInstanceWith(t, "[web]\nmode = \"accounts\"\n")
15 aliceKey := inst.newKey(t, "alice")
16 inst.admin(t, "admin", "user", "create", "alice",
17 "--key", aliceKey+".pub", "--email", "alice@example.test", "--verified")
18 if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/app"); code != 0 {
19 t.Fatalf("repo create: %s", errOut)
20 }
21 runnerKey := inst.newKey(t, "laptop")
22 pub, _ := os.ReadFile(runnerKey + ".pub")
23
24 alice := inst.login(t, aliceKey)
25 settings := inst.base() + "/alice/app/settings"
26 _, body := browserGet(t, alice, settings)
27 if !strings.Contains(body, "No runners attached") {
28 t.Fatalf("empty state missing:\n%s", body)
29 }
30 if status, _ := browserPost(t, alice, settings, url.Values{"field": {"runner-add"}, "key": {string(pub)}}); status != 200 {
31 t.Fatalf("runner-add post: %d", status)
32 }
33 out, _, _ := inst.ssh(t, aliceKey, "", "repo", "runner", "list", "alice/app", "--json")
34 if !strings.Contains(out, `"fingerprint":"SHA256:`) {
35 t.Fatalf("not attached after the form: %s", out)
36 }
37 fp := out[strings.Index(out, "SHA256:"):]
38 fp = fp[:strings.Index(fp, `"`)]
39 // html/template writes + as + in text and attributes, and a
40 // fingerprint is base64, so the page shows the escaped form.
41 shown := strings.ReplaceAll(fp, "+", "+")
42 _, body = browserGet(t, alice, settings)
43 if !strings.Contains(body, shown) || !strings.Contains(body, `value="runner-remove"`) {
44 t.Fatalf("attached runner not listed:\n%s", body)
45 }
46 if status, _ := browserPost(t, alice, settings, url.Values{"field": {"runner-remove"}, "fingerprint": {fp}}); status != 200 {
47 t.Fatalf("runner-remove post: %d", status)
48 }
49 if out, _, _ = inst.ssh(t, aliceKey, "", "repo", "runner", "list", "alice/app", "--json"); strings.Contains(out, fp) {
50 t.Fatalf("still attached after remove: %s", out)
51 }
52}