krz/gitbay

A CLI-first git forge.

clone: git clone https://gitbay.org/krz/gitbay.git

main: e2e/profile_test.go · raw

 1package e2e
 2
 3import (
 4	"strings"
 5	"testing"
 6)
 7
 8func TestOwnerProfiles(t *testing.T) {
 9	inst := startInstance(t)
10	aliceKey := inst.newKey(t, "alice")
11	bobKey := inst.newKey(t, "bob")
12	inst.admin(t, "admin", "user", "create", "alice", "--key", aliceKey+".pub")
13	inst.admin(t, "admin", "user", "create", "bob", "--key", bobKey+".pub")
14
15	// Self-service user profile; website validated.
16	if _, errOut, code := inst.ssh(t, aliceKey, "",
17		"profile", "set", "--description", "'builds small tools'", "--website", "https://alice.example"); code != 0 {
18		t.Fatalf("profile set: %s", errOut)
19	}
20	if _, _, code := inst.ssh(t, aliceKey, "", "profile", "set", "--website", "gopher://nope"); code != 2 {
21		t.Fatal("bad website scheme accepted")
22	}
23	out, _, _ := inst.ssh(t, bobKey, "", "profile", "show", "alice", "--json")
24	if !strings.Contains(out, `"description":"builds small tools"`) || !strings.Contains(out, `"website":"https://alice.example"`) {
25		t.Fatalf("profile show: %s", out)
26	}
27
28	// Partial update leaves the other field untouched; empty clears.
29	if _, _, code := inst.ssh(t, aliceKey, "", "profile", "set", "--description", "'tinkerer'"); code != 0 {
30		t.Fatal("partial set failed")
31	}
32	out, _, _ = inst.ssh(t, aliceKey, "", "profile", "show", "--json")
33	if !strings.Contains(out, "tinkerer") || !strings.Contains(out, "alice.example") {
34		t.Fatalf("partial update clobbered website: %s", out)
35	}
36	if _, _, code := inst.ssh(t, aliceKey, "", "profile", "set", "--website", "''"); code != 0 {
37		t.Fatal("clear failed")
38	}
39	out, _, _ = inst.ssh(t, aliceKey, "", "profile", "show", "--json")
40	if strings.Contains(out, "alice.example") {
41		t.Fatalf("website not cleared: %s", out)
42	}
43
44	// Org profile: admin sets, member cannot; no flags shows.
45	if _, _, code := inst.ssh(t, aliceKey, "", "org", "create", "workshop"); code != 0 {
46		t.Fatal("org create failed")
47	}
48	if _, _, code := inst.ssh(t, aliceKey, "", "org", "members", "add", "workshop", "bob"); code != 0 {
49		t.Fatal("member add failed")
50	}
51	if _, errOut, code := inst.ssh(t, aliceKey, "",
52		"org", "profile", "workshop", "--description", "'where things get made'", "--website", "https://workshop.example"); code != 0 {
53		t.Fatalf("org profile set: %s", errOut)
54	}
55	if _, _, code := inst.ssh(t, bobKey, "", "org", "profile", "workshop", "--description", "hax"); code != 4 {
56		t.Fatal("member set org profile")
57	}
58	out, _, _ = inst.ssh(t, bobKey, "", "org", "profile", "workshop")
59	if !strings.Contains(out, "where things get made") {
60		t.Fatalf("org profile show: %s", out)
61	}
62
63	// Owner pages render description and website link.
64	status, body := inst.get(t, "/alice")
65	if status != 200 || !strings.Contains(body, "tinkerer") {
66		t.Fatalf("user page profile: %d", status)
67	}
68	status, body = inst.get(t, "/workshop")
69	if status != 200 || !strings.Contains(body, "where things get made") ||
70		!strings.Contains(body, `href="https://workshop.example"`) {
71		t.Fatalf("org page profile: %d\n%s", status, body)
72	}
73}