e2e/description_test.go

0a69a8facd64e67e42ec04fa11dd4a0304e40d79
gitbay/e2e/description_test.go history · blame · raw

108 lines · 4243 bytes

  1package e2e
  2
  3import (
  4	"strings"
  5	"testing"
  6)
  7
  8func TestRepoDescriptions(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	// Set at creation; visible in show and list (human and JSON).
 14	if _, errOut, code := inst.ssh(t, aliceKey, "",
 15		"repo", "create", "alice/tool", "--description", "'a fine tool'"); code != 0 {
 16		t.Fatalf("create: %s", errOut)
 17	}
 18	out, _, _ := inst.ssh(t, aliceKey, "", "repo", "show", "alice/tool", "--json")
 19	if !strings.Contains(out, `"description":"a fine tool"`) {
 20		t.Fatalf("show json: %s", out)
 21	}
 22	out, _, _ = inst.ssh(t, aliceKey, "", "repo", "list")
 23	if !strings.Contains(out, "a fine tool") {
 24		t.Fatalf("list: %s", out)
 25	}
 26
 27	// The description lives in the bare repo's native description file.
 28	sshOut, _, _ := inst.ssh(t, aliceKey, "", "repo", "show", "alice/tool")
 29	if !strings.Contains(sshOut, "a fine tool") {
 30		t.Fatalf("show human: %s", sshOut)
 31	}
 32
 33	// Update via settings; first line only, trimmed.
 34	if _, errOut, code := inst.ssh(t, aliceKey, "",
 35		"repo", "settings", "description", "alice/tool", "'better now'"); code != 0 {
 36		t.Fatalf("settings description: %s", errOut)
 37	}
 38	out, _, _ = inst.ssh(t, aliceKey, "", "repo", "show", "alice/tool", "--json")
 39	if !strings.Contains(out, `"description":"better now"`) {
 40		t.Fatalf("updated show: %s", out)
 41	}
 42
 43	// Non-admins cannot set it.
 44	bobKey := inst.newKey(t, "bob")
 45	inst.admin(t, "admin", "user", "create", "bob", "--key", bobKey+".pub")
 46	if _, _, code := inst.ssh(t, bobKey, "", "repo", "settings", "description", "alice/tool", "hax"); code != 4 {
 47		t.Fatalf("non-admin set: exit %d, want 4", code)
 48	}
 49
 50	// Web: explore, owner page, and repo header all show it.
 51	for _, path := range []string{"/explore", "/alice", "/alice/tool"} {
 52		status, body := inst.get(t, path)
 53		if status != 200 || !strings.Contains(body, "better now") {
 54			t.Fatalf("description missing at %s (%d)", path, status)
 55		}
 56	}
 57
 58	// Website: set, shown in show and on the repo page; bad scheme and
 59	// non-admins refused.
 60	if _, errOut, code := inst.ssh(t, aliceKey, "",
 61		"repo", "settings", "website", "alice/tool", "https://tool.example.org"); code != 0 {
 62		t.Fatalf("settings website: %s", errOut)
 63	}
 64	out, _, _ = inst.ssh(t, aliceKey, "", "repo", "show", "alice/tool", "--json")
 65	if !strings.Contains(out, `"website":"https://tool.example.org"`) {
 66		t.Fatalf("website show: %s", out)
 67	}
 68	if _, body := inst.get(t, "/alice/tool"); !strings.Contains(body, `href="https://tool.example.org"`) {
 69		t.Fatalf("website missing on repo page:\n%s", body)
 70	}
 71	if _, _, code := inst.ssh(t, aliceKey, "", "repo", "settings", "website", "alice/tool", "javascript:alert(1)"); code != 2 {
 72		t.Fatalf("bad scheme accepted")
 73	}
 74	if _, _, code := inst.ssh(t, bobKey, "", "repo", "settings", "website", "alice/tool", "https://x.example"); code != 4 {
 75		t.Fatalf("non-admin set website: want exit 4")
 76	}
 77	// Clearing removes it.
 78	if _, _, code := inst.ssh(t, aliceKey, "", "repo", "settings", "website", "alice/tool", "''"); code != 0 {
 79		t.Fatal("website clear failed")
 80	}
 81	out, _, _ = inst.ssh(t, aliceKey, "", "repo", "show", "alice/tool", "--json")
 82	if strings.Contains(out, `"website"`) {
 83		t.Fatalf("website not cleared: %s", out)
 84	}
 85	if _, _, code := inst.ssh(t, aliceKey, "",
 86		"repo", "settings", "website", "alice/tool", "https://tool.example.org"); code != 0 {
 87		t.Fatal("website re-set failed")
 88	}
 89
 90	// Forks inherit the description.
 91	if _, errOut, code := inst.ssh(t, bobKey, "", "repo", "fork", "alice/tool"); code != 0 {
 92		t.Fatalf("fork: %s", errOut)
 93	}
 94	out, _, _ = inst.ssh(t, bobKey, "", "repo", "show", "bob/tool", "--json")
 95	if !strings.Contains(out, `"description":"better now"`) {
 96		t.Fatalf("fork description: %s", out)
 97	}
 98
 99	// A repo with no description set stays clean (git's placeholder is
100	// treated as empty).
101	if _, _, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/plain"); code != 0 {
102		t.Fatal("plain create failed")
103	}
104	out, _, _ = inst.ssh(t, aliceKey, "", "repo", "show", "alice/plain", "--json")
105	if strings.Contains(out, "Unnamed repository") || strings.Contains(out, `"description"`) {
106		t.Fatalf("placeholder leaked: %s", out)
107	}
108}