Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update HTTP status codes #18063

Merged
merged 20 commits into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/web_acme.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,5 @@ func runLetsEncryptFallbackHandler(w http.ResponseWriter, r *http.Request) {
// URI always contains a leading slash, which would result in a double
// slash
target := strings.TrimSuffix(setting.AppURL, "/") + r.URL.RequestURI()
http.Redirect(w, r, target, http.StatusFound)
http.Redirect(w, r, target, http.StatusTemporaryRedirect)
}
2 changes: 1 addition & 1 deletion integrations/admin_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestAdminEditUser(t *testing.T) {
}

func testSuccessfullEdit(t *testing.T, formData user_model.User) {
makeRequest(t, formData, http.StatusFound)
makeRequest(t, formData, http.StatusSeeOther)
}

func makeRequest(t *testing.T, formData user_model.User, headerCode int) {
Expand Down
6 changes: 3 additions & 3 deletions integrations/api_branch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func testAPIGetBranchProtection(t *testing.T, branchName string, expectedHTTPSta
req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/branch_protections/%s?token=%s", branchName, token)
resp := session.MakeRequest(t, req, expectedHTTPStatus)

if resp.Code == 200 {
if resp.Code == http.StatusOK {
var branchProtection api.BranchProtection
DecodeJSON(t, resp, &branchProtection)
assert.EqualValues(t, branchName, branchProtection.BranchName)
Expand All @@ -52,7 +52,7 @@ func testAPICreateBranchProtection(t *testing.T, branchName string, expectedHTTP
})
resp := session.MakeRequest(t, req, expectedHTTPStatus)

if resp.Code == 201 {
if resp.Code == http.StatusCreated {
var branchProtection api.BranchProtection
DecodeJSON(t, resp, &branchProtection)
assert.EqualValues(t, branchName, branchProtection.BranchName)
Expand All @@ -65,7 +65,7 @@ func testAPIEditBranchProtection(t *testing.T, branchName string, body *api.Bran
req := NewRequestWithJSON(t, "PATCH", "/api/v1/repos/user2/repo1/branch_protections/"+branchName+"?token="+token, body)
resp := session.MakeRequest(t, req, expectedHTTPStatus)

if resp.Code == 200 {
if resp.Code == http.StatusOK {
var branchProtection api.BranchProtection
DecodeJSON(t, resp, &branchProtection)
assert.EqualValues(t, branchName, branchProtection.BranchName)
Expand Down
8 changes: 4 additions & 4 deletions integrations/api_helper_for_declarative_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func doAPICreatePullRequest(ctx APITestContext, owner, repo, baseBranch, headBra
Title: fmt.Sprintf("create a pr from %s to %s", headBranch, baseBranch),
})

expected := 201
expected := http.StatusCreated
if ctx.ExpectedCode != 0 {
expected = ctx.ExpectedCode
}
Expand All @@ -246,7 +246,7 @@ func doAPIGetPullRequest(ctx APITestContext, owner, repo string, index int64) fu
owner, repo, index, ctx.Token)
req := NewRequest(t, http.MethodGet, urlStr)

expected := 200
expected := http.StatusOK
if ctx.ExpectedCode != 0 {
expected = ctx.ExpectedCode
}
Expand Down Expand Up @@ -287,7 +287,7 @@ func doAPIMergePullRequest(ctx APITestContext, owner, repo string, index int64)

expected := ctx.ExpectedCode
if expected == 0 {
expected = 200
expected = http.StatusOK
}

if !assert.EqualValues(t, expected, resp.Code,
Expand All @@ -310,7 +310,7 @@ func doAPIManuallyMergePullRequest(ctx APITestContext, owner, repo, commitID str
ctx.Session.MakeRequest(t, req, ctx.ExpectedCode)
return
}
ctx.Session.MakeRequest(t, req, 200)
ctx.Session.MakeRequest(t, req, http.StatusOK)
}
}

Expand Down
10 changes: 5 additions & 5 deletions integrations/api_pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestAPICreatePullSuccess(t *testing.T) {
Base: "master",
Title: "create a failure pr",
})
session.MakeRequest(t, req, 201)
session.MakeRequest(t, req, http.StatusCreated)
session.MakeRequest(t, req, http.StatusUnprocessableEntity) // second request should fail
}

Expand Down Expand Up @@ -105,7 +105,7 @@ func TestAPICreatePullWithFieldsSuccess(t *testing.T) {

req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls?token=%s", owner10.Name, repo10.Name, token), opts)

res := session.MakeRequest(t, req, 201)
res := session.MakeRequest(t, req, http.StatusCreated)
pull := new(api.PullRequest)
DecodeJSON(t, res, pull)

Expand Down Expand Up @@ -165,20 +165,20 @@ func TestAPIEditPull(t *testing.T) {
Title: "create a success pr",
})
pull := new(api.PullRequest)
resp := session.MakeRequest(t, req, 201)
resp := session.MakeRequest(t, req, http.StatusCreated)
DecodeJSON(t, resp, pull)
assert.EqualValues(t, "master", pull.Base.Name)

req = NewRequestWithJSON(t, http.MethodPatch, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d?token=%s", owner10.Name, repo10.Name, pull.Index, token), &api.EditPullRequestOption{
Base: "feature/1",
Title: "edit a this pr",
})
resp = session.MakeRequest(t, req, 201)
resp = session.MakeRequest(t, req, http.StatusCreated)
DecodeJSON(t, resp, pull)
assert.EqualValues(t, "feature/1", pull.Base.Name)

req = NewRequestWithJSON(t, http.MethodPatch, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d?token=%s", owner10.Name, repo10.Name, pull.Index, token), &api.EditPullRequestOption{
Base: "not-exist",
})
session.MakeRequest(t, req, 404)
session.MakeRequest(t, req, http.StatusNotFound)
}
2 changes: 1 addition & 1 deletion integrations/api_repo_languages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestRepoLanguages(t *testing.T) {
"content": "package main",
"commit_choice": "direct",
})
session.MakeRequest(t, req, http.StatusFound)
session.MakeRequest(t, req, http.StatusSeeOther)

