e2e/runnerweb_test.go

f9845abbc93ead5d74684a56f2e677be71c69587
gitbay/e2e/runnerweb_test.go history · blame · raw

48 lines · 1877 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	inst := startInstanceWith(t, "[web]\nmode = \"accounts\"\n")
14	aliceKey := inst.newKey(t, "alice")
15	inst.admin(t, "admin", "user", "create", "alice",
16		"--key", aliceKey+".pub", "--email", "alice@example.test", "--verified")
17	if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/app"); code != 0 {
18		t.Fatalf("repo create: %s", errOut)
19	}
20	runnerKey := inst.newKey(t, "laptop")
21	pub, _ := os.ReadFile(runnerKey + ".pub")
22
23	alice := inst.login(t, aliceKey)
24	settings := inst.base() + "/alice/app/settings"
25	_, body := browserGet(t, alice, settings)
26	if !strings.Contains(body, "No runners attached") {
27		t.Fatalf("empty state missing:\n%s", body)
28	}
29	if status, _ := browserPost(t, alice, settings, url.Values{"field": {"runner-add"}, "key": {string(pub)}}); status != 200 {
30		t.Fatalf("runner-add post: %d", status)
31	}
32	out, _, _ := inst.ssh(t, aliceKey, "", "repo", "runner", "list", "alice/app", "--json")
33	if !strings.Contains(out, `"fingerprint":"SHA256:`) {
34		t.Fatalf("not attached after the form: %s", out)
35	}
36	fp := out[strings.Index(out, "SHA256:"):]
37	fp = fp[:strings.Index(fp, `"`)]
38	_, body = browserGet(t, alice, settings)
39	if !strings.Contains(body, fp) || !strings.Contains(body, `value="runner-remove"`) {
40		t.Fatalf("attached runner not listed:\n%s", body)
41	}
42	if status, _ := browserPost(t, alice, settings, url.Values{"field": {"runner-remove"}, "fingerprint": {fp}}); status != 200 {
43		t.Fatalf("runner-remove post: %d", status)
44	}
45	if out, _, _ = inst.ssh(t, aliceKey, "", "repo", "runner", "list", "alice/app", "--json"); strings.Contains(out, fp) {
46		t.Fatalf("still attached after remove: %s", out)
47	}
48}