e2e/dashboardbuild_test.go
49 lines · 1675 bytes
1package e2e
2
3import (
4 "strings"
5 "testing"
6)
7
8// The dashboard reports which build is serving, so the running commit is
9// visible without reading the journal. It is admin-only: the exact build a
10// host runs narrows down which known issues apply to it.
11func TestDashboardReportsTheServerBuild(t *testing.T) {
12 t.Parallel()
13 inst := startInstance(t)
14
15 adminKey := inst.newKey(t, "root")
16 userKey := inst.newKey(t, "plain")
17 inst.admin(t, "admin", "user", "create", "root", "--key", adminKey+".pub", "--admin")
18 inst.admin(t, "admin", "user", "create", "plain", "--key", userKey+".pub")
19
20 out, errOut, code := inst.ssh(t, adminKey, "", "dashboard", "--json")
21 if code != 0 {
22 t.Fatalf("admin dashboard: %s", errOut)
23 }
24 if !strings.Contains(out, `"server":{"commit":"`) {
25 t.Fatalf("admin dashboard did not report the build:\n%s", out)
26 }
27
28 // A non-admin gets the same dashboard without it. omitempty drops the key
29 // entirely rather than reporting an empty string.
30 out, errOut, code = inst.ssh(t, userKey, "", "dashboard", "--json")
31 if code != 0 {
32 t.Fatalf("user dashboard: %s", errOut)
33 }
34 if strings.Contains(out, `"server"`) {
35 t.Fatalf("a non-admin was told the server build:\n%s", out)
36 }
37 if !strings.Contains(out, `"review_queue"`) {
38 t.Fatalf("user dashboard is missing its usual contents:\n%s", out)
39 }
40
41 // Human output carries it too, for the operator who did not ask for JSON.
42 out, errOut, code = inst.ssh(t, adminKey, "", "dashboard")
43 if code != 0 {
44 t.Fatalf("admin dashboard (human): %s", errOut)
45 }
46 if !strings.Contains(out, "server:") || !strings.Contains(out, "build ") {
47 t.Fatalf("human dashboard did not report the build:\n%s", out)
48 }
49}