// let gitea calculate language stats
time.Sleep(time.Second)
Expand Down
4 changes: 2 additions & 2 deletions integrations/attachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func createAttachment(t *testing.T, session *TestSession, repoURL, filename stri
func TestCreateAnonymousAttachment(t *testing.T) {
defer prepareTestEnv(t)()
session := emptyTestSession(t)
createAttachment(t, session, "user2/repo1", "image.png", generateImg(), http.StatusFound)
createAttachment(t, session, "user2/repo1", "image.png", generateImg(), http.StatusSeeOther)
}

func TestCreateIssueAttachment(t *testing.T) {
Expand All @@ -83,7 +83,7 @@ func TestCreateIssueAttachment(t *testing.T) {
}

req = NewRequestWithValues(t, "POST", link, postData)
resp = session.MakeRequest(t, req, http.StatusFound)
resp = session.MakeRequest(t, req, http.StatusSeeOther)
test.RedirectURL(resp) // check that redirect URL exists

// Validate that attachment is available
Expand Down
4 changes: 2 additions & 2 deletions integrations/auth_ldap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func addAuthSourceLDAP(t *testing.T, sshKeyAttribute string, groupMapParams ...s
"group_team_map_removal": groupTeamMapRemoval,
"user_uid": "DN",
})
session.MakeRequest(t, req, http.StatusFound)
session.MakeRequest(t, req, http.StatusSeeOther)
}

func TestLDAPUserSignin(t *testing.T) {
Expand Down Expand Up @@ -202,7 +202,7 @@ func TestLDAPAuthChange(t *testing.T) {
"is_sync_enabled": "on",
"is_active": "on",
})
session.MakeRequest(t, req, http.StatusFound)
session.MakeRequest(t, req, http.StatusSeeOther)

req = NewRequest(t, "GET", href)
resp = session.MakeRequest(t, req, http.StatusOK)
Expand Down
2 changes: 1 addition & 1 deletion integrations/change_default_branch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestChangeDefaultBranch(t *testing.T) {
"action": "default_branch",
"branch": "DefaultBranch",
})
session.MakeRequest(t, req, http.StatusFound)
session.MakeRequest(t, req, http.StatusSeeOther)

csrf = GetCSRF(t, session, branchesURL)
req = NewRequestWithValues(t, "POST", branchesURL, map[string]string{
Expand Down
2 changes: 1 addition & 1 deletion integrations/create_no_session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestSessionFileCreation(t *testing.T) {
"user_name": "user2",
"password": userPassword,
})
resp = MakeRequest(t, req, http.StatusFound)
resp = MakeRequest(t, req, http.StatusSeeOther)
sessionID = getSessionID(t, resp)

assert.FileExists(t, sessionFile(tmpDir, sessionID))
Expand Down
4 changes: 2 additions & 2 deletions integrations/delete_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestUserDeleteAccount(t *testing.T) {
req := NewRequestWithValues(t, "POST", urlStr, map[string]string{
"_csrf": csrf,
})
session.MakeRequest(t, req, http.StatusFound)
session.MakeRequest(t, req, http.StatusSeeOther)

assertUserDeleted(t, 8)
unittest.CheckConsistencyFor(t, &user_model.User{})
Expand All @@ -51,7 +51,7 @@ func TestUserDeleteAccountStillOwnRepos(t *testing.T) {
req := NewRequestWithValues(t, "POST", urlStr, map[string]string{
"_csrf": csrf,
})
session.MakeRequest(t, req, http.StatusFound)
session.MakeRequest(t, req, http.StatusSeeOther)

// user should not have been deleted, because the user still owns repos
unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
Expand Down
10 changes: 5 additions & 5 deletions integrations/editor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestCreateFile(t *testing.T) {
"content": "Content",
"commit_choice": "direct",
})
session.MakeRequest(t, req, http.StatusFound)
session.MakeRequest(t, req, http.StatusSeeOther)
})
}

Expand All @@ -48,7 +48,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) {
"_csrf": csrf,
"protected": "on",
})
session.MakeRequest(t, req, http.StatusFound)
session.MakeRequest(t, req, http.StatusSeeOther)
// Check if master branch has been locked successfully
flashCookie := session.GetCookie("macaron_flash")
assert.NotNil(t, flashCookie)
Expand Down Expand Up @@ -82,7 +82,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) {
"_csrf": csrf,
"protected": "off",
})
resp = session.MakeRequest(t, req, http.StatusFound)
resp = session.MakeRequest(t, req, http.StatusSeeOther)
// Check if master branch has been locked successfully
flashCookie = session.GetCookie("macaron_flash")
assert.NotNil(t, flashCookie)
Expand All @@ -109,7 +109,7 @@ func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePa
"commit_choice": "direct",
},
)
resp = session.MakeRequest(t, req, http.StatusFound)
resp = session.MakeRequest(t, req, http.StatusSeeOther)

// Verify the change
req = NewRequest(t, "GET", path.Join(user, repo, "raw/branch", branch, filePath))
Expand Down Expand Up @@ -139,7 +139,7 @@ func testEditFileToNewBranch(t *testing.T, session *TestSession, user, repo, bra
"new_branch_name": targetBranch,
},
)
resp = session.MakeRequest(t, req, http.StatusFound)
resp = session.MakeRequest(t, req, http.StatusSeeOther)

// Verify the change
req = NewRequest(t, "GET", path.Join(user, repo, "raw/branch", targetBranch, filePath))
Expand Down
14 changes: 7 additions & 7 deletions integrations/git_smart_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@ func testGitSmartHTTP(t *testing.T, u *url.URL) {
}{
{
p: "user2/repo1/info/refs",
code: 200,
code: http.StatusOK,
},
{
p: "user2/repo1/HEAD",
code: 200,
code: http.StatusOK,
},
{
p: "user2/repo1/objects/info/alternates",
code: 404,
code: http.StatusNotFound,
},
{
p: "user2/repo1/objects/info/http-alternates",
code: 404,
code: http.StatusNotFound,
},
{
p: "user2/repo1/../../custom/conf/app.ini",
code: 404,
code: http.StatusNotFound,
},
{
p: "user2/repo1/objects/info/../../../../custom/conf/app.ini",
code: 404,
code: http.StatusNotFound,
},
{
p: `user2/repo1/objects/info/..\..\..\..\custom\conf\app.ini`,
code: 400,
code: http.StatusBadRequest,
},
}

Expand Down
4 changes: 2 additions & 2 deletions integrations/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ func doProtectBranch(ctx APITestContext, branch, userToWhitelist, unprotectedFil
"protected": "on",
"unprotected_file_patterns": unprotectedFilePatterns,
})
ctx.Session.MakeRequest(t, req, http.StatusFound)
ctx.Session.MakeRequest(t, req, http.StatusSeeOther)
} else {
user, err := user_model.GetUserByName(userToWhitelist)
assert.NoError(t, err)
Expand All @@ -448,7 +448,7 @@ func doProtectBranch(ctx APITestContext, branch, userToWhitelist, unprotectedFil
"whitelist_users": strconv.FormatInt(user.ID, 10),
"unprotected_file_patterns": unprotectedFilePatterns,
})
ctx.Session.MakeRequest(t, req, http.StatusFound)
ctx.Session.MakeRequest(t, req, http.StatusSeeOther)
}
// Check if master branch has been locked successfully
flashCookie := ctx.Session.GetCookie("macaron_flash")
Expand Down
4 changes: 2 additions & 2 deletions integrations/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ func loginUserWithPassword(t testing.TB, userName, password string) *TestSession
"user_name": userName,
"password": password,
})
resp = MakeRequest(t, req, http.StatusFound)
resp = MakeRequest(t, req, http.StatusSeeOther)

ch := http.Header{}
ch.Add("Cookie", strings.Join(resp.Header()["Set-Cookie"], ";"))
Expand Down Expand Up @@ -408,7 +408,7 @@ func getTokenForLoggedInUser(t testing.TB, session *TestSession) string {
"_csrf": doc.GetCSRF(),
"name": fmt.Sprintf("api-testing-token-%d", tokenCounter),
})
resp = session.MakeRequest(t, req, http.StatusFound)
resp = session.MakeRequest(t, req, http.StatusSeeOther)
req = NewRequest(t, "GET", "/user/settings/applications")
resp = session.MakeRequest(t, req, http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body)
Expand Down
10 changes: 5 additions & 5 deletions integrations/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func testNewIssue(t *testing.T, session *TestSession, user, repo, title, content
"title": title,
"content": content,
})
resp = session.MakeRequest(t, req, http.StatusFound)
resp = session.MakeRequest(t, req, http.StatusSeeOther)

issueURL := test.RedirectURL(resp)
req = NewRequest(t, "GET", issueURL)
Expand Down Expand Up @@ -162,7 +162,7 @@ func testIssueAddComment(t *testing.T, session *TestSession, issueURL, content,
"content": content,
"status": status,
})
resp = session.MakeRequest(t, req, http.StatusFound)
resp = session.MakeRequest(t, req, http.StatusSeeOther)

req = NewRequest(t, "GET", test.RedirectURL(resp))
resp = session.MakeRequest(t, req, http.StatusOK)
Expand Down Expand Up @@ -334,16 +334,16 @@ func TestIssueRedirect(t *testing.T) {

// Test external tracker where style not set (shall default numeric)
req := NewRequest(t, "GET", path.Join("org26", "repo_external_tracker", "issues", "1"))
resp := session.MakeRequest(t, req, http.StatusFound)
resp := session.MakeRequest(t, req, http.StatusSeeOther)
assert.Equal(t, "https://tracker.com/org26/repo_external_tracker/issues/1", test.RedirectURL(resp))

// Test external tracker with numeric style
req = NewRequest(t, "GET", path.Join("org26", "repo_external_tracker_numeric", "issues", "1"))
resp = session.MakeRequest(t, req, http.StatusFound)
resp = session.MakeRequest(t, req, http.StatusSeeOther)
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)
req = NewRequest(t, "GET", path.Join("org26", "repo_external_tracker_alpha", "issues", "1"))
resp = session.MakeRequest(t, req, http.StatusFound)
resp = session.MakeRequest(t, req, http.StatusSeeOther)
assert.Equal(t, "/"+path.Join("org26", "repo_external_tracker_alpha", "pulls", "1"), test.RedirectURL(resp))
}
2 changes: 1 addition & 1 deletion integrations/links_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestRedirectsNoLogin(t *testing.T) {
}
for link, redirectLink := range redirects {
req := NewRequest(t, "GET", link)
resp := MakeRequest(t, req, http.StatusFound)
resp := MakeRequest(t, req, http.StatusSeeOther)
assert.EqualValues(t, path.Join(setting.AppSubURL, redirectLink), test.RedirectURL(resp))
}
}
Expand Down
4 changes: 2 additions & 2 deletions integrations/mirror_push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func doCreatePushMirror(ctx APITestContext, address, username, password string)
"push_mirror_password": password,
"push_mirror_interval": "0",
})
ctx.Session.MakeRequest(t, req, http.StatusFound)
ctx.Session.MakeRequest(t, req, http.StatusSeeOther)

flashCookie := ctx.Session.GetCookie("macaron_flash")
assert.NotNil(t, flashCookie)
Expand All @@ -110,7 +110,7 @@ func doRemovePushMirror(ctx APITestContext, address, username, password string,
"push_mirror_password": password,
"push_mirror_interval": "0",
})
ctx.Session.MakeRequest(t, req, http.StatusFound)
ctx.Session.MakeRequest(t, req, http.StatusSeeOther)

flashCookie := ctx.Session.GetCookie("macaron_flash")
assert.NotNil(t, flashCookie)
Expand Down
Loading