summaryrefslogtreecommitdiffstats
path: root/integrations
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-11-18 03:47:35 +0800
committerGitHub <noreply@github.com>2021-11-17 14:47:35 -0500
commit81a4fc752833101dd7d6b4f612bccc4b29c98dff (patch)
tree3fc851bbdbebf63a3c684791368c33efaf077005 /integrations
parentd8a8961b99adc1554c218fee474535d4f302bd11 (diff)
downloadgitea-81a4fc752833101dd7d6b4f612bccc4b29c98dff.tar.gz
gitea-81a4fc752833101dd7d6b4f612bccc4b29c98dff.zip
Return 400 but not 500 when request archive with wrong format (#17691)
Diffstat (limited to 'integrations')
-rw-r--r--integrations/api_repo_archive_test.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/integrations/api_repo_archive_test.go b/integrations/api_repo_archive_test.go
new file mode 100644
index 0000000000..77940f4c36
--- /dev/null
+++ b/integrations/api_repo_archive_test.go
@@ -0,0 +1,52 @@
+// 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"
+ "code.gitea.io/gitea/models/unittest"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestAPIDownloadArchive(t *testing.T) {
+ defer prepareTestEnv(t)()
+
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ user2 := unittest.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.bundle", 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, 382, 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)
+}