|
4 | 4 | package integration
|
5 | 5 |
|
6 | 6 | import (
|
| 7 | + "code.gitea.io/gitea/models/perm" |
| 8 | + "code.gitea.io/gitea/models/unit" |
7 | 9 | "fmt"
|
8 | 10 | "io"
|
9 | 11 | "net/http"
|
@@ -58,9 +60,12 @@ func TestAPIDownloadArchive(t *testing.T) {
|
58 | 60 |
|
59 | 61 | link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master", user2.Name, repo.Name))
|
60 | 62 | MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusBadRequest)
|
| 63 | + |
| 64 | + t.Run("GitHubStyle", testAPIDownloadArchiveGitHubStyle) |
| 65 | + t.Run("PrivateRepo", testAPIDownloadArchivePrivateRepo) |
61 | 66 | }
|
62 | 67 |
|
63 |
| -func TestAPIDownloadArchive2(t *testing.T) { |
| 68 | +func testAPIDownloadArchiveGitHubStyle(t *testing.T) { |
64 | 69 | defer tests.PrepareTestEnv(t)()
|
65 | 70 |
|
66 | 71 | repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
@@ -95,7 +100,13 @@ func TestAPIDownloadArchive2(t *testing.T) {
|
95 | 100 | bs, err = io.ReadAll(resp.Body)
|
96 | 101 | assert.NoError(t, err)
|
97 | 102 | assert.Len(t, bs, 382)
|
| 103 | +} |
98 | 104 |
|
99 |
| - link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master", user2.Name, repo.Name)) |
100 |
| - MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusBadRequest) |
| 105 | +func testAPIDownloadArchivePrivateRepo(t *testing.T) { |
| 106 | + _ = repo_model.UpdateRepositoryColsNoAutoTime(t.Context(), &repo_model.Repository{ID: 1, IsPrivate: true}, "is_private") |
| 107 | + MakeRequest(t, NewRequest(t, "HEAD", "/api/v1/repos/user2/repo1/archive/master.zip"), http.StatusNotFound) |
| 108 | + MakeRequest(t, NewRequest(t, "HEAD", "/api/v1/repos/user2/repo1/zipball/master"), http.StatusNotFound) |
| 109 | + _ = repo_model.UpdateRepoUnitPublicAccess(t.Context(), &repo_model.RepoUnit{RepoID: 1, Type: unit.TypeCode, AnonymousAccessMode: perm.AccessModeRead}) |
| 110 | + MakeRequest(t, NewRequest(t, "HEAD", "/api/v1/repos/user2/repo1/archive/master.zip"), http.StatusOK) |
| 111 | + MakeRequest(t, NewRequest(t, "HEAD", "/api/v1/repos/user2/repo1/zipball/master"), http.StatusOK) |
101 | 112 | }
|
0 commit comments