e2e/userdelete_test.go

3f4afd2210627e46fd0cea1f5831857af71638f6
gitbay/e2e/userdelete_test.go history · blame · raw

68 lines · 2562 bytes

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