2021-11-17 14:47:35 -05:00
|
|
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
2022-11-27 13:20:29 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2021-11-17 14:47:35 -05:00
|
|
|
|
2022-09-02 14:18:23 -05:00
|
|
|
package integration
|
2021-11-17 14:47:35 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
"testing"
|
|
|
|
|
2023-01-17 16:46:03 -05:00
|
|
|
auth_model "code.gitea.io/gitea/models/auth"
|
2021-12-09 20:27:50 -05:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-17 14:47:35 -05:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2021-11-24 04:49:20 -05:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2022-09-02 14:18:23 -05:00
|
|
|
"code.gitea.io/gitea/tests"
|
2021-11-17 14:47:35 -05:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAPIDownloadArchive(t *testing.T) {
|
2022-09-02 14:18:23 -05:00
|
|
|
defer tests.PrepareTestEnv(t)()
|
2021-11-17 14:47:35 -05:00
|
|
|
|
2022-08-15 21:22:25 -05:00
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
|
|
|
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
2021-11-17 14:47:35 -05:00
|
|
|
session := loginUser(t, user2.LowerName)
|
2023-01-17 16:46:03 -05:00
|
|
|
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeRepo)
|
2021-11-17 14:47:35 -05:00
|
|
|
|
|
|
|
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)
|
2023-04-22 16:56:27 -05:00
|
|
|
assert.Len(t, bs, 320)
|
2021-11-17 14:47:35 -05:00
|
|
|
|
|
|
|
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)
|
2023-04-22 16:56:27 -05:00
|
|
|
assert.Len(t, bs, 266)
|
2021-11-17 14:47:35 -05:00
|
|
|
|
|
|
|
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)
|
2023-04-22 16:56:27 -05:00
|
|
|
assert.Len(t, bs, 382)
|
2021-11-17 14:47:35 -05:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|