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 files from the CLI and browser
c51874492382d08085b6388cea898d0d60ab9375 · Keenan Nemetz · 17d ago · parent 214e7ea6
Manage release files from the CLI and browser Move the attach form to its own page, add move/remove operations to the CLI and browser, and simplify the release detail page to notes, files, and source links.
server/release_attach_web_test.go +99−5
| @@ -96,10 +96,18 @@ func TestAttachFromTheBrowser(t *testing.T) { | |||
| 96 | 96 | } | |
| 97 | 97 | sess, cookie := f.browserSession(t, f.ownerID) | |
| 98 | 98 | ||
| 99 | // The release page offers the form to a maintainer, and to nobody else. | ||
| 99 | // The release page links to the attach page to a maintainer, and to nobody | ||
| 100 | // else; the multipart form itself lives on its own page. | ||
| 100 | 101 | _, page := f.browserGet(t, "/"+f.repo+"/releases/v1.0.0", cookie) | |
| 101 | if !strings.Contains(page, `enctype="multipart/form-data"`) || !strings.Contains(page, "Attach files") { | ||
| 102 | t.Fatalf("release page has no attach form:\n%s", page) | ||
| 102 | if strings.Contains(page, `enctype="multipart/form-data"`) { | ||
| 103 | t.Fatalf("release page still embeds the attach form:\n%s", page) | ||
| 104 | } | ||
| 105 | if !strings.Contains(page, "/releases/v1.0.0/attach") || !strings.Contains(page, "Attach files") { | ||
| 106 | t.Fatalf("release page has no attach link:\n%s", page) | ||
| 107 | } | ||
| 108 | resp, page := f.browserGet(t, "/"+f.repo+"/releases/v1.0.0/attach", cookie) | ||
| 109 | if resp.StatusCode != http.StatusOK || !strings.Contains(page, `enctype="multipart/form-data"`) || !strings.Contains(page, "Attach files") { | ||
| 110 | t.Fatalf("attach page = %d:\n%s", resp.StatusCode, page) | ||
| 103 | 111 | } | |
| 104 | 112 | ||
| 105 | 113 | // A flat file keeps its base name. | |
| @@ -141,6 +149,70 @@ func TestAttachFromTheBrowser(t *testing.T) { | |||
| 141 | 149 | } | |
| 142 | 150 | } | |
| 143 | 151 | ||
| 152 | func TestMoveAndDeleteFilesFromTheBrowser(t *testing.T) { | ||
| 153 | t.Parallel() | ||
| 154 | f := releaseFixture(t) | ||
| 155 | attachArtifact(t, f, "v1.0.0", "tool", []byte("the released bytes")) | ||
| 156 | attachArtifact(t, f, "v1.0.0", "apt/Packages", []byte("Package: vole\n")) | ||
| 157 | sess, cookie := f.browserSession(t, f.ownerID) | ||
| 158 | |||
| 159 | // The release page links each attached file to the edit page. | ||
| 160 | _, page := f.browserGet(t, "/"+f.repo+"/releases/v1.0.0", cookie) | ||
| 161 | for _, want := range []string{"/files/edit?path=tool", "/files/edit?path=apt%2FPackages"} { | ||
| 162 | if !strings.Contains(page, want) { | ||
| 163 | t.Fatalf("release page has no edit link %q:\n%s", want, page) | ||
| 164 | } | ||
| 165 | } | ||
| 166 | resp, page := f.browserGet(t, "/"+f.repo+"/releases/v1.0.0/files/edit?path=tool", cookie) | ||
| 167 | if resp.StatusCode != http.StatusOK || !strings.Contains(page, `name="newpath" value="tool"`) { | ||
| 168 | t.Fatalf("file edit page = %d:\n%s", resp.StatusCode, page) | ||
| 169 | } | ||
| 170 | |||
| 171 | // Rename and move are the same write: the path changes, the pointer does not. | ||
| 172 | form := url.Values{"csrf": {sess.CSRF}, "path": {"tool"}, "newpath": {"bin/tool"}} | ||
| 173 | resp, body := f.browserPost(t, "/"+f.repo+"/releases/v1.0.0/files/edit", cookie, form) | ||
| 174 | if resp.StatusCode != http.StatusSeeOther { | ||
| 175 | t.Fatalf("move file = %d:\n%s", resp.StatusCode, body) | ||
| 176 | } | ||
| 177 | m := mustRepo(t, f) | ||
| 178 | arts, err := metadata.ListReleaseArtifacts(m.Git(), "v1.0.0") | ||
| 179 | if err != nil { | ||
| 180 | t.Fatal(err) | ||
| 181 | } | ||
| 182 | if len(arts) != 2 || arts[0].Name != "apt/Packages" || arts[1].Name != "bin/tool" { | ||
| 183 | t.Fatalf("artifacts after move = %+v", arts) | ||
| 184 | } | ||
| 185 | |||
| 186 | // A destination that is already attached is refused, and the tree is untouched. | ||
| 187 | form = url.Values{"csrf": {sess.CSRF}, "path": {"bin/tool"}, "newpath": {"apt/Packages"}} | ||
| 188 | if resp, body := f.browserPost(t, "/"+f.repo+"/releases/v1.0.0/files/edit", cookie, form); resp.StatusCode != http.StatusBadRequest || !strings.Contains(body, "already attached") { | ||
| 189 | t.Fatalf("move onto an existing file = %d:\n%s", resp.StatusCode, body) | ||
| 190 | } | ||
| 191 | |||
| 192 | // Delete removes the pointer, not the other file. | ||
| 193 | form = url.Values{"csrf": {sess.CSRF}, "path": {"bin/tool"}} | ||
| 194 | resp, body = f.browserPost(t, "/"+f.repo+"/releases/v1.0.0/files/delete", cookie, form) | ||
| 195 | if resp.StatusCode != http.StatusSeeOther { | ||
| 196 | t.Fatalf("delete file = %d:\n%s", resp.StatusCode, body) | ||
| 197 | } | ||
| 198 | if arts, err := metadata.ListReleaseArtifacts(m.Git(), "v1.0.0"); err != nil || len(arts) != 1 || arts[0].Name != "apt/Packages" { | ||
| 199 | t.Fatalf("artifacts after delete = %+v %v", arts, err) | ||
| 200 | } | ||
| 201 | |||
| 202 | // The file is gone from the page and the download, and a second delete is | ||
| 203 | // refused rather than silently doing nothing. | ||
| 204 | page = waitForPage(t, f, cookie, "/"+f.repo+"/releases/v1.0.0", "apt/Packages") | ||
| 205 | if strings.Contains(page, "/artifacts/bin/tool") { | ||
| 206 | t.Fatalf("release page still names the deleted file:\n%s", page) | ||
| 207 | } | ||
| 208 | if resp, _ := f.browserGet(t, "/"+f.repo+"/releases/v1.0.0/artifacts/bin/tool", cookie); resp.StatusCode != http.StatusNotFound { | ||
| 209 | t.Fatalf("deleted download = %d, want 404", resp.StatusCode) | ||
| 210 | } | ||
| 211 | if resp, body := f.browserPost(t, "/"+f.repo+"/releases/v1.0.0/files/delete", cookie, form); resp.StatusCode != http.StatusBadRequest || !strings.Contains(body, "no longer attached") { | ||
| 212 | t.Fatalf("second delete = %d:\n%s", resp.StatusCode, body) | ||
| 213 | } | ||
| 214 | } | ||
| 215 | |||
| 144 | 216 | func TestAttachRefusalsFromTheBrowser(t *testing.T) { | |
| 145 | 217 | t.Parallel() | |
| 146 | 218 | f := newFixture(t) | |
| @@ -174,10 +246,16 @@ func TestAttachRefusalsFromTheBrowser(t *testing.T) { | |||
| 174 | 246 | if resp, body := uploadRelease(t, f, cookie, "light", sess.CSRF, "", map[string]string{"tool": "x"}); resp.StatusCode != http.StatusBadRequest || !strings.Contains(body, "lightweight") { | |
| 175 | 247 | t.Fatalf("lightweight attach = %d:\n%s", resp.StatusCode, body) | |
| 176 | 248 | } | |
| 249 | if resp, body := f.browserGet(t, "/"+f.repo+"/releases/light/attach", cookie); resp.StatusCode != http.StatusBadRequest || !strings.Contains(body, "Lightweight") { | ||
| 250 | t.Fatalf("lightweight attach page = %d:\n%s", resp.StatusCode, body) | ||
| 251 | } | ||
| 177 | 252 | // An anonymous visitor gets the login page, not the form. | |
| 178 | 253 | if resp, _ := uploadRelease(t, f, "", "v1.0.0", sess.CSRF, "", map[string]string{"tool": "x"}); resp.StatusCode != http.StatusSeeOther || !strings.HasPrefix(resp.Header.Get("Location"), "/-/login") { | |
| 179 | 254 | t.Fatalf("anonymous attach = %d %q", resp.StatusCode, resp.Header.Get("Location")) | |
| 180 | 255 | } | |
| 256 | if resp, _ := f.browserGet(t, "/"+f.repo+"/releases/v1.0.0/attach", ""); resp.StatusCode != http.StatusSeeOther || !strings.HasPrefix(resp.Header.Get("Location"), "/-/login") { | ||
| 257 | t.Fatalf("anonymous attach page = %d %q", resp.StatusCode, resp.Header.Get("Location")) | ||
| 258 | } | ||
| 181 | 259 | } | |
| 182 | 260 | ||
| 183 | 261 | // TestEditNotesAfterAttachingFiles is the change this rule set exists for: an | |
| @@ -221,6 +299,7 @@ func TestEditNotesAfterAttachingFiles(t *testing.T) { | |||
| 221 | 299 | func TestChanneledReleaseIsLockedInTheBrowser(t *testing.T) { | |
| 222 | 300 | t.Parallel() | |
| 223 | 301 | f := releaseFixture(t) | |
| 302 | attachArtifact(t, f, "v1.0.0", "tool", []byte("bytes")) | ||
| 224 | 303 | setChannel(t, f, "stable", "v1.0.0") | |
| 225 | 304 | sess, cookie := f.browserSession(t, f.ownerID) | |
| 226 | 305 | ||
| @@ -228,11 +307,26 @@ func TestChanneledReleaseIsLockedInTheBrowser(t *testing.T) { | |||
| 228 | 307 | if !strings.Contains(page, "A channel targets this release") { | |
| 229 | 308 | t.Fatalf("release page does not explain the lock:\n%s", page) | |
| 230 | 309 | } | |
| 231 | for _, unwanted := range []string{"Edit notes", `enctype="multipart/form-data"`} { | ||
| 310 | for _, unwanted := range []string{"Edit release", `enctype="multipart/form-data"`, | ||
| 311 | "/releases/v1.0.0/attach", "/releases/v1.0.0/files/edit"} { | ||
| 232 | 312 | if strings.Contains(page, unwanted) { | |
| 233 | 313 | t.Fatalf("release page still offers %q:\n%s", unwanted, page) | |
| 234 | 314 | } | |
| 235 | 315 | } | |
| 316 | for _, path := range []string{"/releases/v1.0.0/attach", "/releases/v1.0.0/files/edit?path=tool"} { | ||
| 317 | resp, body := f.browserGet(t, "/"+f.repo+path, cookie) | ||
| 318 | if resp.StatusCode != http.StatusConflict || !strings.Contains(body, "Channel stable targets this release") { | ||
| 319 | t.Fatalf("channeled %s = %d:\n%s", path, resp.StatusCode, body) | ||
| 320 | } | ||
| 321 | } | ||
| 322 | move := url.Values{"csrf": {sess.CSRF}, "path": {"tool"}, "newpath": {"bin/tool"}} | ||
| 323 | if resp, body := f.browserPost(t, "/"+f.repo+"/releases/v1.0.0/files/edit", cookie, move); resp.StatusCode != http.StatusConflict || !strings.Contains(body, "Channel stable") { | ||
| 324 | t.Fatalf("moving a file of a channeled release = %d:\n%s", resp.StatusCode, body) | ||
| 325 | } | ||
| 326 | remove := url.Values{"csrf": {sess.CSRF}, "path": {"tool"}} | ||
| 327 | if resp, body := f.browserPost(t, "/"+f.repo+"/releases/v1.0.0/files/delete", cookie, remove); resp.StatusCode != http.StatusConflict || !strings.Contains(body, "Channel stable") { | ||
| 328 | t.Fatalf("removing a file of a channeled release = %d:\n%s", resp.StatusCode, body) | ||
| 329 | } | ||
| 236 | 330 | ||
| 237 | 331 | resp, page := f.browserGet(t, "/"+f.repo+"/releases/edit?tag=v1.0.0", cookie) | |
| 238 | 332 | if resp.StatusCode != http.StatusOK || !strings.Contains(page, "Channel stable targets this release") { | |
| @@ -256,7 +350,7 @@ func TestChanneledReleaseIsLockedInTheBrowser(t *testing.T) { | |||
| 256 | 350 | } | |
| 257 | 351 | // Moving the channel re-opens the form. | |
| 258 | 352 | setChannel(t, f, "stable", "v0.9.0") | |
| 259 | if _, page := f.browserGet(t, "/"+f.repo+"/releases/v1.0.0", cookie); !strings.Contains(page, "Edit notes") { | ||
| 353 | if _, page := f.browserGet(t, "/"+f.repo+"/releases/v1.0.0", cookie); !strings.Contains(page, "Edit release") { | ||
| 260 | 354 | t.Fatalf("release page did not re-open after the channel moved:\n%s", page) | |
| 261 | 355 | } | |
| 262 | 356 | } | |