Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Site
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software/vole.git

Self-hosted forge that lives in your Git repo.

Manage release channels from the releases page

de72893e35f2fe73bb1741b88dcbabdfb238c8b0 · Keenan Nemetz · 17d ago · parent 529a8457

Manage release channels from the releases page

Channels no longer have a separate listing page. Releases shows the
channel list, a badge on each target release, and a maintainer form
that creates, moves, and clears channels with the same validation and
audit record as the CLI.

server/channels_test.go +102−11

@@ -2,11 +2,13 @@ package server_test
2 2
3 3 // Channels are a mutable server-side alias to an immutable release: the page
4 4 // redirects, the tree serves the target's files, and moving the pointer is a
5 // maintainer action with an audit line.
5 // maintainer action with an audit line. The CLI and the releases page's form are
6 // two transports for the same writes and the same checks.
6 7
7 8 import (
8 9 "io"
9 10 "net/http"
11 "net/url"
10 12 "os"
11 13 "path/filepath"
12 14 "strings"
@@ -42,15 +44,18 @@ func TestChannelPageAndTree(t *testing.T) {
42 44 attachArtifact(t, f, "v1.0.0", "apt/Packages", data)
43 45 setChannelCLI(t, f, f.keyPath, channelWork(t, f), "stable", "v1.0.0", "Recommended for production.")
44 46
45 code, page := f.get("/" + f.repo + "/channels")
47 code, page := f.get("/" + f.repo + "/releases")
46 48 if code != 200 {
47 t.Fatalf("channels page = %d", code)
49 t.Fatalf("releases page = %d", code)
48 50 }
49 for _, want := range []string{"stable", "v1.0.0", "Recommended for production."} {
51 for _, want := range []string{"stable", "v1.0.0", "Recommended for production.", "/channels/stable"} {
50 52 if !strings.Contains(page, want) {
51 t.Fatalf("channels page does not show %q:\n%s", want, page)
53 t.Fatalf("releases page does not show %q:\n%s", want, page)
52 54 }
53 55 }
56 if strings.Contains(page, `name="channel"`) {
57 t.Fatalf("anonymous releases page exposes the channel form:\n%s", page)
58 }
54 59
55 60 if code, release := f.get("/" + f.repo + "/releases/v1.0.0"); code != 200 ||
56 61 !strings.Contains(release, "/channels/stable") {
@@ -97,6 +102,85 @@ func TestChannelPageAndTree(t *testing.T) {
97 102 }
98 103 }
99 104
105 func TestChannelWriteFromTheBrowser(t *testing.T) {
106 t.Parallel()
107 f := releaseFixture(t)
108 sess, cookie := f.browserSession(t, f.ownerID)
109
110 // The maintainer sees the form; the list itself stays readable to everyone.
111 _, page := f.browserGet(t, "/"+f.repo+"/releases", cookie)
112 for _, want := range []string{"New channel", `name="channel"`, `name="tag"`} {
113 if !strings.Contains(page, want) {
114 t.Fatalf("maintainer releases page does not show %q:\n%s", want, page)
115 }
116 }
117
118 resp, body := f.browserPost(t, "/"+f.repo+"/channels", cookie, url.Values{
119 "csrf": {sess.CSRF}, "channel": {"stable"}, "tag": {"v1.0.0"},
120 "description": {"Recommended for production."},
121 })
122 if resp.StatusCode != http.StatusSeeOther {
123 t.Fatalf("create channel = %d, want 303:\n%s", resp.StatusCode, body)
124 }
125 if got := resp.Header.Get("Location"); got != "/"+f.repo+"/releases#channels" {
126 t.Fatalf("create channel Location = %q", got)
127 }
128 _, page = f.get("/" + f.repo + "/releases")
129 for _, want := range []string{"Recommended for production.", "v1.0.0", "/channels/stable"} {
130 if !strings.Contains(page, want) {
131 t.Fatalf("releases page after create does not show %q:\n%s", want, page)
132 }
133 }
134
135 // The edit link opens the same form with the current target and description.
136 _, page = f.browserGet(t, "/"+f.repo+"/releases?channel=stable", cookie)
137 for _, want := range []string{"Edit channel stable", `value="v1.0.0"`, "Recommended for production."} {
138 if !strings.Contains(page, want) {
139 t.Fatalf("edit channel form does not show %q:\n%s", want, page)
140 }
141 }
142
143 // A second set moves the same name; it does not create a second channel.
144 resp, body = f.browserPost(t, "/"+f.repo+"/channels", cookie, url.Values{
145 "csrf": {sess.CSRF}, "channel": {"stable"}, "tag": {"v0.9.0"},
146 "description": {"Older but stable."}, "editing": {"1"},
147 })
148 if resp.StatusCode != http.StatusSeeOther {
149 t.Fatalf("move channel = %d, want 303:\n%s", resp.StatusCode, body)
150 }
151 _, page = f.get("/" + f.repo + "/releases")
152 if !strings.Contains(page, "Older but stable.") || strings.Contains(page, "Recommended for production.") {
153 t.Fatalf("releases page after move did not replace the description:\n%s", page)
154 }
155
156 // A lightweight tag is refused by the form as it is by the CLI.
157 resp, body = f.browserPost(t, "/"+f.repo+"/channels", cookie, url.Values{
158 "csrf": {sess.CSRF}, "channel": {"beta"}, "tag": {"scratch-tag"},
159 })
160 if resp.StatusCode != http.StatusBadRequest || !strings.Contains(body, "lightweight") {
161 t.Fatalf("lightweight channel target = %d, want 400:\n%s", resp.StatusCode, body)
162 }
163
164 resp, body = f.browserPost(t, "/"+f.repo+"/channels/stable/clear", cookie, url.Values{"csrf": {sess.CSRF}})
165 if resp.StatusCode != http.StatusSeeOther {
166 t.Fatalf("clear channel = %d, want 303:\n%s", resp.StatusCode, body)
167 }
168 _, page = f.get("/" + f.repo + "/releases")
169 if strings.Contains(page, "Older but stable.") || strings.Contains(page, "/channels/stable") {
170 t.Fatalf("releases page still shows the cleared channel:\n%s", page)
171 }
172
173 audit, err := os.ReadFile(f.cfg.AuditLog())
174 if err != nil {
175 t.Fatal(err)
176 }
177 for _, want := range []string{"web.channel.set", "web.channel.clear", "stable -> v1.0.0", "stable -> v0.9.0"} {
178 if !strings.Contains(string(audit), want) {
179 t.Fatalf("audit log does not contain %q:\n%s", want, audit)
180 }
181 }
182 }
183
100 184 func TestChannelDanglingTarget(t *testing.T) {
101 185 t.Parallel()
102 186 f := releaseFixture(t)
@@ -111,9 +195,9 @@ func TestChannelDanglingTarget(t *testing.T) {
111 195 t.Fatal(err)
112 196 }
113 197
114 code, page := f.get("/" + f.repo + "/channels")
198 code, page := f.get("/" + f.repo + "/releases")
115 199 if code != 200 || !strings.Contains(page, "dangling") || !strings.Contains(page, "v9.9.9") {
116 t.Fatalf("channels page = %d, want a dangling marker:\n%s", code, page)
200 t.Fatalf("releases page = %d, want a dangling marker:\n%s", code, page)
117 201 }
118 202 if code, _ := f.get("/" + f.repo + "/channels/stable"); code != 404 {
119 203 t.Fatalf("dangling channel = %d, want 404", code)
@@ -150,6 +234,13 @@ func TestChannelMoveRequiresMaintain(t *testing.T) {
150 234 t.Fatalf("contributor channel move = %v: %s, want a maintain refusal", err, errOut)
151 235 }
152 236
237 contribSess, contribCookie := f.browserSession(t, contrib.Name)
238 if resp, _ := f.browserPost(t, "/"+f.repo+"/channels", contribCookie, url.Values{
239 "csrf": {contribSess.CSRF}, "channel": {"beta"}, "tag": {"v1.0.0"},
240 }); resp.StatusCode != http.StatusNotFound {
241 t.Fatalf("contributor channel write = %d, want 404", resp.StatusCode)
242 }
243
153 244 setChannelCLI(t, f, f.addWriter(t), work, "stable", "v1.0.0", "moved")
154 245 audit, err := os.ReadFile(f.cfg.AuditLog())
155 246 if err != nil {
@@ -158,8 +249,8 @@ func TestChannelMoveRequiresMaintain(t *testing.T) {
158 249 if !strings.Contains(string(audit), "channel.set") || !strings.Contains(string(audit), "stable -> v1.0.0") {
159 250 t.Fatalf("audit log has no channel move:\n%s", audit)
160 251 }
161 if code, page := f.get("/" + f.repo + "/channels"); code != 200 || !strings.Contains(page, "v1.0.0") {
162 t.Fatalf("channel after move = %d:\n%s", code, page)
252 if code, page := f.get("/" + f.repo + "/releases"); code != 200 || !strings.Contains(page, "v1.0.0") {
253 t.Fatalf("releases page after move = %d:\n%s", code, page)
163 254 }
164 255 }
165 256
@@ -216,8 +307,8 @@ func TestChannelCLI(t *testing.T) {
216 307 if !strings.Contains(out, "stable -> v1.0.0") {
217 308 t.Fatalf("channel set output = %q", out)
218 309 }
219 if code, page := f.get("/" + f.repo + "/channels"); code != 200 || !strings.Contains(page, "CLI channel") {
220 t.Fatalf("channels page after CLI set = %d:\n%s", code, page)
310 if code, page := f.get("/" + f.repo + "/releases"); code != 200 || !strings.Contains(page, "CLI channel") {
311 t.Fatalf("releases page after CLI set = %d:\n%s", code, page)
221 312 }
222 313
223 314 out, errOut, err = f.cli(work, "release", "channel", "list")