mirror of
https://github.com/go-gitea/gitea
synced 2024-12-25 18:14:28 +00:00
a08856606e
* Return 400 but not 500 when request archive with wrong format (#17691) * Remove bundle because it's not in this version
45 lines
1.5 KiB
Go
45 lines
1.5 KiB
Go
// Copyright 2021 The Gitea Authors. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package integrations
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"net/url"
|
|
"testing"
|
|
|
|
"code.gitea.io/gitea/models"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestAPIDownloadArchive(t *testing.T) {
|
|
defer prepareTestEnv(t)()
|
|
|
|
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
|
|
user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
|
|
session := loginUser(t, user2.LowerName)
|
|
token := getTokenForLoggedInUser(t, session)
|
|
|
|
link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master.zip", user2.Name, repo.Name))
|
|
link.RawQuery = url.Values{"token": {token}}.Encode()
|
|
resp := MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
|
|
bs, err := io.ReadAll(resp.Body)
|
|
assert.NoError(t, err)
|
|
assert.EqualValues(t, 320, len(bs))
|
|
|
|
link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master.tar.gz", user2.Name, repo.Name))
|
|
link.RawQuery = url.Values{"token": {token}}.Encode()
|
|
resp = MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
|
|
bs, err = io.ReadAll(resp.Body)
|
|
assert.NoError(t, err)
|
|
assert.EqualValues(t, 266, len(bs))
|
|
|
|
link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master", user2.Name, repo.Name))
|
|
link.RawQuery = url.Values{"token": {token}}.Encode()
|
|
MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusBadRequest)
|
|
}
|