2017-06-02 23:46:56 -04:00
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
2022-11-27 13:20:29 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2017-06-02 23:46:56 -04:00
|
|
|
|
2022-09-02 15:18:23 -04:00
|
|
|
package integration
|
2017-06-02 23:46:56 -04:00
|
|
|
|
|
|
|
import (
|
2017-06-29 11:11:38 -04:00
|
|
|
"fmt"
|
2017-06-02 23:46:56 -04:00
|
|
|
"net/http"
|
|
|
|
"testing"
|
2020-04-07 17:52:01 -04:00
|
|
|
"time"
|
2017-06-02 23:46:56 -04:00
|
|
|
|
2021-12-09 20:27:50 -05:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-16 03:53:21 -05:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2020-06-08 22:46:51 -04:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2017-12-15 16:11:02 -05:00
|
|
|
"code.gitea.io/gitea/modules/test"
|
2022-06-26 10:19:22 -04:00
|
|
|
"code.gitea.io/gitea/modules/translation"
|
2022-09-02 15:18:23 -04:00
|
|
|
"code.gitea.io/gitea/tests"
|
2017-12-15 16:11:02 -05:00
|
|
|
|
2021-05-05 23:12:50 -04:00
|
|
|
"github.com/PuerkitoBio/goquery"
|
2017-06-02 23:46:56 -04:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2017-06-29 11:11:38 -04:00
|
|
|
func createNewRelease(t *testing.T, session *TestSession, repoURL, tag, title string, preRelease, draft bool) {
|
2023-08-05 08:47:09 -04:00
|
|
|
createNewReleaseTarget(t, session, repoURL, tag, title, "master", preRelease, draft)
|
|
|
|
}
|
|
|
|
|
|
|
|
func createNewReleaseTarget(t *testing.T, session *TestSession, repoURL, tag, title, target string, preRelease, draft bool) {
|
2017-06-29 11:11:38 -04:00
|
|
|
req := NewRequest(t, "GET", repoURL+"/releases/new")
|
2017-07-07 15:36:47 -04:00
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
2017-06-29 11:11:38 -04:00
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
|
|
|
|
2020-02-25 15:28:47 -05:00
|
|
|
link, exists := htmlDoc.doc.Find("form.ui.form").Attr("action")
|
2017-06-29 11:11:38 -04:00
|
|
|
assert.True(t, exists, "The template has changed")
|
|
|
|
|
|
|
|
postData := map[string]string{
|
|
|
|
"_csrf": htmlDoc.GetCSRF(),
|
|
|
|
"tag_name": tag,
|
2023-08-05 08:47:09 -04:00
|
|
|
"tag_target": target,
|
2017-06-29 11:11:38 -04:00
|
|
|
"title": title,
|
|
|
|
"content": "",
|
|
|
|
}
|
|
|
|
if preRelease {
|
|
|
|
postData["prerelease"] = "on"
|
|
|
|
}
|
|
|
|
if draft {
|
|
|
|
postData["draft"] = "Save Draft"
|
|
|
|
}
|
|
|
|
req = NewRequestWithValues(t, "POST", link, postData)
|
|
|
|
|
2022-03-23 00:54:07 -04:00
|
|
|
resp = session.MakeRequest(t, req, http.StatusSeeOther)
|
2017-06-29 11:11:38 -04:00
|
|
|
|
2017-12-15 16:11:02 -05:00
|
|
|
test.RedirectURL(resp) // check that redirect URL exists
|
2017-06-29 11:11:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func checkLatestReleaseAndCount(t *testing.T, session *TestSession, repoURL, version, label string, count int) {
|
|
|
|
req := NewRequest(t, "GET", repoURL+"/releases")
|
2017-07-07 15:36:47 -04:00
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
2017-06-29 11:11:38 -04:00
|
|
|
|
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
2022-12-06 08:15:46 -05:00
|
|
|
labelText := htmlDoc.doc.Find("#release-list > li .detail .label").First().Text()
|
2017-06-29 11:11:38 -04:00
|
|
|
assert.EqualValues(t, label, labelText)
|
2020-11-02 18:10:22 -05:00
|
|
|
titleText := htmlDoc.doc.Find("#release-list > li .detail h4 a").First().Text()
|
2017-06-29 11:11:38 -04:00
|
|
|
assert.EqualValues(t, version, titleText)
|
|
|
|
|
|
|
|
releaseList := htmlDoc.doc.Find("#release-list > li")
|
|
|
|
assert.EqualValues(t, count, releaseList.Length())
|
|
|
|
}
|
|
|
|
|
2017-06-02 23:46:56 -04:00
|
|
|
func TestViewReleases(t *testing.T) {
|
2022-09-02 15:18:23 -04:00
|
|
|
defer tests.PrepareTestEnv(t)()
|
2017-06-02 23:46:56 -04:00
|
|
|
|
2017-06-17 00:49:45 -04:00
|
|
|
session := loginUser(t, "user2")
|
2017-06-09 20:41:36 -04:00
|
|
|
req := NewRequest(t, "GET", "/user2/repo1/releases")
|
2017-07-07 15:36:47 -04:00
|
|
|
session.MakeRequest(t, req, http.StatusOK)
|
2020-04-07 17:52:01 -04:00
|
|
|
|
|
|
|
// if CI is to slow this test fail, so lets wait a bit
|
|
|
|
time.Sleep(time.Millisecond * 100)
|
2017-06-02 23:46:56 -04:00
|
|
|
}
|
2017-06-17 23:38:24 -04:00
|
|
|
|
|
|
|
func TestViewReleasesNoLogin(t *testing.T) {
|
2022-09-02 15:18:23 -04:00
|
|
|
defer tests.PrepareTestEnv(t)()
|
2017-06-17 23:38:24 -04:00
|
|
|
|
|
|
|
req := NewRequest(t, "GET", "/user2/repo1/releases")
|
2017-07-07 15:36:47 -04:00
|
|
|
MakeRequest(t, req, http.StatusOK)
|
2017-06-17 23:38:24 -04:00
|
|
|
}
|
2017-06-29 11:11:38 -04:00
|
|
|
|
|
|
|
func TestCreateRelease(t *testing.T) {
|
2022-09-02 15:18:23 -04:00
|
|
|
defer tests.PrepareTestEnv(t)()
|
2017-06-29 11:11:38 -04:00
|
|
|
|
|
|
|
session := loginUser(t, "user2")
|
|
|
|
createNewRelease(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", false, false)
|
|
|
|
|
2022-06-26 10:19:22 -04:00
|
|
|
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", translation.NewLocale("en-US").Tr("repo.release.stable"), 4)
|
2017-06-29 11:11:38 -04:00
|
|
|
}
|
|
|
|
|
2023-11-12 14:01:24 -05:00
|
|
|
func TestDeleteRelease(t *testing.T) {
|
|
|
|
defer tests.PrepareTestEnv(t)()
|
|
|
|
|
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 57, OwnerName: "user2", LowerName: "repo-release"})
|
|
|
|
release := unittest.AssertExistsAndLoadBean(t, &repo_model.Release{TagName: "v2.0"})
|
|
|
|
assert.False(t, release.IsTag)
|
|
|
|
|
|
|
|
// Using the ID of a comment that does not belong to the repository must fail
|
|
|
|
session5 := loginUser(t, "user5")
|
|
|
|
otherRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user5", LowerName: "repo4"})
|
|
|
|
|
|
|
|
req := NewRequestWithValues(t, "POST", fmt.Sprintf("%s/releases/delete?id=%d", otherRepo.Link(), release.ID), map[string]string{
|
|
|
|
"_csrf": GetCSRF(t, session5, otherRepo.Link()),
|
|
|
|
})
|
|
|
|
session5.MakeRequest(t, req, http.StatusNotFound)
|
|
|
|
|
|
|
|
session := loginUser(t, "user2")
|
|
|
|
req = NewRequestWithValues(t, "POST", fmt.Sprintf("%s/releases/delete?id=%d", repo.Link(), release.ID), map[string]string{
|
|
|
|
"_csrf": GetCSRF(t, session, repo.Link()),
|
|
|
|
})
|
|
|
|
session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
release = unittest.AssertExistsAndLoadBean(t, &repo_model.Release{ID: release.ID})
|
|
|
|
|
|
|
|
if assert.True(t, release.IsTag) {
|
|
|
|
req = NewRequestWithValues(t, "POST", fmt.Sprintf("%s/tags/delete?id=%d", otherRepo.Link(), release.ID), map[string]string{
|
|
|
|
"_csrf": GetCSRF(t, session5, otherRepo.Link()),
|
|
|
|
})
|
|
|
|
session5.MakeRequest(t, req, http.StatusNotFound)
|
|
|
|
|
|
|
|
req = NewRequestWithValues(t, "POST", fmt.Sprintf("%s/tags/delete?id=%d", repo.Link(), release.ID), map[string]string{
|
|
|
|
"_csrf": GetCSRF(t, session, repo.Link()),
|
|
|
|
})
|
|
|
|
session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
|
|
|
|
unittest.AssertNotExistsBean(t, &repo_model.Release{ID: release.ID})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-29 11:11:38 -04:00
|
|
|
func TestCreateReleasePreRelease(t *testing.T) {
|
2022-09-02 15:18:23 -04:00
|
|
|
defer tests.PrepareTestEnv(t)()
|
2017-06-29 11:11:38 -04:00
|
|
|
|
|
|
|
session := loginUser(t, "user2")
|
|
|
|
createNewRelease(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", true, false)
|
|
|
|
|
2022-06-26 10:19:22 -04:00
|
|
|
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", translation.NewLocale("en-US").Tr("repo.release.prerelease"), 4)
|
2017-06-29 11:11:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateReleaseDraft(t *testing.T) {
|
2022-09-02 15:18:23 -04:00
|
|
|
defer tests.PrepareTestEnv(t)()
|
2017-06-29 11:11:38 -04:00
|
|
|
|
|
|
|
session := loginUser(t, "user2")
|
|
|
|
createNewRelease(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", false, true)
|
|
|
|
|
2022-06-26 10:19:22 -04:00
|
|
|
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", translation.NewLocale("en-US").Tr("repo.release.draft"), 4)
|
2017-06-29 11:11:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateReleasePaging(t *testing.T) {
|
2022-09-02 15:18:23 -04:00
|
|
|
defer tests.PrepareTestEnv(t)()
|
2017-06-29 11:11:38 -04:00
|
|
|
|
2020-06-08 22:46:51 -04:00
|
|
|
oldAPIDefaultNum := setting.API.DefaultPagingNum
|
|
|
|
defer func() {
|
|
|
|
setting.API.DefaultPagingNum = oldAPIDefaultNum
|
|
|
|
}()
|
|
|
|
setting.API.DefaultPagingNum = 10
|
|
|
|
|
2017-06-29 11:11:38 -04:00
|
|
|
session := loginUser(t, "user2")
|
2021-07-08 07:38:13 -04:00
|
|
|
// Create enough releases to have paging
|
2017-06-29 11:11:38 -04:00
|
|
|
for i := 0; i < 12; i++ {
|
|
|
|
version := fmt.Sprintf("v0.0.%d", i)
|
|
|
|
createNewRelease(t, session, "/user2/repo1", version, version, false, false)
|
|
|
|
}
|
|
|
|
createNewRelease(t, session, "/user2/repo1", "v0.0.12", "v0.0.12", false, true)
|
|
|
|
|
2022-06-26 10:19:22 -04:00
|
|
|
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.12", translation.NewLocale("en-US").Tr("repo.release.draft"), 10)
|
2017-06-29 11:11:38 -04:00
|
|
|
|
2019-02-19 02:19:28 -05:00
|
|
|
// Check that user4 does not see draft and still see 10 latest releases
|
|
|
|
session2 := loginUser(t, "user4")
|
2022-06-26 10:19:22 -04:00
|
|
|
checkLatestReleaseAndCount(t, session2, "/user2/repo1", "v0.0.11", translation.NewLocale("en-US").Tr("repo.release.stable"), 10)
|
2017-06-29 11:11:38 -04:00
|
|
|
}
|
2021-05-05 23:12:50 -04:00
|
|
|
|
|
|
|
func TestViewReleaseListNoLogin(t *testing.T) {
|
2022-09-02 15:18:23 -04:00
|
|
|
defer tests.PrepareTestEnv(t)()
|
2021-05-05 23:12:50 -04:00
|
|
|
|
2023-04-18 15:11:17 -04:00
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 57, OwnerName: "user2", LowerName: "repo-release"})
|
2021-05-05 23:12:50 -04:00
|
|
|
|
|
|
|
link := repo.Link() + "/releases"
|
|
|
|
|
|
|
|
req := NewRequest(t, "GET", link)
|
|
|
|
rsp := MakeRequest(t, req, http.StatusOK)
|
|
|
|
|
|
|
|
htmlDoc := NewHTMLParser(t, rsp.Body)
|
|
|
|
releases := htmlDoc.Find("#release-list li.ui.grid")
|
2023-05-09 23:43:55 -04:00
|
|
|
assert.Equal(t, 5, releases.Length())
|
2021-05-05 23:12:50 -04:00
|
|
|
|
2023-05-09 23:43:55 -04:00
|
|
|
links := make([]string, 0, 5)
|
|
|
|
commitsToMain := make([]string, 0, 5)
|
2021-05-05 23:12:50 -04:00
|
|
|
releases.Each(func(i int, s *goquery.Selection) {
|
|
|
|
link, exist := s.Find(".release-list-title a").Attr("href")
|
|
|
|
if !exist {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
links = append(links, link)
|
2023-04-18 15:11:17 -04:00
|
|
|
|
|
|
|
commitsToMain = append(commitsToMain, s.Find(".ahead > a").Text())
|
2021-05-05 23:12:50 -04:00
|
|
|
})
|
|
|
|
|
2023-04-18 15:11:17 -04:00
|
|
|
assert.EqualValues(t, []string{
|
2023-05-09 23:43:55 -04:00
|
|
|
"/user2/repo-release/releases/tag/empty-target-branch",
|
|
|
|
"/user2/repo-release/releases/tag/non-existing-target-branch",
|
2023-04-18 15:11:17 -04:00
|
|
|
"/user2/repo-release/releases/tag/v2.0",
|
|
|
|
"/user2/repo-release/releases/tag/v1.1",
|
|
|
|
"/user2/repo-release/releases/tag/v1.0",
|
|
|
|
}, links)
|
|
|
|
assert.EqualValues(t, []string{
|
2023-05-09 23:43:55 -04:00
|
|
|
"1 commits", // like v1.1
|
|
|
|
"1 commits", // like v1.1
|
2023-04-18 15:11:17 -04:00
|
|
|
"0 commits",
|
|
|
|
"1 commits", // should be 3 commits ahead and 2 commits behind, but not implemented yet
|
|
|
|
"3 commits",
|
|
|
|
}, commitsToMain)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestViewSingleReleaseNoLogin(t *testing.T) {
|
|
|
|
defer tests.PrepareTestEnv(t)()
|
|
|
|
|
|
|
|
req := NewRequest(t, "GET", "/user2/repo-release/releases/tag/v1.0")
|
|
|
|
resp := MakeRequest(t, req, http.StatusOK)
|
|
|
|
|
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
|
|
|
// check the "number of commits to main since this release"
|
|
|
|
releaseList := htmlDoc.doc.Find("#release-list .ahead > a")
|
|
|
|
assert.EqualValues(t, 1, releaseList.Length())
|
|
|
|
assert.EqualValues(t, "3 commits", releaseList.First().Text())
|
2021-05-05 23:12:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestViewReleaseListLogin(t *testing.T) {
|
2022-09-02 15:18:23 -04:00
|
|
|
defer tests.PrepareTestEnv(t)()
|
2021-05-05 23:12:50 -04:00
|
|
|
|
2022-08-15 22:22:25 -04:00
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
2021-05-05 23:12:50 -04:00
|
|
|
|
|
|
|
link := repo.Link() + "/releases"
|
|
|
|
|
|
|
|
session := loginUser(t, "user1")
|
|
|
|
req := NewRequest(t, "GET", link)
|
|
|
|
rsp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
|
|
|
|
htmlDoc := NewHTMLParser(t, rsp.Body)
|
|
|
|
releases := htmlDoc.Find("#release-list li.ui.grid")
|
2021-06-17 04:58:10 -04:00
|
|
|
assert.Equal(t, 3, releases.Length())
|
2021-05-05 23:12:50 -04:00
|
|
|
|
|
|
|
links := make([]string, 0, 5)
|
|
|
|
releases.Each(func(i int, s *goquery.Selection) {
|
|
|
|
link, exist := s.Find(".release-list-title a").Attr("href")
|
|
|
|
if !exist {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
links = append(links, link)
|
|
|
|
})
|
|
|
|
|
2021-06-17 04:58:10 -04:00
|
|
|
assert.EqualValues(t, []string{
|
|
|
|
"/user2/repo1/releases/tag/draft-release",
|
|
|
|
"/user2/repo1/releases/tag/v1.0",
|
|
|
|
"/user2/repo1/releases/tag/v1.1",
|
|
|
|
}, links)
|
2021-05-05 23:12:50 -04:00
|
|
|
}
|
|
|
|
|
2023-08-05 08:47:09 -04:00
|
|
|
func TestReleaseOnCommit(t *testing.T) {
|
|
|
|
defer tests.PrepareTestEnv(t)()
|
|
|
|
|
|
|
|
session := loginUser(t, "user2")
|
|
|
|
createNewReleaseTarget(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", "65f1bf27bc3bf70f64657658635e66094edbcb4d", false, false)
|
|
|
|
|
|
|
|
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", translation.NewLocale("en-US").Tr("repo.release.stable"), 4)
|
|
|
|
}
|
|
|
|
|
2021-05-05 23:12:50 -04:00
|
|
|
func TestViewTagsList(t *testing.T) {
|
2022-09-02 15:18:23 -04:00
|
|
|
defer tests.PrepareTestEnv(t)()
|
2021-05-05 23:12:50 -04:00
|
|
|
|
2022-08-15 22:22:25 -04:00
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
2021-05-05 23:12:50 -04:00
|
|
|
|
|
|
|
link := repo.Link() + "/tags"
|
|
|
|
|
|
|
|
session := loginUser(t, "user1")
|
|
|
|
req := NewRequest(t, "GET", link)
|
|
|
|
rsp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
|
|
|
|
htmlDoc := NewHTMLParser(t, rsp.Body)
|
|
|
|
tags := htmlDoc.Find(".tag-list tr")
|
2021-06-17 04:58:10 -04:00
|
|
|
assert.Equal(t, 3, tags.Length())
|
2021-05-05 23:12:50 -04:00
|
|
|
|
|
|
|
tagNames := make([]string, 0, 5)
|
|
|
|
tags.Each(func(i int, s *goquery.Selection) {
|
2023-02-13 12:59:59 -05:00
|
|
|
tagNames = append(tagNames, s.Find(".tag a.gt-df.gt-ac").Text())
|
2021-05-05 23:12:50 -04:00
|
|
|
})
|
|
|
|
|
2021-06-17 04:58:10 -04:00
|
|
|
assert.EqualValues(t, []string{"v1.0", "delete-tag", "v1.1"}, tagNames)
|
2021-05-05 23:12:50 -04:00
|
|
|
}
|
2023-10-01 07:54:11 -04:00
|
|
|
|
|
|
|
func TestDownloadReleaseAttachment(t *testing.T) {
|
|
|
|
defer tests.PrepareTestEnv(t)()
|
|
|
|
|
|
|
|
tests.PrepareAttachmentsStorage(t)
|
|
|
|
|
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
|
|
|
|
|
|
|
|
url := repo.Link() + "/releases/download/v1.1/README.md"
|
|
|
|
|
|
|
|
req := NewRequest(t, "GET", url)
|
|
|
|
MakeRequest(t, req, http.StatusNotFound)
|
|
|
|
|
|
|
|
req = NewRequest(t, "GET", url)
|
|
|
|
session := loginUser(t, "user2")
|
|
|
|
session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
}
|