e2e/userdelete_test.go
69 lines · 2576 bytes
1package e2e
2
3import (
4 "strings"
5 "testing"
6)
7
8func TestAdminUserDelete(t *testing.T) {
9 t.Parallel()
10 inst := startInstance(t)
11 aliceKey := inst.newKey(t, "alice")
12 inst.admin(t, "admin", "user", "create", "alice", "--key", aliceKey+".pub")
13
14 // --yes is required.
15 out := inst.forgedAdminErr(t, "admin", "user", "delete", "alice")
16 if !strings.Contains(out, "--yes") {
17 t.Fatalf("missing confirmation guard: %s", out)
18 }
19
20 // An owned repo blocks deletion, by name of the blocker.
21 if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/app"); code != 0 {
22 t.Fatalf("repo create: %s", errOut)
23 }
24 out = inst.forgedAdminErr(t, "admin", "user", "delete", "alice", "--yes")
25 if !strings.Contains(out, "owned repositories") {
26 t.Fatalf("repo blocker not reported: %s", out)
27 }
28
29 // Authored content blocks deletion after the repo is gone... the issue
30 // lives in bob's repo so it survives alice/app's deletion.
31 bobKey := inst.newKey(t, "bob")
32 inst.admin(t, "admin", "user", "create", "bob", "--key", bobKey+".pub")
33 if _, errOut, code := inst.ssh(t, bobKey, "", "repo", "create", "bob/proj"); code != 0 {
34 t.Fatalf("bob repo: %s", errOut)
35 }
36 if _, errOut, code := inst.ssh(t, aliceKey, "", "issue", "create", "bob/proj", "--title", "'from alice'"); code != 0 {
37 t.Fatalf("issue create: %s", errOut)
38 }
39 if _, _, code := inst.ssh(t, aliceKey, "", "repo", "delete", "alice/app", "--yes"); code != 0 {
40 t.Fatal("repo delete failed")
41 }
42 out = inst.forgedAdminErr(t, "admin", "user", "delete", "alice", "--yes")
43 if !strings.Contains(out, "authored issues") {
44 t.Fatalf("issue blocker not reported: %s", out)
45 }
46
47 // A clean account deletes; its key stops authenticating.
48 carolKey := inst.newKey(t, "carol")
49 inst.admin(t, "admin", "user", "create", "carol", "--key", carolKey+".pub")
50 if out := inst.admin(t, "admin", "user", "delete", "carol", "--yes"); !strings.Contains(out, "deleted carol") {
51 t.Fatalf("delete: %s", out)
52 }
53 if _, _, code := inst.ssh(t, carolKey, "", "whoami"); code == 0 {
54 t.Fatal("deleted account still authenticates")
55 }
56 out = inst.forgedAdminErr(t, "admin", "user", "delete", "carol", "--yes")
57 if !strings.Contains(out, "no user") {
58 t.Fatalf("second delete: %s", out)
59 }
60
61 // The sole admin of an org is anchored by it.
62 if _, errOut, code := inst.ssh(t, bobKey, "", "org", "create", "solo"); code != 0 {
63 t.Fatalf("org create: %s", errOut)
64 }
65 out = inst.forgedAdminErr(t, "admin", "user", "delete", "bob", "--yes")
66 if !strings.Contains(out, "no other admin") {
67 t.Fatalf("org blocker not reported: %s", out)
68 }
69}