Merge pull request 'Add an immutable tarball link to archive download headers for Nix' (#3615) from jadeprime/forgejo:jade/nix-tarball-link into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/3615 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
This commit is contained in:
commit
c9624d4cdb
4 changed files with 28 additions and 0 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
auth_model "code.gitea.io/gitea/models/auth"
|
||||
|
@ -41,6 +42,16 @@ func TestAPIDownloadArchive(t *testing.T) {
|
|||
assert.Len(t, bs, 266)
|
||||
assert.EqualValues(t, "application/gzip", resp.Header().Get("Content-Type"))
|
||||
|
||||
// Must return a link to a commit ID as the "immutable" archive link
|
||||
linkHeaderRe := regexp.MustCompile(`<(?P<url>https?://.*/api/v1/repos/user2/repo1/archive/[a-f0-9]+\.tar\.gz.*)>; rel="immutable"`)
|
||||
m := linkHeaderRe.FindStringSubmatch(resp.Header().Get("Link"))
|
||||
assert.NotEmpty(t, m[1])
|
||||
resp = MakeRequest(t, NewRequest(t, "GET", m[1]).AddTokenAuth(token), http.StatusOK)
|
||||
bs2, err := io.ReadAll(resp.Body)
|
||||
assert.NoError(t, err)
|
||||
// The locked URL should give the same bytes as the non-locked one
|
||||
assert.EqualValues(t, bs, bs2)
|
||||
|
||||
link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master.bundle", user2.Name, repo.Name))
|
||||
resp = MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK)
|
||||
bs, err = io.ReadAll(resp.Body)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue