From 2f3ba18f64406a7b0a521f6579a465453eb4f21d Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Tue, 21 Dec 2021 22:00:00 +0000 Subject: [PATCH 01/10] Updated status codes. --- cmd/web_letsencrypt.go | 2 +- modules/context/context.go | 2 +- modules/lfs/http_client_test.go | 2 +- modules/private/restore_repo.go | 2 +- modules/web/route_test.go | 2 +- routers/api/v1/org/member.go | 2 +- routers/api/v1/repo/issue_tracked_time.go | 2 +- routers/common/middleware.go | 4 ++-- routers/install/install.go | 2 +- routers/install/routes.go | 8 +++---- routers/web/admin/admin.go | 10 ++++----- routers/web/admin/notice.go | 4 ++-- routers/web/base.go | 16 +++++++------- routers/web/explore/code.go | 2 +- routers/web/goget.go | 2 +- routers/web/metrics.go | 4 ++-- routers/web/repo/editor.go | 4 ++-- routers/web/repo/issue.go | 16 +++++++------- routers/web/repo/issue_label_test.go | 6 +++--- routers/web/repo/pull.go | 2 +- routers/web/repo/search.go | 2 +- routers/web/repo/setting_protected_branch.go | 2 +- routers/web/repo/settings_test.go | 22 ++++++++++---------- routers/web/repo/webhook.go | 6 +++--- routers/web/repo/wiki_test.go | 4 ++-- routers/web/user/home.go | 6 +++--- routers/web/user/oauth.go | 8 +++---- routers/web/user/setting/account_test.go | 2 +- routers/web/user/setting/security_u2f.go | 6 +++--- routers/web/web.go | 8 +++---- services/auth/sspi_windows.go | 2 +- services/lfs/locks.go | 12 +++++------ services/migrations/gitea_downloader_test.go | 2 +- services/migrations/gitlab.go | 4 ++-- services/migrations/gitlab_test.go | 2 +- services/migrations/onedev_test.go | 2 +- 36 files changed, 92 insertions(+), 92 deletions(-) diff --git a/cmd/web_letsencrypt.go b/cmd/web_letsencrypt.go index 066208457bae1..8812021e9bdfe 100644 --- a/cmd/web_letsencrypt.go +++ b/cmd/web_letsencrypt.go @@ -95,5 +95,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) } diff --git a/modules/context/context.go b/modules/context/context.go index 94e1f6cfffc70..6bfc41be6b1e3 100644 --- a/modules/context/context.go +++ b/modules/context/context.go @@ -379,7 +379,7 @@ func (ctx *Context) JSON(status int, content interface{}) { // Redirect redirects the request func (ctx *Context) Redirect(location string, status ...int) { - code := http.StatusFound + code := http.StatusTemporaryRedirect if len(status) == 1 { code = status[0] } diff --git a/modules/lfs/http_client_test.go b/modules/lfs/http_client_test.go index 5b514a1230d7b..1e295469c431d 100644 --- a/modules/lfs/http_client_test.go +++ b/modules/lfs/http_client_test.go @@ -82,7 +82,7 @@ func lfsTestRoundtripHandler(req *http.Request) *http.Response { Objects: []*ObjectResponse{ { Error: &ObjectError{ - Code: 404, + Code: http.StatusNotFound, Message: "Object not found", }, }, diff --git a/modules/private/restore_repo.go b/modules/private/restore_repo.go index 6ebf4c63d5cda..bc4e48e8ccdf3 100644 --- a/modules/private/restore_repo.go +++ b/modules/private/restore_repo.go @@ -43,7 +43,7 @@ func RestoreRepo(ctx context.Context, repoDir, ownerName, repoName string, units } defer resp.Body.Close() - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { var ret = struct { Err string `json:"err"` }{} diff --git a/modules/web/route_test.go b/modules/web/route_test.go index a8470fec94f57..801afe92c9252 100644 --- a/modules/web/route_test.go +++ b/modules/web/route_test.go @@ -67,7 +67,7 @@ func TestRoute2(t *testing.T) { route = 1 }) }, func(resp http.ResponseWriter, req *http.Request) { - resp.WriteHeader(200) + resp.WriteHeader(http.StatusOK) }) r.Group("/issues/{index}", func() { diff --git a/routers/api/v1/org/member.go b/routers/api/v1/org/member.go index d818321790507..8152d14cb0953 100644 --- a/routers/api/v1/org/member.go +++ b/routers/api/v1/org/member.go @@ -161,7 +161,7 @@ func IsMember(ctx *context.APIContext) { } redirectURL := setting.AppSubURL + "/api/v1/orgs/" + url.PathEscape(ctx.Org.Organization.Name) + "/public_members/" + url.PathEscape(userToCheck.Name) - ctx.Redirect(redirectURL, 302) + ctx.Redirect(redirectURL, http.StatusTemporaryRedirect) } // IsPublicMember check if a user is a public member of an organization diff --git a/routers/api/v1/repo/issue_tracked_time.go b/routers/api/v1/repo/issue_tracked_time.go index 00f8e77febddd..47ec1d6d5414d 100644 --- a/routers/api/v1/repo/issue_tracked_time.go +++ b/routers/api/v1/repo/issue_tracked_time.go @@ -288,7 +288,7 @@ func ResetIssueTime(ctx *context.APIContext) { } return } - ctx.Status(204) + ctx.Status(http.StatusNoContent) } // DeleteTime delete a specific time by id diff --git a/routers/common/middleware.go b/routers/common/middleware.go index 7da05d2ae4ef2..428c4313b0921 100644 --- a/routers/common/middleware.go +++ b/routers/common/middleware.go @@ -66,9 +66,9 @@ func Middlewares() []func(http.Handler) http.Handler { combinedErr := fmt.Sprintf("PANIC: %v\n%s", err, string(log.Stack(2))) log.Error("%v", combinedErr) if setting.IsProd { - http.Error(resp, http.StatusText(500), 500) + http.Error(resp, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) } else { - http.Error(resp, combinedErr, 500) + http.Error(resp, combinedErr, http.StatusInternalServerError) } } }() diff --git a/routers/install/install.go b/routers/install/install.go index 7c3d43bbde074..749a55d761be8 100644 --- a/routers/install/install.go +++ b/routers/install/install.go @@ -59,7 +59,7 @@ func Init(next http.Handler) http.Handler { return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) { if setting.InstallLock { resp.Header().Add("Refresh", "1; url="+setting.AppURL+"user/login") - _ = rnd.HTML(resp, 200, string(tplPostInstall), nil) + _ = rnd.HTML(resp, http.StatusOK, string(tplPostInstall), nil) return } var locale = middleware.Locale(resp, req) diff --git a/routers/install/routes.go b/routers/install/routes.go index ad0003a9e8e34..9e89c22155606 100644 --- a/routers/install/routes.go +++ b/routers/install/routes.go @@ -41,9 +41,9 @@ func installRecovery() func(next http.Handler) http.Handler { combinedErr := fmt.Sprintf("PANIC: %v\n%s", err, string(log.Stack(2))) log.Error(combinedErr) if setting.IsProd { - http.Error(w, http.StatusText(500), 500) + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) } else { - http.Error(w, combinedErr, 500) + http.Error(w, combinedErr, http.StatusInternalServerError) } } }() @@ -66,7 +66,7 @@ func installRecovery() func(next http.Handler) http.Handler { if !setting.IsProd { store["ErrorMsg"] = combinedErr } - err = rnd.HTML(w, 500, "status/500", templates.BaseVars().Merge(store)) + err = rnd.HTML(w, http.StatusInternalServerError, "status/500", templates.BaseVars().Merge(store)) if err != nil { log.Error("%v", err) } @@ -107,7 +107,7 @@ func Routes() *web.Route { r.Get("/", Install) r.Post("/", web.Bind(forms.InstallForm{}), SubmitInstall) r.NotFound(func(w http.ResponseWriter, req *http.Request) { - http.Redirect(w, req, setting.AppURL, http.StatusFound) + http.Redirect(w, req, setting.AppURL, http.StatusPermanentRedirect) }) return r } diff --git a/routers/web/admin/admin.go b/routers/web/admin/admin.go index 7e25f96ee004c..e89c5b3abfdb2 100644 --- a/routers/web/admin/admin.go +++ b/routers/web/admin/admin.go @@ -346,7 +346,7 @@ func Queue(ctx *context.Context) { qid := ctx.ParamsInt64("qid") mq := queue.GetManager().GetManagedQueue(qid) if mq == nil { - ctx.Status(404) + ctx.Status(http.StatusNotFound) return } ctx.Data["Title"] = ctx.Tr("admin.monitor.queue", mq.Name) @@ -361,7 +361,7 @@ func WorkerCancel(ctx *context.Context) { qid := ctx.ParamsInt64("qid") mq := queue.GetManager().GetManagedQueue(qid) if mq == nil { - ctx.Status(404) + ctx.Status(http.StatusNotFound) return } pid := ctx.ParamsInt64("pid") @@ -377,7 +377,7 @@ func Flush(ctx *context.Context) { qid := ctx.ParamsInt64("qid") mq := queue.GetManager().GetManagedQueue(qid) if mq == nil { - ctx.Status(404) + ctx.Status(http.StatusNotFound) return } timeout, err := time.ParseDuration(ctx.FormString("timeout")) @@ -399,7 +399,7 @@ func AddWorkers(ctx *context.Context) { qid := ctx.ParamsInt64("qid") mq := queue.GetManager().GetManagedQueue(qid) if mq == nil { - ctx.Status(404) + ctx.Status(http.StatusNotFound) return } number := ctx.FormInt("number") @@ -429,7 +429,7 @@ func SetQueueSettings(ctx *context.Context) { qid := ctx.ParamsInt64("qid") mq := queue.GetManager().GetManagedQueue(qid) if mq == nil { - ctx.Status(404) + ctx.Status(http.StatusNotFound) return } if _, ok := mq.Managed.(queue.ManagedPool); !ok { diff --git a/routers/web/admin/notice.go b/routers/web/admin/notice.go index 3613f428ed797..24cc0e0d76c77 100644 --- a/routers/web/admin/notice.go +++ b/routers/web/admin/notice.go @@ -59,10 +59,10 @@ func DeleteNotices(ctx *context.Context) { if err := admin_model.DeleteNoticesByIDs(ids); err != nil { ctx.Flash.Error("DeleteNoticesByIDs: " + err.Error()) - ctx.Status(500) + ctx.Status(http.StatusInternalServerError) } else { ctx.Flash.Success(ctx.Tr("admin.notices.delete_success")) - ctx.Status(200) + ctx.Status(http.StatusOK) } } diff --git a/routers/web/base.go b/routers/web/base.go index 98713bc8818f6..131b83f3cd5bf 100644 --- a/routers/web/base.go +++ b/routers/web/base.go @@ -45,18 +45,18 @@ func storageHandler(storageSetting setting.Storage, prefix string, objStore stor if err != nil { if os.IsNotExist(err) || errors.Is(err, os.ErrNotExist) { log.Warn("Unable to find %s %s", prefix, rPath) - http.Error(w, "file not found", 404) + http.Error(w, "file not found", http.StatusNotFound) return } log.Error("Error whilst getting URL for %s %s. Error: %v", prefix, rPath, err) - http.Error(w, fmt.Sprintf("Error whilst getting URL for %s %s", prefix, rPath), 500) + http.Error(w, fmt.Sprintf("Error whilst getting URL for %s %s", prefix, rPath), http.StatusInternalServerError) return } http.Redirect( w, req, u.String(), - 301, + http.StatusPermanentRedirect, ) }) } @@ -77,7 +77,7 @@ func storageHandler(storageSetting setting.Storage, prefix string, objStore stor rPath := strings.TrimPrefix(req.URL.EscapedPath(), "/"+prefix+"/") rPath = strings.TrimPrefix(rPath, "/") if rPath == "" { - http.Error(w, "file not found", 404) + http.Error(w, "file not found", http.StatusNotFound) return } rPath = path.Clean("/" + filepath.ToSlash(rPath)) @@ -93,11 +93,11 @@ func storageHandler(storageSetting setting.Storage, prefix string, objStore stor if err != nil { if os.IsNotExist(err) || errors.Is(err, os.ErrNotExist) { log.Warn("Unable to find %s %s", prefix, rPath) - http.Error(w, "file not found", 404) + http.Error(w, "file not found", http.StatusNotFound) return } log.Error("Error whilst opening %s %s. Error: %v", prefix, rPath, err) - http.Error(w, fmt.Sprintf("Error whilst opening %s %s", prefix, rPath), 500) + http.Error(w, fmt.Sprintf("Error whilst opening %s %s", prefix, rPath), http.StatusInternalServerError) return } defer fr.Close() @@ -105,7 +105,7 @@ func storageHandler(storageSetting setting.Storage, prefix string, objStore stor _, err = io.Copy(w, fr) if err != nil { log.Error("Error whilst rendering %s %s. Error: %v", prefix, rPath, err) - http.Error(w, fmt.Sprintf("Error whilst rendering %s %s", prefix, rPath), 500) + http.Error(w, fmt.Sprintf("Error whilst rendering %s %s", prefix, rPath), http.StatusInternalServerError) return } }) @@ -159,7 +159,7 @@ func Recovery() func(next http.Handler) http.Handler { if !setting.IsProd { store["ErrorMsg"] = combinedErr } - err = rnd.HTML(w, 500, "status/500", templates.BaseVars().Merge(store)) + err = rnd.HTML(w, http.StatusInternalServerError, "status/500", templates.BaseVars().Merge(store)) if err != nil { log.Error("%v", err) } diff --git a/routers/web/explore/code.go b/routers/web/explore/code.go index b61f25a96cb12..67445192ca5d9 100644 --- a/routers/web/explore/code.go +++ b/routers/web/explore/code.go @@ -24,7 +24,7 @@ const ( // Code render explore code page func Code(ctx *context.Context) { if !setting.Indexer.RepoIndexerEnabled { - ctx.Redirect(setting.AppSubURL+"/explore", 302) + ctx.Redirect(setting.AppSubURL+"/explore", http.StatusTemporaryRedirect) return } diff --git a/routers/web/goget.go b/routers/web/goget.go index 2843a96c30bd3..4a31fcc2c51cc 100644 --- a/routers/web/goget.go +++ b/routers/web/goget.go @@ -48,7 +48,7 @@ func goGet(ctx *context.Context) { `)) - ctx.Status(400) + ctx.Status(http.StatusBadRequest) return } branchName := setting.Repository.DefaultBranch diff --git a/routers/web/metrics.go b/routers/web/metrics.go index 37558ee337646..c7e01b8faafa3 100644 --- a/routers/web/metrics.go +++ b/routers/web/metrics.go @@ -21,13 +21,13 @@ func Metrics(resp http.ResponseWriter, req *http.Request) { } header := req.Header.Get("Authorization") if header == "" { - http.Error(resp, "", 401) + http.Error(resp, "", http.StatusUnauthorized) return } got := []byte(header) want := []byte("Bearer " + setting.Metrics.Token) if subtle.ConstantTimeCompare(got, want) != 1 { - http.Error(resp, "", 401) + http.Error(resp, "", http.StatusUnauthorized) return } promhttp.Handler().ServeHTTP(resp, req) diff --git a/routers/web/repo/editor.go b/routers/web/repo/editor.go index 12098ddc69112..b2c2e2d894ab7 100644 --- a/routers/web/repo/editor.go +++ b/routers/web/repo/editor.go @@ -785,7 +785,7 @@ func UploadFileToServer(ctx *context.Context) { func RemoveUploadFileFromServer(ctx *context.Context) { form := web.GetForm(ctx).(*forms.RemoveUploadFileForm) if len(form.File) == 0 { - ctx.Status(204) + ctx.Status(http.StatusNoContent) return } @@ -795,7 +795,7 @@ func RemoveUploadFileFromServer(ctx *context.Context) { } log.Trace("Upload file removed: %s", form.File) - ctx.Status(204) + ctx.Status(http.StatusNoContent) } // GetUniquePatchBranchName Gets a unique branch name for a new patch branch diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index d55b6c96b6aff..5a3486de00945 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -1886,7 +1886,7 @@ func UpdatePullReviewRequest(ctx *context.Context) { // TODO: Not support 'clear' now if action != "attach" && action != "detach" { - ctx.Status(403) + ctx.Status(http.StatusForbidden) return } @@ -1901,7 +1901,7 @@ func UpdatePullReviewRequest(ctx *context.Context) { "UpdatePullReviewRequest: refusing to add review request for non-PR issue %-v#%d", issue.Repo, issue.Index, ) - ctx.Status(403) + ctx.Status(http.StatusForbidden) return } if reviewID < 0 { @@ -1916,7 +1916,7 @@ func UpdatePullReviewRequest(ctx *context.Context) { "UpdatePullReviewRequest: refusing to add team review request for %s#%d owned by non organization UID[%d]", issue.Repo.FullName(), issue.Index, issue.Repo.ID, ) - ctx.Status(403) + ctx.Status(http.StatusForbidden) return } @@ -1930,7 +1930,7 @@ func UpdatePullReviewRequest(ctx *context.Context) { log.Warn( "UpdatePullReviewRequest: refusing to add team review request for UID[%d] team %s to %s#%d owned by UID[%d]", team.OrgID, team.Name, issue.Repo.FullName(), issue.Index, issue.Repo.ID) - ctx.Status(403) + ctx.Status(http.StatusForbidden) return } @@ -1942,7 +1942,7 @@ func UpdatePullReviewRequest(ctx *context.Context) { team.OrgID, team.Name, issue.Repo.FullName(), issue.Index, issue.Repo.ID, err, ) - ctx.Status(403) + ctx.Status(http.StatusForbidden) return } ctx.ServerError("IsValidTeamReviewRequest", err) @@ -1965,7 +1965,7 @@ func UpdatePullReviewRequest(ctx *context.Context) { reviewID, issue.Repo, issue.Index, err, ) - ctx.Status(403) + ctx.Status(http.StatusForbidden) return } ctx.ServerError("GetUserByID", err) @@ -1980,7 +1980,7 @@ func UpdatePullReviewRequest(ctx *context.Context) { reviewer, issue.Repo, issue.Index, err, ) - ctx.Status(403) + ctx.Status(http.StatusForbidden) return } ctx.ServerError("isValidReviewRequest", err) @@ -2261,7 +2261,7 @@ func DeleteComment(ctx *context.Context) { return } - ctx.Status(200) + ctx.Status(http.StatusOK) } // ChangeIssueReaction create a reaction for issue diff --git a/routers/web/repo/issue_label_test.go b/routers/web/repo/issue_label_test.go index baa34530fabdf..4dda9a7ba42d4 100644 --- a/routers/web/repo/issue_label_test.go +++ b/routers/web/repo/issue_label_test.go @@ -36,7 +36,7 @@ func TestInitializeLabels(t *testing.T) { test.LoadRepo(t, ctx, 2) web.SetForm(ctx, &forms.InitializeLabelsForm{TemplateName: "Default"}) InitializeLabels(ctx) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) unittest.AssertExistsAndLoadBean(t, &models.Label{ RepoID: 2, Name: "enhancement", @@ -82,7 +82,7 @@ func TestNewLabel(t *testing.T) { Color: "#abcdef", }) NewLabel(ctx) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) unittest.AssertExistsAndLoadBean(t, &models.Label{ Name: "newlabel", Color: "#abcdef", @@ -101,7 +101,7 @@ func TestUpdateLabel(t *testing.T) { Color: "#abcdef", }) UpdateLabel(ctx) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) unittest.AssertExistsAndLoadBean(t, &models.Label{ ID: 2, Name: "newnameforlabel", diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index bf80a7e5dfe62..27cc6bbec1b6f 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -1205,7 +1205,7 @@ func TriggerTask(ctx *context.Context) { log.Trace("TriggerTask '%s/%s' by %s", repo.Name, branch, pusher.Name) go pull_service.AddTestPullRequestTask(pusher, repo.ID, branch, true, "", "") - ctx.Status(202) + ctx.Status(http.StatusAccepted) } // CleanUpPullRequest responses for delete merged branch when PR has been merged diff --git a/routers/web/repo/search.go b/routers/web/repo/search.go index 67539c3d7eb8a..bfb28612642ac 100644 --- a/routers/web/repo/search.go +++ b/routers/web/repo/search.go @@ -18,7 +18,7 @@ const tplSearch base.TplName = "repo/search" // Search render repository search page func Search(ctx *context.Context) { if !setting.Indexer.RepoIndexerEnabled { - ctx.Redirect(ctx.Repo.RepoLink, 302) + ctx.Redirect(ctx.Repo.RepoLink, http.StatusTemporaryRedirect) return } language := ctx.FormTrim("l") diff --git a/routers/web/repo/setting_protected_branch.go b/routers/web/repo/setting_protected_branch.go index 1435b820add0e..5c277e3824ae2 100644 --- a/routers/web/repo/setting_protected_branch.go +++ b/routers/web/repo/setting_protected_branch.go @@ -73,7 +73,7 @@ func ProtectedBranchPost(ctx *context.Context) { branch := ctx.FormString("branch") if !ctx.Repo.GitRepo.IsBranchExist(branch) { - ctx.Status(404) + ctx.Status(http.StatusNotFound) return } else if repo.DefaultBranch != branch { repo.DefaultBranch = branch diff --git a/routers/web/repo/settings_test.go b/routers/web/repo/settings_test.go index 5b62e1ed16f7a..621f7857399fa 100644 --- a/routers/web/repo/settings_test.go +++ b/routers/web/repo/settings_test.go @@ -60,7 +60,7 @@ func TestAddReadOnlyDeployKey(t *testing.T) { } web.SetForm(ctx, &addKeyForm) DeployKeysPost(ctx) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) unittest.AssertExistsAndLoadBean(t, &asymkey_model.DeployKey{ Name: addKeyForm.Title, @@ -90,7 +90,7 @@ func TestAddReadWriteOnlyDeployKey(t *testing.T) { } web.SetForm(ctx, &addKeyForm) DeployKeysPost(ctx) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) unittest.AssertExistsAndLoadBean(t, &asymkey_model.DeployKey{ Name: addKeyForm.Title, @@ -128,7 +128,7 @@ func TestCollaborationPost(t *testing.T) { CollaborationPost(ctx) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) exists, err := models.IsCollaborator(re.ID, 4) assert.NoError(t, err) @@ -155,7 +155,7 @@ func TestCollaborationPost_InactiveUser(t *testing.T) { CollaborationPost(ctx) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) assert.NotEmpty(t, ctx.Flash.ErrorMsg) } @@ -188,7 +188,7 @@ func TestCollaborationPost_AddCollaboratorTwice(t *testing.T) { CollaborationPost(ctx) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) exists, err := models.IsCollaborator(re.ID, 4) assert.NoError(t, err) @@ -197,7 +197,7 @@ func TestCollaborationPost_AddCollaboratorTwice(t *testing.T) { // Try adding the same collaborator again CollaborationPost(ctx) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) assert.NotEmpty(t, ctx.Flash.ErrorMsg) } @@ -220,7 +220,7 @@ func TestCollaborationPost_NonExistentUser(t *testing.T) { CollaborationPost(ctx) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) assert.NotEmpty(t, ctx.Flash.ErrorMsg) } @@ -260,7 +260,7 @@ func TestAddTeamPost(t *testing.T) { AddTeamPost(ctx) assert.True(t, team.HasRepository(re.ID)) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) assert.Empty(t, ctx.Flash.ErrorMsg) } @@ -300,7 +300,7 @@ func TestAddTeamPost_NotAllowed(t *testing.T) { AddTeamPost(ctx) assert.False(t, team.HasRepository(re.ID)) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) assert.NotEmpty(t, ctx.Flash.ErrorMsg) } @@ -342,7 +342,7 @@ func TestAddTeamPost_AddTeamTwice(t *testing.T) { AddTeamPost(ctx) assert.True(t, team.HasRepository(re.ID)) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) assert.NotEmpty(t, ctx.Flash.ErrorMsg) } @@ -375,7 +375,7 @@ func TestAddTeamPost_NonExistentTeam(t *testing.T) { ctx.Repo = repo AddTeamPost(ctx) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) assert.NotEmpty(t, ctx.Flash.ErrorMsg) } diff --git a/routers/web/repo/webhook.go b/routers/web/repo/webhook.go index 47d84136718dc..50a17c698349d 100644 --- a/routers/web/repo/webhook.go +++ b/routers/web/repo/webhook.go @@ -1143,7 +1143,7 @@ func TestWebhook(ctx *context.Context) { w, err := webhook.GetWebhookByRepoID(ctx.Repo.Repository.ID, hookID) if err != nil { ctx.Flash.Error("GetWebhookByID: " + err.Error()) - ctx.Status(500) + ctx.Status(http.StatusInternalServerError) return } @@ -1187,10 +1187,10 @@ func TestWebhook(ctx *context.Context) { } if err := webhook_service.PrepareWebhook(w, ctx.Repo.Repository, webhook.HookEventPush, p); err != nil { ctx.Flash.Error("PrepareWebhook: " + err.Error()) - ctx.Status(500) + ctx.Status(http.StatusInternalServerError) } else { ctx.Flash.Info(ctx.Tr("repo.settings.webhook.test_delivery_success")) - ctx.Status(200) + ctx.Status(http.StatusOK) } } diff --git a/routers/web/repo/wiki_test.go b/routers/web/repo/wiki_test.go index 1bfda50d19386..7505d45f46bbe 100644 --- a/routers/web/repo/wiki_test.go +++ b/routers/web/repo/wiki_test.go @@ -122,7 +122,7 @@ func TestNewWikiPost(t *testing.T) { Message: message, }) NewWikiPost(ctx) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) assertWikiExists(t, ctx.Repo.Repository, title) assert.Equal(t, wikiContent(t, ctx.Repo.Repository, title), content) } @@ -174,7 +174,7 @@ func TestEditWikiPost(t *testing.T) { Message: message, }) EditWikiPost(ctx) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) assertWikiExists(t, ctx.Repo.Repository, title) assert.Equal(t, wikiContent(t, ctx.Repo.Repository, title), content) if title != "Home" { diff --git a/routers/web/user/home.go b/routers/web/user/home.go index 975262cf9c78b..95d2be0cfe85e 100644 --- a/routers/web/user/home.go +++ b/routers/web/user/home.go @@ -152,7 +152,7 @@ func Dashboard(ctx *context.Context) { func Milestones(ctx *context.Context) { if unit.TypeIssues.UnitGlobalDisabled() && unit.TypePullRequests.UnitGlobalDisabled() { log.Debug("Milestones overview page not available as both issues and pull requests are globally disabled") - ctx.Status(404) + ctx.Status(http.StatusNotFound) return } @@ -324,7 +324,7 @@ func Milestones(ctx *context.Context) { func Pulls(ctx *context.Context) { if unit.TypePullRequests.UnitGlobalDisabled() { log.Debug("Pull request overview page not available as it is globally disabled.") - ctx.Status(404) + ctx.Status(http.StatusNotFound) return } @@ -337,7 +337,7 @@ func Pulls(ctx *context.Context) { func Issues(ctx *context.Context) { if unit.TypeIssues.UnitGlobalDisabled() { log.Debug("Issues overview page not available as it is globally disabled.") - ctx.Status(404) + ctx.Status(http.StatusNotFound) return } diff --git a/routers/web/user/oauth.go b/routers/web/user/oauth.go index 166420221d26a..4ea2a8f87b837 100644 --- a/routers/web/user/oauth.go +++ b/routers/web/user/oauth.go @@ -445,7 +445,7 @@ func AuthorizeOAuth(ctx *context.Context) { log.Error("Unable to update nonce: %v", err) } } - ctx.Redirect(redirect.String(), 302) + ctx.Redirect(redirect.String(), http.StatusTemporaryRedirect) return } @@ -527,7 +527,7 @@ func GrantApplicationOAuth(ctx *context.Context) { handleServerError(ctx, form.State, form.RedirectURI) return } - ctx.Redirect(redirect.String(), 302) + ctx.Redirect(redirect.String(), http.StatusTemporaryRedirect) } // OIDCWellKnown generates JSON so OIDC clients know Gitea's capabilities @@ -735,7 +735,7 @@ func handleAuthorizeError(ctx *context.Context, authErr AuthorizeError, redirect if redirectURI == "" { log.Warn("Authorization failed: %v", authErr.ErrorDescription) ctx.Data["Error"] = authErr - ctx.HTML(400, tplGrantError) + ctx.HTML(http.StatusBadRequest, tplGrantError) return } redirect, err := url.Parse(redirectURI) @@ -748,5 +748,5 @@ func handleAuthorizeError(ctx *context.Context, authErr AuthorizeError, redirect q.Set("error_description", authErr.ErrorDescription) q.Set("state", authErr.State) redirect.RawQuery = q.Encode() - ctx.Redirect(redirect.String(), 302) + ctx.Redirect(redirect.String(), http.StatusTemporaryRedirect) } diff --git a/routers/web/user/setting/account_test.go b/routers/web/user/setting/account_test.go index cd5c77795ea9d..394bf79b965c4 100644 --- a/routers/web/user/setting/account_test.go +++ b/routers/web/user/setting/account_test.go @@ -94,6 +94,6 @@ func TestChangePassword(t *testing.T) { AccountPost(ctx) assert.Contains(t, ctx.Flash.ErrorMsg, req.Message) - assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) } } diff --git a/routers/web/user/setting/security_u2f.go b/routers/web/user/setting/security_u2f.go index d1d6d1e8cad89..7573e43d2b450 100644 --- a/routers/web/user/setting/security_u2f.go +++ b/routers/web/user/setting/security_u2f.go @@ -82,7 +82,7 @@ func U2FRegisterPost(ctx *context.Context) { ctx.ServerError("u2f.Register", err) return } - ctx.Status(200) + ctx.Status(http.StatusOK) } // U2FDelete deletes an security key by id @@ -91,14 +91,14 @@ func U2FDelete(ctx *context.Context) { reg, err := login.GetU2FRegistrationByID(form.ID) if err != nil { if login.IsErrU2FRegistrationNotExist(err) { - ctx.Status(200) + ctx.Status(http.StatusOK) return } ctx.ServerError("GetU2FRegistrationByID", err) return } if reg.UserID != ctx.User.ID { - ctx.Status(401) + ctx.Status(http.StatusUnauthorized) return } if err := login.DeleteRegistration(reg); err != nil { diff --git a/routers/web/web.go b/routers/web/web.go index 41c4e122fb4e9..fd113d552b5ca 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -94,7 +94,7 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route { // this png is very likely to always be below the limit for gzip so it doesn't need to pass through gzip routes.Get("/apple-touch-icon.png", func(w http.ResponseWriter, req *http.Request) { - http.Redirect(w, req, path.Join(setting.StaticURLPrefix, "/assets/img/apple-touch-icon.png"), 301) + http.Redirect(w, req, path.Join(setting.StaticURLPrefix, "/assets/img/apple-touch-icon.png"), http.StatusPermanentRedirect) }) gob.Register(&u2f.Challenge{}) @@ -137,17 +137,17 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route { routes.Get("/ssh_info", func(rw http.ResponseWriter, req *http.Request) { if !git.SupportProcReceive { - rw.WriteHeader(404) + rw.WriteHeader(http.StatusNotFound) return } rw.Header().Set("content-type", "text/json;charset=UTF-8") _, err := rw.Write([]byte(`{"type":"gitea","version":1}`)) if err != nil { log.Error("fail to write result: err: %v", err) - rw.WriteHeader(500) + rw.WriteHeader(http.StatusInternalServerError) return } - rw.WriteHeader(200) + rw.WriteHeader(http.StatusOK) }) // Removed: toolbox.Toolboxer middleware will provide debug information which seems unnecessary diff --git a/services/auth/sspi_windows.go b/services/auth/sspi_windows.go index 19f2349122437..11219a8182aaf 100644 --- a/services/auth/sspi_windows.go +++ b/services/auth/sspi_windows.go @@ -109,7 +109,7 @@ func (s *SSPI) Verify(req *http.Request, w http.ResponseWriter, store DataStore, store.GetData()["EnableOpenIDSignIn"] = setting.Service.EnableOpenIDSignIn store.GetData()["EnableSSPI"] = true - err := s.rnd.HTML(w, 401, string(tplSignIn), templates.BaseVars().Merge(store.GetData())) + err := s.rnd.HTML(w, http.StatusUnauthorized, string(tplSignIn), templates.BaseVars().Merge(store.GetData())) if err != nil { log.Error("%v", err) } diff --git a/services/lfs/locks.go b/services/lfs/locks.go index c2ede20b7cf9f..d0768bcad5d2f 100644 --- a/services/lfs/locks.go +++ b/services/lfs/locks.go @@ -52,7 +52,7 @@ func GetListLockHandler(ctx *context.Context) { if err != nil { log.Debug("Could not find repository: %s/%s - %s", rv.User, rv.Repo, err) ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs") - ctx.JSON(401, api.LFSLockError{ + ctx.JSON(http.StatusUnauthorized, api.LFSLockError{ Message: "You must have pull access to list locks", }) return @@ -139,7 +139,7 @@ func PostLockHandler(ctx *context.Context) { if err != nil { log.Error("Unable to get repository: %s/%s Error: %v", userName, repoName, err) ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs") - ctx.JSON(401, api.LFSLockError{ + ctx.JSON(http.StatusUnauthorized, api.LFSLockError{ Message: "You must have push access to create locks", }) return @@ -164,7 +164,7 @@ func PostLockHandler(ctx *context.Context) { dec := json.NewDecoder(bodyReader) if err := dec.Decode(&req); err != nil { log.Warn("Failed to decode lock request as json. Error: %v", err) - writeStatus(ctx, 400) + writeStatus(ctx, http.StatusBadRequest) return } @@ -206,7 +206,7 @@ func VerifyLockHandler(ctx *context.Context) { if err != nil { log.Error("Unable to get repository: %s/%s Error: %v", userName, repoName, err) ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs") - ctx.JSON(401, api.LFSLockError{ + ctx.JSON(http.StatusUnauthorized, api.LFSLockError{ Message: "You must have push access to verify locks", }) return @@ -272,7 +272,7 @@ func UnLockHandler(ctx *context.Context) { if err != nil { log.Error("Unable to get repository: %s/%s Error: %v", userName, repoName, err) ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs") - ctx.JSON(401, api.LFSLockError{ + ctx.JSON(http.StatusUnauthorized, api.LFSLockError{ Message: "You must have push access to delete locks", }) return @@ -297,7 +297,7 @@ func UnLockHandler(ctx *context.Context) { dec := json.NewDecoder(bodyReader) if err := dec.Decode(&req); err != nil { log.Warn("Failed to decode lock request as json. Error: %v", err) - writeStatus(ctx, 400) + writeStatus(ctx, http.StatusBadRequest) return } diff --git a/services/migrations/gitea_downloader_test.go b/services/migrations/gitea_downloader_test.go index 2c70dc421356f..cc5e3171dbd5b 100644 --- a/services/migrations/gitea_downloader_test.go +++ b/services/migrations/gitea_downloader_test.go @@ -25,7 +25,7 @@ func TestGiteaDownloadRepo(t *testing.T) { } resp, err := http.Get("https://gitea.com/gitea") - if err != nil || resp.StatusCode != 200 { + if err != nil || resp.StatusCode != http.StatusOK { t.Skipf("Can't reach https://gitea.com, skipping %s", t.Name()) } diff --git a/services/migrations/gitlab.go b/services/migrations/gitlab.go index 4eb7e3e47c983..ef910cb3472ed 100644 --- a/services/migrations/gitlab.go +++ b/services/migrations/gitlab.go @@ -92,7 +92,7 @@ func NewGitlabDownloader(ctx context.Context, baseURL, repoPath, username, passw u, _ := url.Parse(baseURL) for len(pathParts) >= 2 { _, resp, err = gitlabClient.Version.GetVersion() - if err == nil || resp != nil && resp.StatusCode == 401 { + if err == nil || resp != nil && resp.StatusCode == http.StatusUnauthorized { err = nil // if no authentication given, this still should work break } @@ -634,7 +634,7 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque func (g *GitlabDownloader) GetReviews(context base.IssueContext) ([]*base.Review, error) { approvals, resp, err := g.client.MergeRequestApprovals.GetConfiguration(g.repoID, int(context.ForeignID()), gitlab.WithContext(g.ctx)) if err != nil { - if resp != nil && resp.StatusCode == 404 { + if resp != nil && resp.StatusCode == http.StatusNotFound { log.Error(fmt.Sprintf("GitlabDownloader: while migrating a error occurred: '%s'", err.Error())) return []*base.Review{}, nil } diff --git a/services/migrations/gitlab_test.go b/services/migrations/gitlab_test.go index f6dc7510cbed8..775ce55f9ad1e 100644 --- a/services/migrations/gitlab_test.go +++ b/services/migrations/gitlab_test.go @@ -25,7 +25,7 @@ func TestGitlabDownloadRepo(t *testing.T) { } resp, err := http.Get("https://gitlab.com/gitea/test_repo") - if err != nil || resp.StatusCode != 200 { + if err != nil || resp.StatusCode != http.StatusOK { t.Skipf("Can't access test repo, skipping %s", t.Name()) } diff --git a/services/migrations/onedev_test.go b/services/migrations/onedev_test.go index 59b7cae5feffe..77beafcbc1375 100644 --- a/services/migrations/onedev_test.go +++ b/services/migrations/onedev_test.go @@ -19,7 +19,7 @@ import ( func TestOneDevDownloadRepo(t *testing.T) { resp, err := http.Get("https://code.onedev.io/projects/go-gitea-test_repo") - if err != nil || resp.StatusCode != 200 { + if err != nil || resp.StatusCode != http.StatusOK { t.Skipf("Can't access test repo, skipping %s", t.Name()) } From d043ac9b36479b4d4c51b539afa27eb45960d28d Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Wed, 22 Dec 2021 07:28:08 +0000 Subject: [PATCH 02/10] Fix status code. --- routers/install/routes.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/install/routes.go b/routers/install/routes.go index 9e89c22155606..0fbdeb0249630 100644 --- a/routers/install/routes.go +++ b/routers/install/routes.go @@ -107,7 +107,7 @@ func Routes() *web.Route { r.Get("/", Install) r.Post("/", web.Bind(forms.InstallForm{}), SubmitInstall) r.NotFound(func(w http.ResponseWriter, req *http.Request) { - http.Redirect(w, req, setting.AppURL, http.StatusPermanentRedirect) + http.Redirect(w, req, setting.AppURL, http.StatusTemporaryRedirect) }) return r } From 081ef7937e9c0e90ceb883a77af45da6f1a25479 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Wed, 22 Dec 2021 15:55:00 +0000 Subject: [PATCH 03/10] Replaced missed numbers with constants. --- integrations/api_branch_test.go | 6 +-- .../api_helper_for_declarative_test.go | 8 ++-- integrations/api_pull_test.go | 10 ++--- integrations/git_smart_http_test.go | 14 +++---- integrations/oauth_test.go | 41 ++++++++++--------- integrations/pull_merge_test.go | 4 +- modules/context/api.go | 4 +- modules/context/context.go | 2 +- routers/api/v1/org/member.go | 2 +- 9 files changed, 46 insertions(+), 45 deletions(-) diff --git a/integrations/api_branch_test.go b/integrations/api_branch_test.go index d898266afee4e..f35b63ad23263 100644 --- a/integrations/api_branch_test.go +++ b/integrations/api_branch_test.go @@ -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) @@ -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) @@ -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) diff --git a/integrations/api_helper_for_declarative_test.go b/integrations/api_helper_for_declarative_test.go index 9c6adaf084b71..28a14fe43f3cd 100644 --- a/integrations/api_helper_for_declarative_test.go +++ b/integrations/api_helper_for_declarative_test.go @@ -226,7 +226,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 } @@ -245,7 +245,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 } @@ -283,7 +283,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, @@ -306,7 +306,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) } } diff --git a/integrations/api_pull_test.go b/integrations/api_pull_test.go index b6b8ad873476c..a1c2a4c3e6edb 100644 --- a/integrations/api_pull_test.go +++ b/integrations/api_pull_test.go @@ -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 } @@ -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) @@ -165,7 +165,7 @@ 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) @@ -173,12 +173,12 @@ func TestAPIEditPull(t *testing.T) { 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) } diff --git a/integrations/git_smart_http_test.go b/integrations/git_smart_http_test.go index c049f71c303dc..0fe93da2f68e7 100644 --- a/integrations/git_smart_http_test.go +++ b/integrations/git_smart_http_test.go @@ -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, }, } diff --git a/integrations/oauth_test.go b/integrations/oauth_test.go index c36aab652b36f..e105bfb395156 100644 --- a/integrations/oauth_test.go +++ b/integrations/oauth_test.go @@ -7,6 +7,7 @@ package integrations import ( "bytes" "io" + "net/http" "testing" "code.gitea.io/gitea/modules/json" @@ -21,20 +22,20 @@ func TestNoClientID(t *testing.T) { defer prepareTestEnv(t)() req := NewRequest(t, "GET", "/login/oauth/authorize") ctx := loginUser(t, "user2") - ctx.MakeRequest(t, req, 400) + ctx.MakeRequest(t, req, http.StatusBadRequest) } func TestLoginRedirect(t *testing.T) { defer prepareTestEnv(t)() req := NewRequest(t, "GET", "/login/oauth/authorize") - assert.Contains(t, MakeRequest(t, req, 302).Body.String(), "/user/login") + assert.Contains(t, MakeRequest(t, req, http.StatusTemporaryRedirect).Body.String(), "/user/login") } func TestShowAuthorize(t *testing.T) { defer prepareTestEnv(t)() req := NewRequest(t, "GET", defaultAuthorize) ctx := loginUser(t, "user4") - resp := ctx.MakeRequest(t, req, 200) + resp := ctx.MakeRequest(t, req, http.StatusOK) htmlDoc := NewHTMLParser(t, resp.Body) htmlDoc.AssertElement(t, "#authorize-app", true) @@ -45,7 +46,7 @@ func TestRedirectWithExistingGrant(t *testing.T) { defer prepareTestEnv(t)() req := NewRequest(t, "GET", defaultAuthorize) ctx := loginUser(t, "user1") - resp := ctx.MakeRequest(t, req, 302) + resp := ctx.MakeRequest(t, req, http.StatusTemporaryRedirect) u, err := resp.Result().Location() assert.NoError(t, err) assert.Equal(t, "thestate", u.Query().Get("state")) @@ -62,7 +63,7 @@ func TestAccessTokenExchange(t *testing.T) { "code": "authcode", "code_verifier": "N1Zo9-8Rfwhkt68r1r29ty8YwIraXR8eh_1Qwxg7yQXsonBt", // test PKCE additionally }) - resp := MakeRequest(t, req, 200) + resp := MakeRequest(t, req, http.StatusOK) type response struct { AccessToken string `json:"access_token"` TokenType string `json:"token_type"` @@ -86,7 +87,7 @@ func TestAccessTokenExchangeWithoutPKCE(t *testing.T) { "code": "authcode", "code_verifier": "N1Zo9-8Rfwhkt68r1r29ty8YwIraXR8eh_1Qwxg7yQXsonBt", // test PKCE additionally }) - resp := MakeRequest(t, req, 200) + resp := MakeRequest(t, req, http.StatusOK) type response struct { AccessToken string `json:"access_token"` TokenType string `json:"token_type"` @@ -109,7 +110,7 @@ func TestAccessTokenExchangeJSON(t *testing.T) { "redirect_uri": "a", "code": "authcode", }) - MakeRequest(t, req, 400) + MakeRequest(t, req, http.StatusBadRequest) } func TestAccessTokenExchangeWithInvalidCredentials(t *testing.T) { @@ -123,7 +124,7 @@ func TestAccessTokenExchangeWithInvalidCredentials(t *testing.T) { "code": "authcode", "code_verifier": "N1Zo9-8Rfwhkt68r1r29ty8YwIraXR8eh_1Qwxg7yQXsonBt", // test PKCE additionally }) - MakeRequest(t, req, 400) + MakeRequest(t, req, http.StatusBadRequest) // invalid client secret req = NewRequestWithValues(t, "POST", "/login/oauth/access_token", map[string]string{ "grant_type": "authorization_code", @@ -133,7 +134,7 @@ func TestAccessTokenExchangeWithInvalidCredentials(t *testing.T) { "code": "authcode", "code_verifier": "N1Zo9-8Rfwhkt68r1r29ty8YwIraXR8eh_1Qwxg7yQXsonBt", // test PKCE additionally }) - MakeRequest(t, req, 400) + MakeRequest(t, req, http.StatusBadRequest) // invalid redirect uri req = NewRequestWithValues(t, "POST", "/login/oauth/access_token", map[string]string{ "grant_type": "authorization_code", @@ -143,7 +144,7 @@ func TestAccessTokenExchangeWithInvalidCredentials(t *testing.T) { "code": "authcode", "code_verifier": "N1Zo9-8Rfwhkt68r1r29ty8YwIraXR8eh_1Qwxg7yQXsonBt", // test PKCE additionally }) - MakeRequest(t, req, 400) + MakeRequest(t, req, http.StatusBadRequest) // invalid authorization code req = NewRequestWithValues(t, "POST", "/login/oauth/access_token", map[string]string{ "grant_type": "authorization_code", @@ -153,7 +154,7 @@ func TestAccessTokenExchangeWithInvalidCredentials(t *testing.T) { "code": "???", "code_verifier": "N1Zo9-8Rfwhkt68r1r29ty8YwIraXR8eh_1Qwxg7yQXsonBt", // test PKCE additionally }) - MakeRequest(t, req, 400) + MakeRequest(t, req, http.StatusBadRequest) // invalid grant_type req = NewRequestWithValues(t, "POST", "/login/oauth/access_token", map[string]string{ "grant_type": "???", @@ -163,7 +164,7 @@ func TestAccessTokenExchangeWithInvalidCredentials(t *testing.T) { "code": "authcode", "code_verifier": "N1Zo9-8Rfwhkt68r1r29ty8YwIraXR8eh_1Qwxg7yQXsonBt", // test PKCE additionally }) - MakeRequest(t, req, 400) + MakeRequest(t, req, http.StatusBadRequest) } func TestAccessTokenExchangeWithBasicAuth(t *testing.T) { @@ -175,7 +176,7 @@ func TestAccessTokenExchangeWithBasicAuth(t *testing.T) { "code_verifier": "N1Zo9-8Rfwhkt68r1r29ty8YwIraXR8eh_1Qwxg7yQXsonBt", // test PKCE additionally }) req.Header.Add("Authorization", "Basic ZGE3ZGEzYmEtOWExMy00MTY3LTg1NmYtMzg5OWRlMGIwMTM4OjRNSzhOYTZSNTVzbWRDWTBXdUNDdW1aNmhqUlBuR1k1c2FXVlJISGpKaUE9") - resp := MakeRequest(t, req, 200) + resp := MakeRequest(t, req, http.StatusOK) type response struct { AccessToken string `json:"access_token"` TokenType string `json:"token_type"` @@ -196,7 +197,7 @@ func TestAccessTokenExchangeWithBasicAuth(t *testing.T) { "code_verifier": "N1Zo9-8Rfwhkt68r1r29ty8YwIraXR8eh_1Qwxg7yQXsonBt", // test PKCE additionally }) req.Header.Add("Authorization", "Basic ZGE3ZGEzYmEtOWExMy00MTY3LTg1NmYtMzg5OWRlMGIwMTM4OmJsYWJsYQ==") - resp = MakeRequest(t, req, 400) + resp = MakeRequest(t, req, http.StatusBadRequest) // missing header req = NewRequestWithValues(t, "POST", "/login/oauth/access_token", map[string]string{ @@ -205,7 +206,7 @@ func TestAccessTokenExchangeWithBasicAuth(t *testing.T) { "code": "authcode", "code_verifier": "N1Zo9-8Rfwhkt68r1r29ty8YwIraXR8eh_1Qwxg7yQXsonBt", // test PKCE additionally }) - resp = MakeRequest(t, req, 400) + resp = MakeRequest(t, req, http.StatusBadRequest) } func TestRefreshTokenInvalidation(t *testing.T) { @@ -218,7 +219,7 @@ func TestRefreshTokenInvalidation(t *testing.T) { "code": "authcode", "code_verifier": "N1Zo9-8Rfwhkt68r1r29ty8YwIraXR8eh_1Qwxg7yQXsonBt", // test PKCE additionally }) - resp := MakeRequest(t, req, 200) + resp := MakeRequest(t, req, http.StatusOK) type response struct { AccessToken string `json:"access_token"` TokenType string `json:"token_type"` @@ -244,16 +245,16 @@ func TestRefreshTokenInvalidation(t *testing.T) { assert.NoError(t, err) refreshReq.Body = io.NopCloser(bytes.NewReader(bs)) - MakeRequest(t, refreshReq, 200) + MakeRequest(t, refreshReq, http.StatusOK) refreshReq.Body = io.NopCloser(bytes.NewReader(bs)) - MakeRequest(t, refreshReq, 200) + MakeRequest(t, refreshReq, http.StatusOK) // test with invalidation setting.OAuth2.InvalidateRefreshTokens = true refreshReq.Body = io.NopCloser(bytes.NewReader(bs)) - MakeRequest(t, refreshReq, 200) + MakeRequest(t, refreshReq, http.StatusOK) refreshReq.Body = io.NopCloser(bytes.NewReader(bs)) - MakeRequest(t, refreshReq, 400) + MakeRequest(t, refreshReq, http.StatusBadRequest) } diff --git a/integrations/pull_merge_test.go b/integrations/pull_merge_test.go index a0b87eeee8368..37b3632b7938e 100644 --- a/integrations/pull_merge_test.go +++ b/integrations/pull_merge_test.go @@ -220,7 +220,7 @@ func TestCantMergeConflict(t *testing.T) { Base: "base", Title: "create a conflicting pr", }) - session.MakeRequest(t, req, 201) + session.MakeRequest(t, req, http.StatusCreated) // Now this PR will be marked conflict - or at least a race will do - so drop down to pure code at this point... user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ @@ -317,7 +317,7 @@ func TestCantMergeUnrelated(t *testing.T) { Base: "base", Title: "create an unrelated pr", }) - session.MakeRequest(t, req, 201) + session.MakeRequest(t, req, http.StatusCreated) // Now this PR could be marked conflict - or at least a race may occur - so drop down to pure code at this point... gitRepo, err := git.OpenRepository(path) diff --git a/modules/context/api.go b/modules/context/api.go index 574d7c424883e..e3354baff1ee4 100644 --- a/modules/context/api.go +++ b/modules/context/api.go @@ -209,7 +209,7 @@ func (ctx *APIContext) RequireCSRF() { if len(headerToken) > 0 || len(formValueToken) > 0 { Validate(ctx.Context, ctx.csrf) } else { - ctx.Context.Error(401, "Missing CSRF token.") + ctx.Context.Error(http.StatusUnauthorized, "Missing CSRF token.") } } @@ -234,7 +234,7 @@ func (ctx *APIContext) CheckForOTP() { return } if !ok { - ctx.Context.Error(401) + ctx.Context.Error(http.StatusUnauthorized) return } } diff --git a/modules/context/context.go b/modules/context/context.go index 6bfc41be6b1e3..536fdf9305698 100644 --- a/modules/context/context.go +++ b/modules/context/context.go @@ -210,7 +210,7 @@ func (ctx *Context) HTML(status int, name base.TplName) { // RenderToString renders the template content to a string func (ctx *Context) RenderToString(name base.TplName, data map[string]interface{}) (string, error) { var buf strings.Builder - err := ctx.Render.HTML(&buf, 200, string(name), data) + err := ctx.Render.HTML(&buf, http.StatusOK, string(name), data) return buf.String(), err } diff --git a/routers/api/v1/org/member.go b/routers/api/v1/org/member.go index 8152d14cb0953..753ffb782a665 100644 --- a/routers/api/v1/org/member.go +++ b/routers/api/v1/org/member.go @@ -130,7 +130,7 @@ func IsMember(ctx *context.APIContext) { // responses: // "204": // description: user is a member - // "302": + // "307": // description: redirection to /orgs/{org}/public_members/{username} // "404": // description: user is not a member From 9b6d725d4ffac6a68680817e04117f7285aa0e18 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Wed, 22 Dec 2021 16:01:22 +0000 Subject: [PATCH 04/10] Replaced constants in integration tests. --- integrations/admin_user_test.go | 2 +- integrations/api_repo_languages_test.go | 2 +- integrations/attachment_test.go | 4 ++-- integrations/auth_ldap_test.go | 4 ++-- integrations/change_default_branch_test.go | 2 +- integrations/create_no_session_test.go | 2 +- integrations/delete_user_test.go | 4 ++-- integrations/editor_test.go | 10 ++++----- integrations/git_test.go | 4 ++-- integrations/integration_test.go | 4 ++-- integrations/issue_test.go | 10 ++++----- integrations/links_test.go | 2 +- integrations/mirror_push_test.go | 4 ++-- integrations/nonascii_branches_test.go | 4 ++-- integrations/privateactivity_test.go | 2 +- integrations/pull_create_test.go | 6 +++--- integrations/pull_merge_test.go | 2 +- integrations/pull_status_test.go | 4 ++-- integrations/release_test.go | 2 +- integrations/rename_branch_test.go | 4 ++-- integrations/repo_branch_test.go | 24 +++++++++++----------- integrations/repo_fork_test.go | 2 +- integrations/repo_generate_test.go | 2 +- integrations/repo_migrate_test.go | 2 +- integrations/setting_test.go | 6 +++--- integrations/signout_test.go | 2 +- integrations/signup_test.go | 6 +++--- integrations/user_avatar_test.go | 2 +- integrations/user_test.go | 4 ++-- integrations/xss_test.go | 2 +- 30 files changed, 65 insertions(+), 65 deletions(-) diff --git a/integrations/admin_user_test.go b/integrations/admin_user_test.go index d657f65fa55e4..91eeda483e034 100644 --- a/integrations/admin_user_test.go +++ b/integrations/admin_user_test.go @@ -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.StatusTemporaryRedirect) } func makeRequest(t *testing.T, formData user_model.User, headerCode int) { diff --git a/integrations/api_repo_languages_test.go b/integrations/api_repo_languages_test.go index ea20e6d5428c3..ea0d837e4d446 100644 --- a/integrations/api_repo_languages_test.go +++ b/integrations/api_repo_languages_test.go @@ -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.StatusTemporaryRedirect) // let gitea calculate language stats time.Sleep(time.Second) diff --git a/integrations/attachment_test.go b/integrations/attachment_test.go index 481104d73f58f..b3a858787e518 100644 --- a/integrations/attachment_test.go +++ b/integrations/attachment_test.go @@ -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.StatusTemporaryRedirect) } func TestCreateIssueAttachment(t *testing.T) { @@ -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.StatusTemporaryRedirect) test.RedirectURL(resp) // check that redirect URL exists //Validate that attachment is available diff --git a/integrations/auth_ldap_test.go b/integrations/auth_ldap_test.go index 6eb017017f8da..55ae389b0f3ad 100644 --- a/integrations/auth_ldap_test.go +++ b/integrations/auth_ldap_test.go @@ -120,7 +120,7 @@ func addAuthSourceLDAP(t *testing.T, sshKeyAttribute string) { "is_sync_enabled": "on", "is_active": "on", }) - session.MakeRequest(t, req, http.StatusFound) + session.MakeRequest(t, req, http.StatusTemporaryRedirect) } func TestLDAPUserSignin(t *testing.T) { @@ -187,7 +187,7 @@ func TestLDAPAuthChange(t *testing.T) { "is_sync_enabled": "on", "is_active": "on", }) - session.MakeRequest(t, req, http.StatusFound) + session.MakeRequest(t, req, http.StatusTemporaryRedirect) req = NewRequest(t, "GET", href) resp = session.MakeRequest(t, req, http.StatusOK) diff --git a/integrations/change_default_branch_test.go b/integrations/change_default_branch_test.go index af5542e0b2d3c..d1a3c70643d68 100644 --- a/integrations/change_default_branch_test.go +++ b/integrations/change_default_branch_test.go @@ -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.StatusTemporaryRedirect) csrf = GetCSRF(t, session, branchesURL) req = NewRequestWithValues(t, "POST", branchesURL, map[string]string{ diff --git a/integrations/create_no_session_test.go b/integrations/create_no_session_test.go index a76ff1eaafb3d..e9e2dd25313e3 100644 --- a/integrations/create_no_session_test.go +++ b/integrations/create_no_session_test.go @@ -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.StatusTemporaryRedirect) sessionID = getSessionID(t, resp) assert.FileExists(t, sessionFile(tmpDir, sessionID)) diff --git a/integrations/delete_user_test.go b/integrations/delete_user_test.go index e44d2e7bd3de1..2e2f2b698118d 100644 --- a/integrations/delete_user_test.go +++ b/integrations/delete_user_test.go @@ -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.StatusTemporaryRedirect) assertUserDeleted(t, 8) unittest.CheckConsistencyFor(t, &user_model.User{}) @@ -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.StatusTemporaryRedirect) // user should not have been deleted, because the user still owns repos unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) diff --git a/integrations/editor_test.go b/integrations/editor_test.go index a46712293e86c..c60c17a45f2c0 100644 --- a/integrations/editor_test.go +++ b/integrations/editor_test.go @@ -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.StatusTemporaryRedirect) }) } @@ -48,7 +48,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) { "_csrf": csrf, "protected": "on", }) - session.MakeRequest(t, req, http.StatusFound) + session.MakeRequest(t, req, http.StatusTemporaryRedirect) // Check if master branch has been locked successfully flashCookie := session.GetCookie("macaron_flash") assert.NotNil(t, flashCookie) @@ -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.StatusTemporaryRedirect) // Check if master branch has been locked successfully flashCookie = session.GetCookie("macaron_flash") assert.NotNil(t, flashCookie) @@ -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.StatusTemporaryRedirect) // Verify the change req = NewRequest(t, "GET", path.Join(user, repo, "raw/branch", branch, filePath)) @@ -140,7 +140,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.StatusTemporaryRedirect) // Verify the change req = NewRequest(t, "GET", path.Join(user, repo, "raw/branch", targetBranch, filePath)) diff --git a/integrations/git_test.go b/integrations/git_test.go index 0d33c786aaefa..d8279f64ee17a 100644 --- a/integrations/git_test.go +++ b/integrations/git_test.go @@ -430,7 +430,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.StatusTemporaryRedirect) } else { user, err := user_model.GetUserByName(userToWhitelist) assert.NoError(t, err) @@ -443,7 +443,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.StatusTemporaryRedirect) } // Check if master branch has been locked successfully flashCookie := ctx.Session.GetCookie("macaron_flash") diff --git a/integrations/integration_test.go b/integrations/integration_test.go index 527d4b951ad27..9683115831385 100644 --- a/integrations/integration_test.go +++ b/integrations/integration_test.go @@ -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.StatusTemporaryRedirect) ch := http.Header{} ch.Add("Cookie", strings.Join(resp.Header()["Set-Cookie"], ";")) @@ -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.StatusTemporaryRedirect) req = NewRequest(t, "GET", "/user/settings/applications") resp = session.MakeRequest(t, req, http.StatusOK) htmlDoc := NewHTMLParser(t, resp.Body) diff --git a/integrations/issue_test.go b/integrations/issue_test.go index a2c74d4bdd8f5..cfa9ec6afc56d 100644 --- a/integrations/issue_test.go +++ b/integrations/issue_test.go @@ -133,7 +133,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.StatusTemporaryRedirect) issueURL := test.RedirectURL(resp) req = NewRequest(t, "GET", issueURL) @@ -164,7 +164,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.StatusTemporaryRedirect) req = NewRequest(t, "GET", test.RedirectURL(resp)) resp = session.MakeRequest(t, req, http.StatusOK) @@ -330,16 +330,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.StatusTemporaryRedirect) 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.StatusTemporaryRedirect) 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.StatusTemporaryRedirect) assert.Equal(t, "/"+path.Join("org26", "repo_external_tracker_alpha", "pulls", "1"), test.RedirectURL(resp)) } diff --git a/integrations/links_test.go b/integrations/links_test.go index 872234e61fcc9..05be2c5693104 100644 --- a/integrations/links_test.go +++ b/integrations/links_test.go @@ -58,7 +58,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.StatusTemporaryRedirect) assert.EqualValues(t, path.Join(setting.AppSubURL, redirectLink), test.RedirectURL(resp)) } diff --git a/integrations/mirror_push_test.go b/integrations/mirror_push_test.go index b231b7a91968c..d40efd75d133a 100644 --- a/integrations/mirror_push_test.go +++ b/integrations/mirror_push_test.go @@ -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.StatusTemporaryRedirect) flashCookie := ctx.Session.GetCookie("macaron_flash") assert.NotNil(t, flashCookie) @@ -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.StatusTemporaryRedirect) flashCookie := ctx.Session.GetCookie("macaron_flash") assert.NotNil(t, flashCookie) diff --git a/integrations/nonascii_branches_test.go b/integrations/nonascii_branches_test.go index 71d0ee3cb106f..8f7efcf6aa0ab 100644 --- a/integrations/nonascii_branches_test.go +++ b/integrations/nonascii_branches_test.go @@ -18,7 +18,7 @@ func testSrcRouteRedirect(t *testing.T, session *TestSession, user, repo, route, // Make request req := NewRequest(t, "GET", path.Join(prefix, route)) - resp := session.MakeRequest(t, req, http.StatusFound) + resp := session.MakeRequest(t, req, http.StatusTemporaryRedirect) // Check Location header location := resp.HeaderMap.Get("Location") @@ -37,7 +37,7 @@ func setDefaultBranch(t *testing.T, session *TestSession, user, repo, branch str "action": "default_branch", "branch": branch, }) - session.MakeRequest(t, req, http.StatusFound) + session.MakeRequest(t, req, http.StatusTemporaryRedirect) } func TestNonasciiBranches(t *testing.T) { diff --git a/integrations/privateactivity_test.go b/integrations/privateactivity_test.go index 7969339644ebe..5f2434bb8096e 100644 --- a/integrations/privateactivity_test.go +++ b/integrations/privateactivity_test.go @@ -51,7 +51,7 @@ func testPrivateActivityHelperEnablePrivateActivity(t *testing.T) { "language": "en-US", "keep_activity_private": "1", }) - session.MakeRequest(t, req, http.StatusFound) + session.MakeRequest(t, req, http.StatusTemporaryRedirect) } func testPrivateActivityHelperHasVisibleActivitiesInHTMLDoc(htmlDoc *HTMLDoc) bool { diff --git a/integrations/pull_create_test.go b/integrations/pull_create_test.go index 948c0b9ce257e..09bdea013fa52 100644 --- a/integrations/pull_create_test.go +++ b/integrations/pull_create_test.go @@ -38,7 +38,7 @@ func testPullCreate(t *testing.T, session *TestSession, user, repo, branch, titl "_csrf": htmlDoc.GetCSRF(), "title": title, }) - resp = session.MakeRequest(t, req, http.StatusFound) + resp = session.MakeRequest(t, req, http.StatusTemporaryRedirect) return resp } @@ -130,7 +130,7 @@ func testDeleteRepository(t *testing.T, session *TestSession, ownerName, repoNam "_csrf": htmlDoc.GetCSRF(), "repo_name": repoName, }) - session.MakeRequest(t, req, http.StatusFound) + session.MakeRequest(t, req, http.StatusTemporaryRedirect) } func TestPullBranchDelete(t *testing.T) { @@ -139,7 +139,7 @@ func TestPullBranchDelete(t *testing.T) { session := loginUser(t, "user1") testRepoFork(t, session, "user2", "repo1", "user1", "repo1") - testCreateBranch(t, session, "user1", "repo1", "branch/master", "master1", http.StatusFound) + testCreateBranch(t, session, "user1", "repo1", "branch/master", "master1", http.StatusTemporaryRedirect) testEditFile(t, session, "user1", "repo1", "master1", "README.md", "Hello, World (Edited)\n") resp := testPullCreate(t, session, "user1", "repo1", "master1", "This is a pull title") diff --git a/integrations/pull_merge_test.go b/integrations/pull_merge_test.go index 37b3632b7938e..1280db765558b 100644 --- a/integrations/pull_merge_test.go +++ b/integrations/pull_merge_test.go @@ -42,7 +42,7 @@ func testPullMerge(t *testing.T, session *TestSession, user, repo, pullnum strin "_csrf": htmlDoc.GetCSRF(), "do": string(mergeStyle), }) - resp = session.MakeRequest(t, req, http.StatusFound) + resp = session.MakeRequest(t, req, http.StatusTemporaryRedirect) return resp } diff --git a/integrations/pull_status_test.go b/integrations/pull_status_test.go index f818643005348..9aead42823faa 100644 --- a/integrations/pull_status_test.go +++ b/integrations/pull_status_test.go @@ -29,7 +29,7 @@ func TestPullCreate_CommitStatus(t *testing.T) { "title": "pull request from status1", }, ) - session.MakeRequest(t, req, http.StatusFound) + session.MakeRequest(t, req, http.StatusTemporaryRedirect) req = NewRequest(t, "GET", "/user1/repo1/pulls") resp := session.MakeRequest(t, req, http.StatusOK) @@ -108,7 +108,7 @@ func TestPullCreate_EmptyChangesWithCommits(t *testing.T) { "title": "pull request from status1", }, ) - session.MakeRequest(t, req, http.StatusFound) + session.MakeRequest(t, req, http.StatusTemporaryRedirect) req = NewRequest(t, "GET", "/user1/repo1/pulls/1") resp := session.MakeRequest(t, req, http.StatusOK) diff --git a/integrations/release_test.go b/integrations/release_test.go index 28e03477917a3..a36a17ea4d9de 100644 --- a/integrations/release_test.go +++ b/integrations/release_test.go @@ -43,7 +43,7 @@ func createNewRelease(t *testing.T, session *TestSession, repoURL, tag, title st } req = NewRequestWithValues(t, "POST", link, postData) - resp = session.MakeRequest(t, req, http.StatusFound) + resp = session.MakeRequest(t, req, http.StatusTemporaryRedirect) test.RedirectURL(resp) // check that redirect URL exists } diff --git a/integrations/rename_branch_test.go b/integrations/rename_branch_test.go index e856214f3c51b..831c0ebe10888 100644 --- a/integrations/rename_branch_test.go +++ b/integrations/rename_branch_test.go @@ -27,7 +27,7 @@ func TestRenameBranch(t *testing.T) { "to": "main", } req = NewRequestWithValues(t, "POST", "/user2/repo1/settings/rename_branch", postData) - session.MakeRequest(t, req, http.StatusFound) + session.MakeRequest(t, req, http.StatusTemporaryRedirect) // check new branch link req = NewRequestWithValues(t, "GET", "/user2/repo1/src/branch/main/README.md", postData) @@ -35,7 +35,7 @@ func TestRenameBranch(t *testing.T) { // check old branch link req = NewRequestWithValues(t, "GET", "/user2/repo1/src/branch/master/README.md", postData) - resp = session.MakeRequest(t, req, http.StatusFound) + resp = session.MakeRequest(t, req, http.StatusTemporaryRedirect) location := resp.HeaderMap.Get("Location") assert.Equal(t, "/user2/repo1/src/branch/main/README.md", location) diff --git a/integrations/repo_branch_test.go b/integrations/repo_branch_test.go index af5c475ea7dcb..fb976442d8eb7 100644 --- a/integrations/repo_branch_test.go +++ b/integrations/repo_branch_test.go @@ -30,7 +30,7 @@ func testCreateBranch(t testing.TB, session *TestSession, user, repo, oldRefSubU "new_branch_name": newBranchName, }) resp := session.MakeRequest(t, req, expectedStatus) - if expectedStatus != http.StatusFound { + if expectedStatus != http.StatusTemporaryRedirect { return "" } return test.RedirectURL(resp) @@ -51,37 +51,37 @@ func testCreateBranches(t *testing.T, giteaURL *url.URL) { { OldRefSubURL: "branch/master", NewBranch: "feature/test1", - ExpectedStatus: http.StatusFound, + ExpectedStatus: http.StatusTemporaryRedirect, FlashMessage: i18n.Tr("en", "repo.branch.create_success", "feature/test1"), }, { OldRefSubURL: "branch/master", NewBranch: "", - ExpectedStatus: http.StatusFound, + ExpectedStatus: http.StatusTemporaryRedirect, FlashMessage: i18n.Tr("en", "form.NewBranchName") + i18n.Tr("en", "form.require_error"), }, { OldRefSubURL: "branch/master", NewBranch: "feature=test1", - ExpectedStatus: http.StatusFound, + ExpectedStatus: http.StatusTemporaryRedirect, FlashMessage: i18n.Tr("en", "repo.branch.create_success", "feature=test1"), }, { OldRefSubURL: "branch/master", NewBranch: strings.Repeat("b", 101), - ExpectedStatus: http.StatusFound, + ExpectedStatus: http.StatusTemporaryRedirect, FlashMessage: i18n.Tr("en", "form.NewBranchName") + i18n.Tr("en", "form.max_size_error", "100"), }, { OldRefSubURL: "branch/master", NewBranch: "master", - ExpectedStatus: http.StatusFound, + ExpectedStatus: http.StatusTemporaryRedirect, FlashMessage: i18n.Tr("en", "repo.branch.branch_already_exists", "master"), }, { OldRefSubURL: "branch/master", NewBranch: "master/test", - ExpectedStatus: http.StatusFound, + ExpectedStatus: http.StatusTemporaryRedirect, FlashMessage: i18n.Tr("en", "repo.branch.branch_name_conflict", "master/test", "master"), }, { @@ -92,21 +92,21 @@ func testCreateBranches(t *testing.T, giteaURL *url.URL) { { OldRefSubURL: "commit/65f1bf27bc3bf70f64657658635e66094edbcb4d", NewBranch: "feature/test3", - ExpectedStatus: http.StatusFound, + ExpectedStatus: http.StatusTemporaryRedirect, FlashMessage: i18n.Tr("en", "repo.branch.create_success", "feature/test3"), }, { OldRefSubURL: "branch/master", NewBranch: "v1.0.0", CreateRelease: "v1.0.0", - ExpectedStatus: http.StatusFound, + ExpectedStatus: http.StatusTemporaryRedirect, FlashMessage: i18n.Tr("en", "repo.branch.tag_collision", "v1.0.0"), }, { OldRefSubURL: "tag/v1.0.0", NewBranch: "feature/test4", CreateRelease: "v1.0.1", - ExpectedStatus: http.StatusFound, + ExpectedStatus: http.StatusTemporaryRedirect, FlashMessage: i18n.Tr("en", "repo.branch.create_success", "feature/test4"), }, } @@ -116,7 +116,7 @@ func testCreateBranches(t *testing.T, giteaURL *url.URL) { createNewRelease(t, session, "/user2/repo1", test.CreateRelease, test.CreateRelease, false, false) } redirectURL := testCreateBranch(t, session, "user2", "repo1", test.OldRefSubURL, test.NewBranch, test.ExpectedStatus) - if test.ExpectedStatus == http.StatusFound { + if test.ExpectedStatus == http.StatusTemporaryRedirect { req := NewRequest(t, "GET", redirectURL) resp := session.MakeRequest(t, req, http.StatusOK) htmlDoc := NewHTMLParser(t, resp.Body) @@ -135,7 +135,7 @@ func TestCreateBranchInvalidCSRF(t *testing.T) { "_csrf": "fake_csrf", "new_branch_name": "test", }) - resp := session.MakeRequest(t, req, http.StatusFound) + resp := session.MakeRequest(t, req, http.StatusTemporaryRedirect) loc := resp.Header().Get("Location") assert.Equal(t, setting.AppSubURL+"/", loc) resp = session.MakeRequest(t, NewRequest(t, "GET", loc), http.StatusOK) diff --git a/integrations/repo_fork_test.go b/integrations/repo_fork_test.go index 27b62d264652d..12c2c4933bff8 100644 --- a/integrations/repo_fork_test.go +++ b/integrations/repo_fork_test.go @@ -45,7 +45,7 @@ func testRepoFork(t *testing.T, session *TestSession, ownerName, repoName, forkO "uid": fmt.Sprintf("%d", forkOwner.ID), "repo_name": forkRepoName, }) - resp = session.MakeRequest(t, req, http.StatusFound) + resp = session.MakeRequest(t, req, http.StatusTemporaryRedirect) // Step4: check the existence of the forked repo req = NewRequestf(t, "GET", "/%s/%s", forkOwnerName, forkRepoName) diff --git a/integrations/repo_generate_test.go b/integrations/repo_generate_test.go index b70a4a4797393..b2fb16c929147 100644 --- a/integrations/repo_generate_test.go +++ b/integrations/repo_generate_test.go @@ -46,7 +46,7 @@ func testRepoGenerate(t *testing.T, session *TestSession, templateOwnerName, tem "repo_name": generateRepoName, "git_content": "true", }) - resp = session.MakeRequest(t, req, http.StatusFound) + resp = session.MakeRequest(t, req, http.StatusTemporaryRedirect) // Step4: check the existence of the generated repo req = NewRequestf(t, "GET", "/%s/%s", generateOwnerName, generateRepoName) diff --git a/integrations/repo_migrate_test.go b/integrations/repo_migrate_test.go index e6ba15b137bd0..d571d4255f0db 100644 --- a/integrations/repo_migrate_test.go +++ b/integrations/repo_migrate_test.go @@ -33,7 +33,7 @@ func testRepoMigrate(t testing.TB, session *TestSession, cloneAddr, repoName str "repo_name": repoName, "service": fmt.Sprintf("%d", structs.PlainGitService), }) - resp = session.MakeRequest(t, req, http.StatusFound) + resp = session.MakeRequest(t, req, http.StatusTemporaryRedirect) return resp } diff --git a/integrations/setting_test.go b/integrations/setting_test.go index eb495acb24454..58610666b89c3 100644 --- a/integrations/setting_test.go +++ b/integrations/setting_test.go @@ -91,17 +91,17 @@ func TestSettingLandingPage(t *testing.T) { setting.LandingPageURL = setting.LandingPageExplore req = NewRequest(t, "GET", "/") - resp := MakeRequest(t, req, http.StatusFound) + resp := MakeRequest(t, req, http.StatusTemporaryRedirect) assert.Equal(t, "/explore", resp.Header().Get("Location")) setting.LandingPageURL = setting.LandingPageOrganizations req = NewRequest(t, "GET", "/") - resp = MakeRequest(t, req, http.StatusFound) + resp = MakeRequest(t, req, http.StatusTemporaryRedirect) assert.Equal(t, "/explore/organizations", resp.Header().Get("Location")) setting.LandingPageURL = setting.LandingPageLogin req = NewRequest(t, "GET", "/") - resp = MakeRequest(t, req, http.StatusFound) + resp = MakeRequest(t, req, http.StatusTemporaryRedirect) assert.Equal(t, "/user/login", resp.Header().Get("Location")) setting.LandingPageURL = landingPage diff --git a/integrations/signout_test.go b/integrations/signout_test.go index b54e7ee9eeec4..0c2c4a0ec8ff9 100644 --- a/integrations/signout_test.go +++ b/integrations/signout_test.go @@ -15,7 +15,7 @@ func TestSignOut(t *testing.T) { session := loginUser(t, "user2") req := NewRequest(t, "POST", "/user/logout") - session.MakeRequest(t, req, http.StatusFound) + session.MakeRequest(t, req, http.StatusTemporaryRedirect) // try to view a private repo, should fail req = NewRequest(t, "GET", "/user2/repo2") diff --git a/integrations/signup_test.go b/integrations/signup_test.go index 93e384076ffd3..feb494c913901 100644 --- a/integrations/signup_test.go +++ b/integrations/signup_test.go @@ -29,7 +29,7 @@ func TestSignup(t *testing.T) { "password": "examplePassword!1", "retype": "examplePassword!1", }) - MakeRequest(t, req, http.StatusFound) + MakeRequest(t, req, http.StatusTemporaryRedirect) // should be able to view new user's page req = NewRequest(t, "GET", "/exampleUser") @@ -48,7 +48,7 @@ func TestSignupAsRestricted(t *testing.T) { "password": "examplePassword!1", "retype": "examplePassword!1", }) - MakeRequest(t, req, http.StatusFound) + MakeRequest(t, req, http.StatusTemporaryRedirect) // should be able to view new user's page req = NewRequest(t, "GET", "/restrictedUser") @@ -71,7 +71,7 @@ func TestSignupEmail(t *testing.T) { {"exampleUser@example.com\r\n", http.StatusOK, i18n.Tr("en", "form.email_invalid", nil)}, {"exampleUser@example.com\r", http.StatusOK, i18n.Tr("en", "form.email_invalid", nil)}, {"exampleUser@example.com\n", http.StatusOK, i18n.Tr("en", "form.email_invalid", nil)}, - {"exampleUser@example.com", http.StatusFound, ""}, + {"exampleUser@example.com", http.StatusTemporaryRedirect, ""}, } for i, test := range tests { diff --git a/integrations/user_avatar_test.go b/integrations/user_avatar_test.go index d1005bce078b5..0ce63adb26793 100644 --- a/integrations/user_avatar_test.go +++ b/integrations/user_avatar_test.go @@ -70,7 +70,7 @@ func TestUserAvatar(t *testing.T) { req.Header.Add("X-Csrf-Token", csrf) req.Header.Add("Content-Type", writer.FormDataContentType()) - session.MakeRequest(t, req, http.StatusFound) + session.MakeRequest(t, req, http.StatusTemporaryRedirect) user2 = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) // owner of the repo3, is an org diff --git a/integrations/user_test.go b/integrations/user_test.go index 8552993217a7a..bd2c7548228e0 100644 --- a/integrations/user_test.go +++ b/integrations/user_test.go @@ -33,7 +33,7 @@ func TestRenameUsername(t *testing.T) { "email": "user2@example.com", "language": "en-US", }) - session.MakeRequest(t, req, http.StatusFound) + session.MakeRequest(t, req, http.StatusTemporaryRedirect) unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "newUsername"}) unittest.AssertNotExistsBean(t, &user_model.User{Name: "user2"}) @@ -103,7 +103,7 @@ func TestRenameReservedUsername(t *testing.T) { "email": "user2@example.com", "language": "en-US", }) - resp := session.MakeRequest(t, req, http.StatusFound) + resp := session.MakeRequest(t, req, http.StatusTemporaryRedirect) req = NewRequest(t, "GET", test.RedirectURL(resp)) resp = session.MakeRequest(t, req, http.StatusOK) diff --git a/integrations/xss_test.go b/integrations/xss_test.go index 4c2e60e799b71..f09be6e57d2eb 100644 --- a/integrations/xss_test.go +++ b/integrations/xss_test.go @@ -27,7 +27,7 @@ func TestXSSUserFullName(t *testing.T) { "email": user.Email, "language": "en-US", }) - session.MakeRequest(t, req, http.StatusFound) + session.MakeRequest(t, req, http.StatusTemporaryRedirect) req = NewRequestf(t, "GET", "/%s", user.Name) resp := session.MakeRequest(t, req, http.StatusOK) From 7627e3b424dcf13b853a7924314eedf349526461 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Wed, 22 Dec 2021 16:06:32 +0000 Subject: [PATCH 05/10] Make swagger. --- templates/swagger/v1_json.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index b016ad22a2d62..88a82699cbda8 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -1474,7 +1474,7 @@ "204": { "description": "user is a member" }, - "302": { + "307": { "description": "redirection to /orgs/{org}/public_members/{username}" }, "404": { From b8c7fc1f61790173b5641d4bbb03dcf1f6ca1c6d Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Wed, 22 Dec 2021 19:39:24 +0000 Subject: [PATCH 06/10] Use SeeOther as per spec. --- routers/web/user/oauth.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/routers/web/user/oauth.go b/routers/web/user/oauth.go index 4ea2a8f87b837..4011465908b23 100644 --- a/routers/web/user/oauth.go +++ b/routers/web/user/oauth.go @@ -445,7 +445,7 @@ func AuthorizeOAuth(ctx *context.Context) { log.Error("Unable to update nonce: %v", err) } } - ctx.Redirect(redirect.String(), http.StatusTemporaryRedirect) + ctx.Redirect(redirect.String(), http.StatusSeeOther) return } @@ -527,7 +527,7 @@ func GrantApplicationOAuth(ctx *context.Context) { handleServerError(ctx, form.State, form.RedirectURI) return } - ctx.Redirect(redirect.String(), http.StatusTemporaryRedirect) + ctx.Redirect(redirect.String(), http.StatusSeeOther) } // OIDCWellKnown generates JSON so OIDC clients know Gitea's capabilities @@ -748,5 +748,5 @@ func handleAuthorizeError(ctx *context.Context, authErr AuthorizeError, redirect q.Set("error_description", authErr.ErrorDescription) q.Set("state", authErr.State) redirect.RawQuery = q.Encode() - ctx.Redirect(redirect.String(), http.StatusTemporaryRedirect) + ctx.Redirect(redirect.String(), http.StatusSeeOther) } From d77129efc1adb5b7f6707ddabd0d0e32ea9b3a14 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Wed, 29 Dec 2021 21:31:38 +0000 Subject: [PATCH 07/10] Updated http status codes. --- modules/context/context.go | 4 ++-- modules/context/repo.go | 2 +- routers/api/v1/org/member.go | 4 ++-- routers/install/routes.go | 2 +- routers/web/explore/code.go | 2 +- routers/web/repo/issue.go | 6 +++--- routers/web/repo/issue_dependency.go | 4 ++-- routers/web/repo/issue_lock.go | 4 ++-- routers/web/repo/issue_watch.go | 2 +- routers/web/repo/search.go | 2 +- routers/web/user/oauth.go | 2 +- 11 files changed, 17 insertions(+), 17 deletions(-) diff --git a/modules/context/context.go b/modules/context/context.go index e6ae0068bcc41..7c057008b29ba 100644 --- a/modules/context/context.go +++ b/modules/context/context.go @@ -137,7 +137,7 @@ func RedirectToUser(ctx *Context, userName string, redirectUserID int64) { if ctx.Req.URL.RawQuery != "" { redirectPath += "?" + ctx.Req.URL.RawQuery } - ctx.Redirect(path.Join(setting.AppSubURL, redirectPath)) + ctx.Redirect(path.Join(setting.AppSubURL, redirectPath), http.StatusTemporaryRedirect) } // HasAPIError returns true if error occurs in form validation. @@ -379,7 +379,7 @@ func (ctx *Context) JSON(status int, content interface{}) { // Redirect redirects the request func (ctx *Context) Redirect(location string, status ...int) { - code := http.StatusTemporaryRedirect + code := http.StatusSeeOther if len(status) == 1 { code = status[0] } diff --git a/modules/context/repo.go b/modules/context/repo.go index e259168d56718..925ededa3383c 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -336,7 +336,7 @@ func RedirectToRepo(ctx *Context, redirectRepoID int64) { if ctx.Req.URL.RawQuery != "" { redirectPath += "?" + ctx.Req.URL.RawQuery } - ctx.Redirect(path.Join(setting.AppSubURL, redirectPath)) + ctx.Redirect(path.Join(setting.AppSubURL, redirectPath), http.StatusTemporaryRedirect) } func repoAssignment(ctx *Context, repo *repo_model.Repository) { diff --git a/routers/api/v1/org/member.go b/routers/api/v1/org/member.go index 753ffb782a665..ba3ab4fdca599 100644 --- a/routers/api/v1/org/member.go +++ b/routers/api/v1/org/member.go @@ -130,7 +130,7 @@ func IsMember(ctx *context.APIContext) { // responses: // "204": // description: user is a member - // "307": + // "303": // description: redirection to /orgs/{org}/public_members/{username} // "404": // description: user is not a member @@ -161,7 +161,7 @@ func IsMember(ctx *context.APIContext) { } redirectURL := setting.AppSubURL + "/api/v1/orgs/" + url.PathEscape(ctx.Org.Organization.Name) + "/public_members/" + url.PathEscape(userToCheck.Name) - ctx.Redirect(redirectURL, http.StatusTemporaryRedirect) + ctx.Redirect(redirectURL) } // IsPublicMember check if a user is a public member of an organization diff --git a/routers/install/routes.go b/routers/install/routes.go index 0fbdeb0249630..10b878db457b2 100644 --- a/routers/install/routes.go +++ b/routers/install/routes.go @@ -107,7 +107,7 @@ func Routes() *web.Route { r.Get("/", Install) r.Post("/", web.Bind(forms.InstallForm{}), SubmitInstall) r.NotFound(func(w http.ResponseWriter, req *http.Request) { - http.Redirect(w, req, setting.AppURL, http.StatusTemporaryRedirect) + http.Redirect(w, req, setting.AppURL, http.StatusSeeOther) }) return r } diff --git a/routers/web/explore/code.go b/routers/web/explore/code.go index 67445192ca5d9..2cdda2e07d891 100644 --- a/routers/web/explore/code.go +++ b/routers/web/explore/code.go @@ -24,7 +24,7 @@ const ( // Code render explore code page func Code(ctx *context.Context) { if !setting.Indexer.RepoIndexerEnabled { - ctx.Redirect(setting.AppSubURL+"/explore", http.StatusTemporaryRedirect) + ctx.Redirect(setting.AppSubURL+"/explore") return } diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 5a3486de00945..ce35c3b26d12b 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -2072,7 +2072,7 @@ func NewComment(ctx *context.Context) { if issue.IsLocked && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) && !ctx.User.IsAdmin { ctx.Flash.Error(ctx.Tr("repo.issues.comment_on_locked")) - ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther) + ctx.Redirect(issue.HTMLURL()) return } @@ -2125,10 +2125,10 @@ func NewComment(ctx *context.Context) { if models.IsErrDependenciesLeft(err) { if issue.IsPull { ctx.Flash.Error(ctx.Tr("repo.issues.dependency.pr_close_blocked")) - ctx.Redirect(fmt.Sprintf("%s/pulls/%d", ctx.Repo.RepoLink, issue.Index), http.StatusSeeOther) + ctx.Redirect(fmt.Sprintf("%s/pulls/%d", ctx.Repo.RepoLink, issue.Index)) } else { ctx.Flash.Error(ctx.Tr("repo.issues.dependency.issue_close_blocked")) - ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index), http.StatusSeeOther) + ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index)) } return } diff --git a/routers/web/repo/issue_dependency.go b/routers/web/repo/issue_dependency.go index 015f31d8304ff..aeb98e17b82a6 100644 --- a/routers/web/repo/issue_dependency.go +++ b/routers/web/repo/issue_dependency.go @@ -35,7 +35,7 @@ func AddDependency(ctx *context.Context) { } // Redirect - defer ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther) + defer ctx.Redirect(issue.HTMLURL()) // Dependency dep, err := models.GetIssueByID(depID) @@ -125,5 +125,5 @@ func RemoveDependency(ctx *context.Context) { } // Redirect - ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther) + ctx.Redirect(issue.HTMLURL()) } diff --git a/routers/web/repo/issue_lock.go b/routers/web/repo/issue_lock.go index 36894b4be3b9f..2ac89b98a791d 100644 --- a/routers/web/repo/issue_lock.go +++ b/routers/web/repo/issue_lock.go @@ -43,7 +43,7 @@ func LockIssue(ctx *context.Context) { return } - ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther) + ctx.Redirect(issue.HTMLURL()) } // UnlockIssue unlocks a previously locked issue. @@ -68,5 +68,5 @@ func UnlockIssue(ctx *context.Context) { return } - ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther) + ctx.Redirect(issue.HTMLURL()) } diff --git a/routers/web/repo/issue_watch.go b/routers/web/repo/issue_watch.go index dabbff842b195..5f10a840ffdd3 100644 --- a/routers/web/repo/issue_watch.go +++ b/routers/web/repo/issue_watch.go @@ -53,5 +53,5 @@ func IssueWatch(ctx *context.Context) { return } - ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther) + ctx.Redirect(issue.HTMLURL()) } diff --git a/routers/web/repo/search.go b/routers/web/repo/search.go index bfb28612642ac..59830b5ee630c 100644 --- a/routers/web/repo/search.go +++ b/routers/web/repo/search.go @@ -18,7 +18,7 @@ const tplSearch base.TplName = "repo/search" // Search render repository search page func Search(ctx *context.Context) { if !setting.Indexer.RepoIndexerEnabled { - ctx.Redirect(ctx.Repo.RepoLink, http.StatusTemporaryRedirect) + ctx.Redirect(ctx.Repo.RepoLink) return } language := ctx.FormTrim("l") diff --git a/routers/web/user/oauth.go b/routers/web/user/oauth.go index 4011465908b23..41b6cfedc02da 100644 --- a/routers/web/user/oauth.go +++ b/routers/web/user/oauth.go @@ -445,7 +445,7 @@ func AuthorizeOAuth(ctx *context.Context) { log.Error("Unable to update nonce: %v", err) } } - ctx.Redirect(redirect.String(), http.StatusSeeOther) + ctx.Redirect(redirect.String()) return } From 853c1ce0735144ac9620bd02aaa561294ee60ad0 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Wed, 29 Dec 2021 23:02:04 +0000 Subject: [PATCH 08/10] lint --- routers/web/explore/code.go | 2 +- routers/web/repo/issue_lock.go | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/routers/web/explore/code.go b/routers/web/explore/code.go index 2cdda2e07d891..a29a8f43c29f2 100644 --- a/routers/web/explore/code.go +++ b/routers/web/explore/code.go @@ -24,7 +24,7 @@ const ( // Code render explore code page func Code(ctx *context.Context) { if !setting.Indexer.RepoIndexerEnabled { - ctx.Redirect(setting.AppSubURL+"/explore") + ctx.Redirect(setting.AppSubURL + "/explore") return } diff --git a/routers/web/repo/issue_lock.go b/routers/web/repo/issue_lock.go index 2ac89b98a791d..d628995b945ac 100644 --- a/routers/web/repo/issue_lock.go +++ b/routers/web/repo/issue_lock.go @@ -5,8 +5,6 @@ package repo import ( - "net/http" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/web" From 1ea86844011aa8d146ecd6eac41087076eaf2fc2 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Wed, 29 Dec 2021 23:26:58 +0000 Subject: [PATCH 09/10] Adjusted tests. --- integrations/admin_user_test.go | 2 +- integrations/api_repo_languages_test.go | 2 +- integrations/attachment_test.go | 4 ++-- integrations/auth_ldap_test.go | 4 ++-- integrations/change_default_branch_test.go | 2 +- integrations/create_no_session_test.go | 2 +- integrations/delete_user_test.go | 4 ++-- integrations/editor_test.go | 10 ++++----- integrations/git_test.go | 4 ++-- integrations/integration_test.go | 4 ++-- integrations/issue_test.go | 10 ++++----- integrations/links_test.go | 2 +- integrations/mirror_push_test.go | 4 ++-- integrations/nonascii_branches_test.go | 4 ++-- integrations/oauth_test.go | 4 ++-- integrations/privateactivity_test.go | 2 +- integrations/pull_create_test.go | 6 +++--- integrations/pull_merge_test.go | 2 +- integrations/pull_status_test.go | 4 ++-- integrations/release_test.go | 2 +- integrations/rename_branch_test.go | 4 ++-- integrations/repo_branch_test.go | 24 +++++++++++----------- integrations/repo_fork_test.go | 2 +- integrations/repo_generate_test.go | 2 +- integrations/repo_migrate_test.go | 2 +- integrations/setting_test.go | 6 +++--- integrations/signout_test.go | 2 +- integrations/signup_test.go | 6 +++--- integrations/user_avatar_test.go | 2 +- integrations/user_test.go | 4 ++-- integrations/xss_test.go | 2 +- routers/web/repo/issue_label_test.go | 6 +++--- routers/web/repo/settings_test.go | 22 ++++++++++---------- routers/web/repo/wiki_test.go | 4 ++-- routers/web/user/setting/account_test.go | 2 +- 35 files changed, 84 insertions(+), 84 deletions(-) diff --git a/integrations/admin_user_test.go b/integrations/admin_user_test.go index 91eeda483e034..59adac7ecc65b 100644 --- a/integrations/admin_user_test.go +++ b/integrations/admin_user_test.go @@ -46,7 +46,7 @@ func TestAdminEditUser(t *testing.T) { } func testSuccessfullEdit(t *testing.T, formData user_model.User) { - makeRequest(t, formData, http.StatusTemporaryRedirect) + makeRequest(t, formData, http.StatusSeeOther) } func makeRequest(t *testing.T, formData user_model.User, headerCode int) { diff --git a/integrations/api_repo_languages_test.go b/integrations/api_repo_languages_test.go index ea0d837e4d446..8775d2502998c 100644 --- a/integrations/api_repo_languages_test.go +++ b/integrations/api_repo_languages_test.go @@ -33,7 +33,7 @@ func TestRepoLanguages(t *testing.T) { "content": "package main", "commit_choice": "direct", }) - session.MakeRequest(t, req, http.StatusTemporaryRedirect) + session.MakeRequest(t, req, http.StatusSeeOther) // let gitea calculate language stats time.Sleep(time.Second) diff --git a/integrations/attachment_test.go b/integrations/attachment_test.go index b3a858787e518..a43e9118bd6e5 100644 --- a/integrations/attachment_test.go +++ b/integrations/attachment_test.go @@ -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.StatusTemporaryRedirect) + createAttachment(t, session, "user2/repo1", "image.png", generateImg(), http.StatusSeeOther) } func TestCreateIssueAttachment(t *testing.T) { @@ -83,7 +83,7 @@ func TestCreateIssueAttachment(t *testing.T) { } req = NewRequestWithValues(t, "POST", link, postData) - resp = session.MakeRequest(t, req, http.StatusTemporaryRedirect) + resp = session.MakeRequest(t, req, http.StatusSeeOther) test.RedirectURL(resp) // check that redirect URL exists //Validate that attachment is available diff --git a/integrations/auth_ldap_test.go b/integrations/auth_ldap_test.go index 55ae389b0f3ad..7a46394123a4a 100644 --- a/integrations/auth_ldap_test.go +++ b/integrations/auth_ldap_test.go @@ -120,7 +120,7 @@ func addAuthSourceLDAP(t *testing.T, sshKeyAttribute string) { "is_sync_enabled": "on", "is_active": "on", }) - session.MakeRequest(t, req, http.StatusTemporaryRedirect) + session.MakeRequest(t, req, http.StatusSeeOther) } func TestLDAPUserSignin(t *testing.T) { @@ -187,7 +187,7 @@ func TestLDAPAuthChange(t *testing.T) { "is_sync_enabled": "on", "is_active": "on", }) - session.MakeRequest(t, req, http.StatusTemporaryRedirect) + session.MakeRequest(t, req, http.StatusSeeOther) req = NewRequest(t, "GET", href) resp = session.MakeRequest(t, req, http.StatusOK) diff --git a/integrations/change_default_branch_test.go b/integrations/change_default_branch_test.go index d1a3c70643d68..096afa28f46f5 100644 --- a/integrations/change_default_branch_test.go +++ b/integrations/change_default_branch_test.go @@ -28,7 +28,7 @@ func TestChangeDefaultBranch(t *testing.T) { "action": "default_branch", "branch": "DefaultBranch", }) - session.MakeRequest(t, req, http.StatusTemporaryRedirect) + session.MakeRequest(t, req, http.StatusSeeOther) csrf = GetCSRF(t, session, branchesURL) req = NewRequestWithValues(t, "POST", branchesURL, map[string]string{ diff --git a/integrations/create_no_session_test.go b/integrations/create_no_session_test.go index e9e2dd25313e3..49234c1e9599c 100644 --- a/integrations/create_no_session_test.go +++ b/integrations/create_no_session_test.go @@ -110,7 +110,7 @@ func TestSessionFileCreation(t *testing.T) { "user_name": "user2", "password": userPassword, }) - resp = MakeRequest(t, req, http.StatusTemporaryRedirect) + resp = MakeRequest(t, req, http.StatusSeeOther) sessionID = getSessionID(t, resp) assert.FileExists(t, sessionFile(tmpDir, sessionID)) diff --git a/integrations/delete_user_test.go b/integrations/delete_user_test.go index 2e2f2b698118d..f24d75065f200 100644 --- a/integrations/delete_user_test.go +++ b/integrations/delete_user_test.go @@ -36,7 +36,7 @@ func TestUserDeleteAccount(t *testing.T) { req := NewRequestWithValues(t, "POST", urlStr, map[string]string{ "_csrf": csrf, }) - session.MakeRequest(t, req, http.StatusTemporaryRedirect) + session.MakeRequest(t, req, http.StatusSeeOther) assertUserDeleted(t, 8) unittest.CheckConsistencyFor(t, &user_model.User{}) @@ -51,7 +51,7 @@ func TestUserDeleteAccountStillOwnRepos(t *testing.T) { req := NewRequestWithValues(t, "POST", urlStr, map[string]string{ "_csrf": csrf, }) - session.MakeRequest(t, req, http.StatusTemporaryRedirect) + 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}) diff --git a/integrations/editor_test.go b/integrations/editor_test.go index c60c17a45f2c0..621c9fc8b457d 100644 --- a/integrations/editor_test.go +++ b/integrations/editor_test.go @@ -34,7 +34,7 @@ func TestCreateFile(t *testing.T) { "content": "Content", "commit_choice": "direct", }) - session.MakeRequest(t, req, http.StatusTemporaryRedirect) + session.MakeRequest(t, req, http.StatusSeeOther) }) } @@ -48,7 +48,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) { "_csrf": csrf, "protected": "on", }) - session.MakeRequest(t, req, http.StatusTemporaryRedirect) + session.MakeRequest(t, req, http.StatusSeeOther) // Check if master branch has been locked successfully flashCookie := session.GetCookie("macaron_flash") assert.NotNil(t, flashCookie) @@ -82,7 +82,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) { "_csrf": csrf, "protected": "off", }) - resp = session.MakeRequest(t, req, http.StatusTemporaryRedirect) + resp = session.MakeRequest(t, req, http.StatusSeeOther) // Check if master branch has been locked successfully flashCookie = session.GetCookie("macaron_flash") assert.NotNil(t, flashCookie) @@ -109,7 +109,7 @@ func testEditFile(t *testing.T, session *TestSession, user, repo, branch, filePa "commit_choice": "direct", }, ) - resp = session.MakeRequest(t, req, http.StatusTemporaryRedirect) + resp = session.MakeRequest(t, req, http.StatusSeeOther) // Verify the change req = NewRequest(t, "GET", path.Join(user, repo, "raw/branch", branch, filePath)) @@ -140,7 +140,7 @@ func testEditFileToNewBranch(t *testing.T, session *TestSession, user, repo, bra "new_branch_name": targetBranch, }, ) - resp = session.MakeRequest(t, req, http.StatusTemporaryRedirect) + resp = session.MakeRequest(t, req, http.StatusSeeOther) // Verify the change req = NewRequest(t, "GET", path.Join(user, repo, "raw/branch", targetBranch, filePath)) diff --git a/integrations/git_test.go b/integrations/git_test.go index d8279f64ee17a..5cebf79e8dd49 100644 --- a/integrations/git_test.go +++ b/integrations/git_test.go @@ -430,7 +430,7 @@ func doProtectBranch(ctx APITestContext, branch, userToWhitelist, unprotectedFil "protected": "on", "unprotected_file_patterns": unprotectedFilePatterns, }) - ctx.Session.MakeRequest(t, req, http.StatusTemporaryRedirect) + ctx.Session.MakeRequest(t, req, http.StatusSeeOther) } else { user, err := user_model.GetUserByName(userToWhitelist) assert.NoError(t, err) @@ -443,7 +443,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.StatusTemporaryRedirect) + ctx.Session.MakeRequest(t, req, http.StatusSeeOther) } // Check if master branch has been locked successfully flashCookie := ctx.Session.GetCookie("macaron_flash") diff --git a/integrations/integration_test.go b/integrations/integration_test.go index 9683115831385..f1429929d88f2 100644 --- a/integrations/integration_test.go +++ b/integrations/integration_test.go @@ -380,7 +380,7 @@ func loginUserWithPassword(t testing.TB, userName, password string) *TestSession "user_name": userName, "password": password, }) - resp = MakeRequest(t, req, http.StatusTemporaryRedirect) + resp = MakeRequest(t, req, http.StatusSeeOther) ch := http.Header{} ch.Add("Cookie", strings.Join(resp.Header()["Set-Cookie"], ";")) @@ -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.StatusTemporaryRedirect) + 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) diff --git a/integrations/issue_test.go b/integrations/issue_test.go index cfa9ec6afc56d..1859e22e3e332 100644 --- a/integrations/issue_test.go +++ b/integrations/issue_test.go @@ -133,7 +133,7 @@ func testNewIssue(t *testing.T, session *TestSession, user, repo, title, content "title": title, "content": content, }) - resp = session.MakeRequest(t, req, http.StatusTemporaryRedirect) + resp = session.MakeRequest(t, req, http.StatusSeeOther) issueURL := test.RedirectURL(resp) req = NewRequest(t, "GET", issueURL) @@ -164,7 +164,7 @@ func testIssueAddComment(t *testing.T, session *TestSession, issueURL, content, "content": content, "status": status, }) - resp = session.MakeRequest(t, req, http.StatusTemporaryRedirect) + resp = session.MakeRequest(t, req, http.StatusSeeOther) req = NewRequest(t, "GET", test.RedirectURL(resp)) resp = session.MakeRequest(t, req, http.StatusOK) @@ -330,16 +330,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.StatusTemporaryRedirect) + 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.StatusTemporaryRedirect) + 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.StatusTemporaryRedirect) + resp = session.MakeRequest(t, req, http.StatusSeeOther) assert.Equal(t, "/"+path.Join("org26", "repo_external_tracker_alpha", "pulls", "1"), test.RedirectURL(resp)) } diff --git a/integrations/links_test.go b/integrations/links_test.go index 08e22f5e9d24e..95a1cfc53322e 100644 --- a/integrations/links_test.go +++ b/integrations/links_test.go @@ -59,7 +59,7 @@ func TestRedirectsNoLogin(t *testing.T) { } for link, redirectLink := range redirects { req := NewRequest(t, "GET", link) - resp := MakeRequest(t, req, http.StatusTemporaryRedirect) + resp := MakeRequest(t, req, http.StatusSeeOther) assert.EqualValues(t, path.Join(setting.AppSubURL, redirectLink), test.RedirectURL(resp)) } } diff --git a/integrations/mirror_push_test.go b/integrations/mirror_push_test.go index d40efd75d133a..c5f45643ec290 100644 --- a/integrations/mirror_push_test.go +++ b/integrations/mirror_push_test.go @@ -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.StatusTemporaryRedirect) + ctx.Session.MakeRequest(t, req, http.StatusSeeOther) flashCookie := ctx.Session.GetCookie("macaron_flash") assert.NotNil(t, flashCookie) @@ -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.StatusTemporaryRedirect) + ctx.Session.MakeRequest(t, req, http.StatusSeeOther) flashCookie := ctx.Session.GetCookie("macaron_flash") assert.NotNil(t, flashCookie) diff --git a/integrations/nonascii_branches_test.go b/integrations/nonascii_branches_test.go index 8f7efcf6aa0ab..5ac9a0a1fdd95 100644 --- a/integrations/nonascii_branches_test.go +++ b/integrations/nonascii_branches_test.go @@ -18,7 +18,7 @@ func testSrcRouteRedirect(t *testing.T, session *TestSession, user, repo, route, // Make request req := NewRequest(t, "GET", path.Join(prefix, route)) - resp := session.MakeRequest(t, req, http.StatusTemporaryRedirect) + resp := session.MakeRequest(t, req, http.StatusSeeOther) // Check Location header location := resp.HeaderMap.Get("Location") @@ -37,7 +37,7 @@ func setDefaultBranch(t *testing.T, session *TestSession, user, repo, branch str "action": "default_branch", "branch": branch, }) - session.MakeRequest(t, req, http.StatusTemporaryRedirect) + session.MakeRequest(t, req, http.StatusSeeOther) } func TestNonasciiBranches(t *testing.T) { diff --git a/integrations/oauth_test.go b/integrations/oauth_test.go index e105bfb395156..678dfbae2d486 100644 --- a/integrations/oauth_test.go +++ b/integrations/oauth_test.go @@ -28,7 +28,7 @@ func TestNoClientID(t *testing.T) { func TestLoginRedirect(t *testing.T) { defer prepareTestEnv(t)() req := NewRequest(t, "GET", "/login/oauth/authorize") - assert.Contains(t, MakeRequest(t, req, http.StatusTemporaryRedirect).Body.String(), "/user/login") + assert.Contains(t, MakeRequest(t, req, http.StatusSeeOther).Body.String(), "/user/login") } func TestShowAuthorize(t *testing.T) { @@ -46,7 +46,7 @@ func TestRedirectWithExistingGrant(t *testing.T) { defer prepareTestEnv(t)() req := NewRequest(t, "GET", defaultAuthorize) ctx := loginUser(t, "user1") - resp := ctx.MakeRequest(t, req, http.StatusTemporaryRedirect) + resp := ctx.MakeRequest(t, req, http.StatusSeeOther) u, err := resp.Result().Location() assert.NoError(t, err) assert.Equal(t, "thestate", u.Query().Get("state")) diff --git a/integrations/privateactivity_test.go b/integrations/privateactivity_test.go index 5f2434bb8096e..f2caa64a222d9 100644 --- a/integrations/privateactivity_test.go +++ b/integrations/privateactivity_test.go @@ -51,7 +51,7 @@ func testPrivateActivityHelperEnablePrivateActivity(t *testing.T) { "language": "en-US", "keep_activity_private": "1", }) - session.MakeRequest(t, req, http.StatusTemporaryRedirect) + session.MakeRequest(t, req, http.StatusSeeOther) } func testPrivateActivityHelperHasVisibleActivitiesInHTMLDoc(htmlDoc *HTMLDoc) bool { diff --git a/integrations/pull_create_test.go b/integrations/pull_create_test.go index 09bdea013fa52..671b5e7551b50 100644 --- a/integrations/pull_create_test.go +++ b/integrations/pull_create_test.go @@ -38,7 +38,7 @@ func testPullCreate(t *testing.T, session *TestSession, user, repo, branch, titl "_csrf": htmlDoc.GetCSRF(), "title": title, }) - resp = session.MakeRequest(t, req, http.StatusTemporaryRedirect) + resp = session.MakeRequest(t, req, http.StatusSeeOther) return resp } @@ -130,7 +130,7 @@ func testDeleteRepository(t *testing.T, session *TestSession, ownerName, repoNam "_csrf": htmlDoc.GetCSRF(), "repo_name": repoName, }) - session.MakeRequest(t, req, http.StatusTemporaryRedirect) + session.MakeRequest(t, req, http.StatusSeeOther) } func TestPullBranchDelete(t *testing.T) { @@ -139,7 +139,7 @@ func TestPullBranchDelete(t *testing.T) { session := loginUser(t, "user1") testRepoFork(t, session, "user2", "repo1", "user1", "repo1") - testCreateBranch(t, session, "user1", "repo1", "branch/master", "master1", http.StatusTemporaryRedirect) + testCreateBranch(t, session, "user1", "repo1", "branch/master", "master1", http.StatusSeeOther) testEditFile(t, session, "user1", "repo1", "master1", "README.md", "Hello, World (Edited)\n") resp := testPullCreate(t, session, "user1", "repo1", "master1", "This is a pull title") diff --git a/integrations/pull_merge_test.go b/integrations/pull_merge_test.go index 1280db765558b..a131d4898deef 100644 --- a/integrations/pull_merge_test.go +++ b/integrations/pull_merge_test.go @@ -42,7 +42,7 @@ func testPullMerge(t *testing.T, session *TestSession, user, repo, pullnum strin "_csrf": htmlDoc.GetCSRF(), "do": string(mergeStyle), }) - resp = session.MakeRequest(t, req, http.StatusTemporaryRedirect) + resp = session.MakeRequest(t, req, http.StatusSeeOther) return resp } diff --git a/integrations/pull_status_test.go b/integrations/pull_status_test.go index 9aead42823faa..07c73ceac6826 100644 --- a/integrations/pull_status_test.go +++ b/integrations/pull_status_test.go @@ -29,7 +29,7 @@ func TestPullCreate_CommitStatus(t *testing.T) { "title": "pull request from status1", }, ) - session.MakeRequest(t, req, http.StatusTemporaryRedirect) + session.MakeRequest(t, req, http.StatusSeeOther) req = NewRequest(t, "GET", "/user1/repo1/pulls") resp := session.MakeRequest(t, req, http.StatusOK) @@ -108,7 +108,7 @@ func TestPullCreate_EmptyChangesWithCommits(t *testing.T) { "title": "pull request from status1", }, ) - session.MakeRequest(t, req, http.StatusTemporaryRedirect) + session.MakeRequest(t, req, http.StatusSeeOther) req = NewRequest(t, "GET", "/user1/repo1/pulls/1") resp := session.MakeRequest(t, req, http.StatusOK) diff --git a/integrations/release_test.go b/integrations/release_test.go index a36a17ea4d9de..88591a05e91a6 100644 --- a/integrations/release_test.go +++ b/integrations/release_test.go @@ -43,7 +43,7 @@ func createNewRelease(t *testing.T, session *TestSession, repoURL, tag, title st } req = NewRequestWithValues(t, "POST", link, postData) - resp = session.MakeRequest(t, req, http.StatusTemporaryRedirect) + resp = session.MakeRequest(t, req, http.StatusSeeOther) test.RedirectURL(resp) // check that redirect URL exists } diff --git a/integrations/rename_branch_test.go b/integrations/rename_branch_test.go index 831c0ebe10888..7760a2d946c41 100644 --- a/integrations/rename_branch_test.go +++ b/integrations/rename_branch_test.go @@ -27,7 +27,7 @@ func TestRenameBranch(t *testing.T) { "to": "main", } req = NewRequestWithValues(t, "POST", "/user2/repo1/settings/rename_branch", postData) - session.MakeRequest(t, req, http.StatusTemporaryRedirect) + session.MakeRequest(t, req, http.StatusSeeOther) // check new branch link req = NewRequestWithValues(t, "GET", "/user2/repo1/src/branch/main/README.md", postData) @@ -35,7 +35,7 @@ func TestRenameBranch(t *testing.T) { // check old branch link req = NewRequestWithValues(t, "GET", "/user2/repo1/src/branch/master/README.md", postData) - resp = session.MakeRequest(t, req, http.StatusTemporaryRedirect) + resp = session.MakeRequest(t, req, http.StatusSeeOther) location := resp.HeaderMap.Get("Location") assert.Equal(t, "/user2/repo1/src/branch/main/README.md", location) diff --git a/integrations/repo_branch_test.go b/integrations/repo_branch_test.go index e7596872a37ea..ade5d673b9c9c 100644 --- a/integrations/repo_branch_test.go +++ b/integrations/repo_branch_test.go @@ -30,7 +30,7 @@ func testCreateBranch(t testing.TB, session *TestSession, user, repo, oldRefSubU "new_branch_name": newBranchName, }) resp := session.MakeRequest(t, req, expectedStatus) - if expectedStatus != http.StatusTemporaryRedirect { + if expectedStatus != http.StatusSeeOther { return "" } return test.RedirectURL(resp) @@ -51,37 +51,37 @@ func testCreateBranches(t *testing.T, giteaURL *url.URL) { { OldRefSubURL: "branch/master", NewBranch: "feature/test1", - ExpectedStatus: http.StatusTemporaryRedirect, + ExpectedStatus: http.StatusSeeOther, FlashMessage: i18n.Tr("en", "repo.branch.create_success", "feature/test1"), }, { OldRefSubURL: "branch/master", NewBranch: "", - ExpectedStatus: http.StatusTemporaryRedirect, + ExpectedStatus: http.StatusSeeOther, FlashMessage: i18n.Tr("en", "form.NewBranchName") + i18n.Tr("en", "form.require_error"), }, { OldRefSubURL: "branch/master", NewBranch: "feature=test1", - ExpectedStatus: http.StatusTemporaryRedirect, + ExpectedStatus: http.StatusSeeOther, FlashMessage: i18n.Tr("en", "repo.branch.create_success", "feature=test1"), }, { OldRefSubURL: "branch/master", NewBranch: strings.Repeat("b", 101), - ExpectedStatus: http.StatusTemporaryRedirect, + ExpectedStatus: http.StatusSeeOther, FlashMessage: i18n.Tr("en", "form.NewBranchName") + i18n.Tr("en", "form.max_size_error", "100"), }, { OldRefSubURL: "branch/master", NewBranch: "master", - ExpectedStatus: http.StatusTemporaryRedirect, + ExpectedStatus: http.StatusSeeOther, FlashMessage: i18n.Tr("en", "repo.branch.branch_already_exists", "master"), }, { OldRefSubURL: "branch/master", NewBranch: "master/test", - ExpectedStatus: http.StatusTemporaryRedirect, + ExpectedStatus: http.StatusSeeOther, FlashMessage: i18n.Tr("en", "repo.branch.branch_name_conflict", "master/test", "master"), }, { @@ -92,21 +92,21 @@ func testCreateBranches(t *testing.T, giteaURL *url.URL) { { OldRefSubURL: "commit/65f1bf27bc3bf70f64657658635e66094edbcb4d", NewBranch: "feature/test3", - ExpectedStatus: http.StatusTemporaryRedirect, + ExpectedStatus: http.StatusSeeOther, FlashMessage: i18n.Tr("en", "repo.branch.create_success", "feature/test3"), }, { OldRefSubURL: "branch/master", NewBranch: "v1.0.0", CreateRelease: "v1.0.0", - ExpectedStatus: http.StatusTemporaryRedirect, + ExpectedStatus: http.StatusSeeOther, FlashMessage: i18n.Tr("en", "repo.branch.tag_collision", "v1.0.0"), }, { OldRefSubURL: "tag/v1.0.0", NewBranch: "feature/test4", CreateRelease: "v1.0.1", - ExpectedStatus: http.StatusTemporaryRedirect, + ExpectedStatus: http.StatusSeeOther, FlashMessage: i18n.Tr("en", "repo.branch.create_success", "feature/test4"), }, } @@ -116,7 +116,7 @@ func testCreateBranches(t *testing.T, giteaURL *url.URL) { createNewRelease(t, session, "/user2/repo1", test.CreateRelease, test.CreateRelease, false, false) } redirectURL := testCreateBranch(t, session, "user2", "repo1", test.OldRefSubURL, test.NewBranch, test.ExpectedStatus) - if test.ExpectedStatus == http.StatusTemporaryRedirect { + if test.ExpectedStatus == http.StatusSeeOther { req := NewRequest(t, "GET", redirectURL) resp := session.MakeRequest(t, req, http.StatusOK) htmlDoc := NewHTMLParser(t, resp.Body) @@ -135,7 +135,7 @@ func TestCreateBranchInvalidCSRF(t *testing.T) { "_csrf": "fake_csrf", "new_branch_name": "test", }) - resp := session.MakeRequest(t, req, http.StatusTemporaryRedirect) + resp := session.MakeRequest(t, req, http.StatusSeeOther) loc := resp.Header().Get("Location") assert.Equal(t, setting.AppSubURL+"/", loc) resp = session.MakeRequest(t, NewRequest(t, "GET", loc), http.StatusOK) diff --git a/integrations/repo_fork_test.go b/integrations/repo_fork_test.go index 12c2c4933bff8..d701850f140e2 100644 --- a/integrations/repo_fork_test.go +++ b/integrations/repo_fork_test.go @@ -45,7 +45,7 @@ func testRepoFork(t *testing.T, session *TestSession, ownerName, repoName, forkO "uid": fmt.Sprintf("%d", forkOwner.ID), "repo_name": forkRepoName, }) - resp = session.MakeRequest(t, req, http.StatusTemporaryRedirect) + resp = session.MakeRequest(t, req, http.StatusSeeOther) // Step4: check the existence of the forked repo req = NewRequestf(t, "GET", "/%s/%s", forkOwnerName, forkRepoName) diff --git a/integrations/repo_generate_test.go b/integrations/repo_generate_test.go index b2fb16c929147..4fbbb56c50d93 100644 --- a/integrations/repo_generate_test.go +++ b/integrations/repo_generate_test.go @@ -46,7 +46,7 @@ func testRepoGenerate(t *testing.T, session *TestSession, templateOwnerName, tem "repo_name": generateRepoName, "git_content": "true", }) - resp = session.MakeRequest(t, req, http.StatusTemporaryRedirect) + resp = session.MakeRequest(t, req, http.StatusSeeOther) // Step4: check the existence of the generated repo req = NewRequestf(t, "GET", "/%s/%s", generateOwnerName, generateRepoName) diff --git a/integrations/repo_migrate_test.go b/integrations/repo_migrate_test.go index d571d4255f0db..4e6923dd6f57e 100644 --- a/integrations/repo_migrate_test.go +++ b/integrations/repo_migrate_test.go @@ -33,7 +33,7 @@ func testRepoMigrate(t testing.TB, session *TestSession, cloneAddr, repoName str "repo_name": repoName, "service": fmt.Sprintf("%d", structs.PlainGitService), }) - resp = session.MakeRequest(t, req, http.StatusTemporaryRedirect) + resp = session.MakeRequest(t, req, http.StatusSeeOther) return resp } diff --git a/integrations/setting_test.go b/integrations/setting_test.go index 58610666b89c3..275ebff13fe9c 100644 --- a/integrations/setting_test.go +++ b/integrations/setting_test.go @@ -91,17 +91,17 @@ func TestSettingLandingPage(t *testing.T) { setting.LandingPageURL = setting.LandingPageExplore req = NewRequest(t, "GET", "/") - resp := MakeRequest(t, req, http.StatusTemporaryRedirect) + resp := MakeRequest(t, req, http.StatusSeeOther) assert.Equal(t, "/explore", resp.Header().Get("Location")) setting.LandingPageURL = setting.LandingPageOrganizations req = NewRequest(t, "GET", "/") - resp = MakeRequest(t, req, http.StatusTemporaryRedirect) + resp = MakeRequest(t, req, http.StatusSeeOther) assert.Equal(t, "/explore/organizations", resp.Header().Get("Location")) setting.LandingPageURL = setting.LandingPageLogin req = NewRequest(t, "GET", "/") - resp = MakeRequest(t, req, http.StatusTemporaryRedirect) + resp = MakeRequest(t, req, http.StatusSeeOther) assert.Equal(t, "/user/login", resp.Header().Get("Location")) setting.LandingPageURL = landingPage diff --git a/integrations/signout_test.go b/integrations/signout_test.go index 0c2c4a0ec8ff9..8ef97e89c5283 100644 --- a/integrations/signout_test.go +++ b/integrations/signout_test.go @@ -15,7 +15,7 @@ func TestSignOut(t *testing.T) { session := loginUser(t, "user2") req := NewRequest(t, "POST", "/user/logout") - session.MakeRequest(t, req, http.StatusTemporaryRedirect) + session.MakeRequest(t, req, http.StatusSeeOther) // try to view a private repo, should fail req = NewRequest(t, "GET", "/user2/repo2") diff --git a/integrations/signup_test.go b/integrations/signup_test.go index feb494c913901..87dea2fbe714e 100644 --- a/integrations/signup_test.go +++ b/integrations/signup_test.go @@ -29,7 +29,7 @@ func TestSignup(t *testing.T) { "password": "examplePassword!1", "retype": "examplePassword!1", }) - MakeRequest(t, req, http.StatusTemporaryRedirect) + MakeRequest(t, req, http.StatusSeeOther) // should be able to view new user's page req = NewRequest(t, "GET", "/exampleUser") @@ -48,7 +48,7 @@ func TestSignupAsRestricted(t *testing.T) { "password": "examplePassword!1", "retype": "examplePassword!1", }) - MakeRequest(t, req, http.StatusTemporaryRedirect) + MakeRequest(t, req, http.StatusSeeOther) // should be able to view new user's page req = NewRequest(t, "GET", "/restrictedUser") @@ -71,7 +71,7 @@ func TestSignupEmail(t *testing.T) { {"exampleUser@example.com\r\n", http.StatusOK, i18n.Tr("en", "form.email_invalid", nil)}, {"exampleUser@example.com\r", http.StatusOK, i18n.Tr("en", "form.email_invalid", nil)}, {"exampleUser@example.com\n", http.StatusOK, i18n.Tr("en", "form.email_invalid", nil)}, - {"exampleUser@example.com", http.StatusTemporaryRedirect, ""}, + {"exampleUser@example.com", http.StatusSeeOther, ""}, } for i, test := range tests { diff --git a/integrations/user_avatar_test.go b/integrations/user_avatar_test.go index 0ce63adb26793..77b02dc73dda4 100644 --- a/integrations/user_avatar_test.go +++ b/integrations/user_avatar_test.go @@ -70,7 +70,7 @@ func TestUserAvatar(t *testing.T) { req.Header.Add("X-Csrf-Token", csrf) req.Header.Add("Content-Type", writer.FormDataContentType()) - session.MakeRequest(t, req, http.StatusTemporaryRedirect) + session.MakeRequest(t, req, http.StatusSeeOther) user2 = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) // owner of the repo3, is an org diff --git a/integrations/user_test.go b/integrations/user_test.go index bd2c7548228e0..03995139b2f5d 100644 --- a/integrations/user_test.go +++ b/integrations/user_test.go @@ -33,7 +33,7 @@ func TestRenameUsername(t *testing.T) { "email": "user2@example.com", "language": "en-US", }) - session.MakeRequest(t, req, http.StatusTemporaryRedirect) + session.MakeRequest(t, req, http.StatusSeeOther) unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "newUsername"}) unittest.AssertNotExistsBean(t, &user_model.User{Name: "user2"}) @@ -103,7 +103,7 @@ func TestRenameReservedUsername(t *testing.T) { "email": "user2@example.com", "language": "en-US", }) - resp := session.MakeRequest(t, req, http.StatusTemporaryRedirect) + resp := session.MakeRequest(t, req, http.StatusSeeOther) req = NewRequest(t, "GET", test.RedirectURL(resp)) resp = session.MakeRequest(t, req, http.StatusOK) diff --git a/integrations/xss_test.go b/integrations/xss_test.go index f09be6e57d2eb..1ce25e1bf5c3a 100644 --- a/integrations/xss_test.go +++ b/integrations/xss_test.go @@ -27,7 +27,7 @@ func TestXSSUserFullName(t *testing.T) { "email": user.Email, "language": "en-US", }) - session.MakeRequest(t, req, http.StatusTemporaryRedirect) + session.MakeRequest(t, req, http.StatusSeeOther) req = NewRequestf(t, "GET", "/%s", user.Name) resp := session.MakeRequest(t, req, http.StatusOK) diff --git a/routers/web/repo/issue_label_test.go b/routers/web/repo/issue_label_test.go index 4dda9a7ba42d4..5d7a29ee936d5 100644 --- a/routers/web/repo/issue_label_test.go +++ b/routers/web/repo/issue_label_test.go @@ -36,7 +36,7 @@ func TestInitializeLabels(t *testing.T) { test.LoadRepo(t, ctx, 2) web.SetForm(ctx, &forms.InitializeLabelsForm{TemplateName: "Default"}) InitializeLabels(ctx) - assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) unittest.AssertExistsAndLoadBean(t, &models.Label{ RepoID: 2, Name: "enhancement", @@ -82,7 +82,7 @@ func TestNewLabel(t *testing.T) { Color: "#abcdef", }) NewLabel(ctx) - assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) unittest.AssertExistsAndLoadBean(t, &models.Label{ Name: "newlabel", Color: "#abcdef", @@ -101,7 +101,7 @@ func TestUpdateLabel(t *testing.T) { Color: "#abcdef", }) UpdateLabel(ctx) - assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) unittest.AssertExistsAndLoadBean(t, &models.Label{ ID: 2, Name: "newnameforlabel", diff --git a/routers/web/repo/settings_test.go b/routers/web/repo/settings_test.go index 621f7857399fa..c12e26f17bb27 100644 --- a/routers/web/repo/settings_test.go +++ b/routers/web/repo/settings_test.go @@ -60,7 +60,7 @@ func TestAddReadOnlyDeployKey(t *testing.T) { } web.SetForm(ctx, &addKeyForm) DeployKeysPost(ctx) - assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) unittest.AssertExistsAndLoadBean(t, &asymkey_model.DeployKey{ Name: addKeyForm.Title, @@ -90,7 +90,7 @@ func TestAddReadWriteOnlyDeployKey(t *testing.T) { } web.SetForm(ctx, &addKeyForm) DeployKeysPost(ctx) - assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) unittest.AssertExistsAndLoadBean(t, &asymkey_model.DeployKey{ Name: addKeyForm.Title, @@ -128,7 +128,7 @@ func TestCollaborationPost(t *testing.T) { CollaborationPost(ctx) - assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) exists, err := models.IsCollaborator(re.ID, 4) assert.NoError(t, err) @@ -155,7 +155,7 @@ func TestCollaborationPost_InactiveUser(t *testing.T) { CollaborationPost(ctx) - assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) assert.NotEmpty(t, ctx.Flash.ErrorMsg) } @@ -188,7 +188,7 @@ func TestCollaborationPost_AddCollaboratorTwice(t *testing.T) { CollaborationPost(ctx) - assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) exists, err := models.IsCollaborator(re.ID, 4) assert.NoError(t, err) @@ -197,7 +197,7 @@ func TestCollaborationPost_AddCollaboratorTwice(t *testing.T) { // Try adding the same collaborator again CollaborationPost(ctx) - assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) assert.NotEmpty(t, ctx.Flash.ErrorMsg) } @@ -220,7 +220,7 @@ func TestCollaborationPost_NonExistentUser(t *testing.T) { CollaborationPost(ctx) - assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) assert.NotEmpty(t, ctx.Flash.ErrorMsg) } @@ -260,7 +260,7 @@ func TestAddTeamPost(t *testing.T) { AddTeamPost(ctx) assert.True(t, team.HasRepository(re.ID)) - assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) assert.Empty(t, ctx.Flash.ErrorMsg) } @@ -300,7 +300,7 @@ func TestAddTeamPost_NotAllowed(t *testing.T) { AddTeamPost(ctx) assert.False(t, team.HasRepository(re.ID)) - assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) assert.NotEmpty(t, ctx.Flash.ErrorMsg) } @@ -342,7 +342,7 @@ func TestAddTeamPost_AddTeamTwice(t *testing.T) { AddTeamPost(ctx) assert.True(t, team.HasRepository(re.ID)) - assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) assert.NotEmpty(t, ctx.Flash.ErrorMsg) } @@ -375,7 +375,7 @@ func TestAddTeamPost_NonExistentTeam(t *testing.T) { ctx.Repo = repo AddTeamPost(ctx) - assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) assert.NotEmpty(t, ctx.Flash.ErrorMsg) } diff --git a/routers/web/repo/wiki_test.go b/routers/web/repo/wiki_test.go index 7505d45f46bbe..c433d82815c8c 100644 --- a/routers/web/repo/wiki_test.go +++ b/routers/web/repo/wiki_test.go @@ -122,7 +122,7 @@ func TestNewWikiPost(t *testing.T) { Message: message, }) NewWikiPost(ctx) - assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) assertWikiExists(t, ctx.Repo.Repository, title) assert.Equal(t, wikiContent(t, ctx.Repo.Repository, title), content) } @@ -174,7 +174,7 @@ func TestEditWikiPost(t *testing.T) { Message: message, }) EditWikiPost(ctx) - assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) assertWikiExists(t, ctx.Repo.Repository, title) assert.Equal(t, wikiContent(t, ctx.Repo.Repository, title), content) if title != "Home" { diff --git a/routers/web/user/setting/account_test.go b/routers/web/user/setting/account_test.go index 394bf79b965c4..c35a71133b448 100644 --- a/routers/web/user/setting/account_test.go +++ b/routers/web/user/setting/account_test.go @@ -94,6 +94,6 @@ func TestChangePassword(t *testing.T) { AccountPost(ctx) assert.Contains(t, ctx.Flash.ErrorMsg, req.Message) - assert.EqualValues(t, http.StatusTemporaryRedirect, ctx.Resp.Status()) + assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status()) } } From cdf0611226fc769a8d6061ab3e4ea8d58d5d60f7 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Wed, 29 Dec 2021 23:29:23 +0000 Subject: [PATCH 10/10] swagger --- templates/swagger/v1_json.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index fe62c46d29dd6..59ef84dc6c645 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -1474,7 +1474,7 @@ "204": { "description": "user is a member" }, - "307": { + "303": { "description": "redirection to /orgs/{org}/public_members/{username}" }, "404": {