mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-23 23:42:51 +02:00
fix more tests
This commit is contained in:
parent
d9e9d0bf5a
commit
41c1e208b9
@ -31,7 +31,7 @@ func TestAPIRepoBranchesPlain(t *testing.T) {
|
|||||||
|
|
||||||
// public only token should be forbidden
|
// public only token should be forbidden
|
||||||
publicOnlyToken := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopePublicOnly, auth_model.AccessTokenScopeWriteRepository)
|
publicOnlyToken := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopePublicOnly, auth_model.AccessTokenScopeWriteRepository)
|
||||||
link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/org3/%s/branches", repo3.Name)) // a plain repo
|
link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/org3/%s%s/branches", maybeGroupSegment(repo3.GroupID), repo3.Name)) // a plain repo
|
||||||
MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(publicOnlyToken), http.StatusForbidden)
|
MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(publicOnlyToken), http.StatusForbidden)
|
||||||
|
|
||||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
|
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
|
||||||
@ -45,7 +45,7 @@ func TestAPIRepoBranchesPlain(t *testing.T) {
|
|||||||
assert.Equal(t, "test_branch", branches[0].Name)
|
assert.Equal(t, "test_branch", branches[0].Name)
|
||||||
assert.Equal(t, "master", branches[1].Name)
|
assert.Equal(t, "master", branches[1].Name)
|
||||||
|
|
||||||
link2, _ := url.Parse(fmt.Sprintf("/api/v1/repos/org3/%s/branches/test_branch", repo3.Name))
|
link2, _ := url.Parse(fmt.Sprintf("/api/v1/repos/org3/%s%s/branches/test_branch", maybeGroupSegment(repo3.GroupID), repo3.Name))
|
||||||
MakeRequest(t, NewRequest(t, "GET", link2.String()).AddTokenAuth(publicOnlyToken), http.StatusForbidden)
|
MakeRequest(t, NewRequest(t, "GET", link2.String()).AddTokenAuth(publicOnlyToken), http.StatusForbidden)
|
||||||
|
|
||||||
resp = MakeRequest(t, NewRequest(t, "GET", link2.String()).AddTokenAuth(token), http.StatusOK)
|
resp = MakeRequest(t, NewRequest(t, "GET", link2.String()).AddTokenAuth(token), http.StatusOK)
|
||||||
@ -79,7 +79,7 @@ func TestAPIRepoBranchesPlain(t *testing.T) {
|
|||||||
assert.Equal(t, "test_branch2", branches[1].Name)
|
assert.Equal(t, "test_branch2", branches[1].Name)
|
||||||
assert.Equal(t, "master", branches[2].Name)
|
assert.Equal(t, "master", branches[2].Name)
|
||||||
|
|
||||||
link3, _ := url.Parse(fmt.Sprintf("/api/v1/repos/org3/%s/branches/test_branch2", repo3.Name))
|
link3, _ := url.Parse(fmt.Sprintf("/api/v1/repos/org3/%s%s/branches/test_branch2", maybeGroupSegment(repo3.GroupID), repo3.Name))
|
||||||
MakeRequest(t, NewRequest(t, "DELETE", link3.String()), http.StatusNotFound)
|
MakeRequest(t, NewRequest(t, "DELETE", link3.String()), http.StatusNotFound)
|
||||||
MakeRequest(t, NewRequest(t, "DELETE", link3.String()).AddTokenAuth(publicOnlyToken), http.StatusForbidden)
|
MakeRequest(t, NewRequest(t, "DELETE", link3.String()).AddTokenAuth(publicOnlyToken), http.StatusForbidden)
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ func TestAPIRepoBranchesMirror(t *testing.T) {
|
|||||||
session := loginUser(t, user1.LowerName)
|
session := loginUser(t, user1.LowerName)
|
||||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
|
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
|
||||||
|
|
||||||
link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/org3/%s/branches", repo5.Name)) // a mirror repo
|
link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/org3/%s%s/branches", maybeGroupSegment(repo5.GroupID), repo5.Name)) // a mirror repo
|
||||||
resp := MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK)
|
resp := MakeRequest(t, NewRequest(t, "GET", link.String()).AddTokenAuth(token), http.StatusOK)
|
||||||
bs, err := io.ReadAll(resp.Body)
|
bs, err := io.ReadAll(resp.Body)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
@ -107,7 +107,7 @@ func TestAPIRepoBranchesMirror(t *testing.T) {
|
|||||||
assert.Equal(t, "test_branch", branches[0].Name)
|
assert.Equal(t, "test_branch", branches[0].Name)
|
||||||
assert.Equal(t, "master", branches[1].Name)
|
assert.Equal(t, "master", branches[1].Name)
|
||||||
|
|
||||||
link2, _ := url.Parse(fmt.Sprintf("/api/v1/repos/org3/%s/branches/test_branch", repo5.Name))
|
link2, _ := url.Parse(fmt.Sprintf("/api/v1/repos/org3/%s%s/branches/test_branch", maybeGroupSegment(repo5.GroupID), repo5.Name))
|
||||||
resp = MakeRequest(t, NewRequest(t, "GET", link2.String()).AddTokenAuth(token), http.StatusOK)
|
resp = MakeRequest(t, NewRequest(t, "GET", link2.String()).AddTokenAuth(token), http.StatusOK)
|
||||||
bs, err = io.ReadAll(resp.Body)
|
bs, err = io.ReadAll(resp.Body)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|||||||
@ -398,11 +398,11 @@ func TestAPIRepoEdit(t *testing.T) {
|
|||||||
// Test using org repo "org3/repo3" where user2 is a collaborator
|
// Test using org repo "org3/repo3" where user2 is a collaborator
|
||||||
origRepoEditOption = getRepoEditOptionFromRepo(repo3)
|
origRepoEditOption = getRepoEditOptionFromRepo(repo3)
|
||||||
repoEditOption = getNewRepoEditOption(origRepoEditOption)
|
repoEditOption = getNewRepoEditOption(origRepoEditOption)
|
||||||
req = NewRequestWithJSON(t, "PATCH", fmt.Sprintf("/api/v1/repos/%s/%s", org3.Name, repo3.Name), &repoEditOption).
|
req = NewRequestWithJSON(t, "PATCH", fmt.Sprintf("/api/v1/repos/%s/group/%d/%s", org3.Name, repo3.GroupID, repo3.Name), &repoEditOption).
|
||||||
AddTokenAuth(token2)
|
AddTokenAuth(token2)
|
||||||
MakeRequest(t, req, http.StatusOK)
|
MakeRequest(t, req, http.StatusOK)
|
||||||
// reset repo in db
|
// reset repo in db
|
||||||
req = NewRequestWithJSON(t, "PATCH", fmt.Sprintf("/api/v1/repos/%s/%s", org3.Name, *repoEditOption.Name), &origRepoEditOption).
|
req = NewRequestWithJSON(t, "PATCH", fmt.Sprintf("/api/v1/repos/%s/group/%d/%s", org3.Name, repo3.GroupID, *repoEditOption.Name), &origRepoEditOption).
|
||||||
AddTokenAuth(token2)
|
AddTokenAuth(token2)
|
||||||
_ = MakeRequest(t, req, http.StatusOK)
|
_ = MakeRequest(t, req, http.StatusOK)
|
||||||
|
|
||||||
|
|||||||
@ -73,12 +73,12 @@ func TestAPIApplyDiffPatchFileOptions(t *testing.T) {
|
|||||||
MakeRequest(t, req, http.StatusCreated)
|
MakeRequest(t, req, http.StatusCreated)
|
||||||
|
|
||||||
// Test using org repo "org3/repo3" where user2 is a collaborator
|
// Test using org repo "org3/repo3" where user2 is a collaborator
|
||||||
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/diffpatch", org3.Name, repo3.Name), getApplyDiffPatchFileOptions()).
|
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/diffpatch", org3.Name, maybeGroupSegment(repo3.GroupID), repo3.Name), getApplyDiffPatchFileOptions()).
|
||||||
AddTokenAuth(token2)
|
AddTokenAuth(token2)
|
||||||
MakeRequest(t, req, http.StatusCreated)
|
MakeRequest(t, req, http.StatusCreated)
|
||||||
|
|
||||||
// Test using org repo "org3/repo3" with no user token
|
// Test using org repo "org3/repo3" with no user token
|
||||||
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/diffpatch", org3.Name, repo3.Name), getApplyDiffPatchFileOptions())
|
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s%s/diffpatch", org3.Name, maybeGroupSegment(repo3.GroupID), repo3.Name), getApplyDiffPatchFileOptions())
|
||||||
MakeRequest(t, req, http.StatusNotFound)
|
MakeRequest(t, req, http.StatusNotFound)
|
||||||
|
|
||||||
// Test using repo "user2/repo1" where user4 is a NOT collaborator
|
// Test using repo "user2/repo1" where user4 is a NOT collaborator
|
||||||
|
|||||||
@ -122,7 +122,7 @@ func testEditorActionEdit(t *testing.T, session *TestSession, groupID int64, use
|
|||||||
params["tree_path"] = util.IfZero(params["tree_path"], filePath)
|
params["tree_path"] = util.IfZero(params["tree_path"], filePath)
|
||||||
newBranchName := util.Iif(params["commit_choice"] == "direct", branch, params["new_branch_name"])
|
newBranchName := util.Iif(params["commit_choice"] == "direct", branch, params["new_branch_name"])
|
||||||
|
|
||||||
resp := testEditorActionPostRequest(t, session, fmt.Sprintf("/%s/%s/%s%s/%s/%s", user, maybeGroupSegment(groupID), repo, editorAction, branch, filePath), params)
|
resp := testEditorActionPostRequest(t, session, fmt.Sprintf("/%s/%s%s/%s/%s/%s", user, maybeGroupSegment(groupID), repo, editorAction, branch, filePath), params)
|
||||||
assert.Equal(t, http.StatusOK, resp.Code)
|
assert.Equal(t, http.StatusOK, resp.Code)
|
||||||
assert.NotEmpty(t, test.RedirectURL(resp))
|
assert.NotEmpty(t, test.RedirectURL(resp))
|
||||||
req := NewRequest(t, "GET", path.Join(user, repo, "raw/branch", newBranchName, params["tree_path"]))
|
req := NewRequest(t, "GET", path.Join(user, repo, "raw/branch", newBranchName, params["tree_path"]))
|
||||||
|
|||||||
@ -445,19 +445,19 @@ func TestIssueRedirect(t *testing.T) {
|
|||||||
session := loginUser(t, "user2")
|
session := loginUser(t, "user2")
|
||||||
|
|
||||||
// Test external tracker where style not set (shall default numeric)
|
// Test external tracker where style not set (shall default numeric)
|
||||||
req := NewRequest(t, "GET", "/org26/repo_external_tracker/issues/1")
|
req := NewRequest(t, "GET", "/org26/group/49/repo_external_tracker/issues/1")
|
||||||
resp := session.MakeRequest(t, req, http.StatusSeeOther)
|
resp := session.MakeRequest(t, req, http.StatusSeeOther)
|
||||||
assert.Equal(t, "https://tracker.com/org26/repo_external_tracker/issues/1", test.RedirectURL(resp))
|
assert.Equal(t, "https://tracker.com/org26/repo_external_tracker/issues/1", test.RedirectURL(resp))
|
||||||
|
|
||||||
// Test external tracker with numeric style
|
// Test external tracker with numeric style
|
||||||
req = NewRequest(t, "GET", "/org26/repo_external_tracker_numeric/issues/1")
|
req = NewRequest(t, "GET", "/org26/group/53/repo_external_tracker_numeric/issues/1")
|
||||||
resp = session.MakeRequest(t, req, http.StatusSeeOther)
|
resp = session.MakeRequest(t, req, http.StatusSeeOther)
|
||||||
assert.Equal(t, "https://tracker.com/org26/repo_external_tracker_numeric/issues/1", test.RedirectURL(resp))
|
assert.Equal(t, "https://tracker.com/org26/repo_external_tracker_numeric/issues/1", test.RedirectURL(resp))
|
||||||
|
|
||||||
// Test external tracker with alphanumeric style (for a pull request)
|
// Test external tracker with alphanumeric style (for a pull request)
|
||||||
req = NewRequest(t, "GET", "/org26/repo_external_tracker_alpha/issues/1")
|
req = NewRequest(t, "GET", "/org26/repo_external_tracker_alpha/issues/1")
|
||||||
resp = session.MakeRequest(t, req, http.StatusSeeOther)
|
resp = session.MakeRequest(t, req, http.StatusSeeOther)
|
||||||
assert.Equal(t, "/org26/repo_external_tracker_alpha/pulls/1", test.RedirectURL(resp))
|
assert.Equal(t, "/org26/group/41/repo_external_tracker_alpha/pulls/1", test.RedirectURL(resp))
|
||||||
|
|
||||||
// test to check that the PR redirection works if the issue unit is disabled
|
// test to check that the PR redirection works if the issue unit is disabled
|
||||||
// repo1 is a normal repository with issue unit enabled, visit issue 2(which is a pull request)
|
// repo1 is a normal repository with issue unit enabled, visit issue 2(which is a pull request)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user