diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-04-14 03:45:33 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-13 15:45:33 -0400 |
commit | 5b9557aef59b190c55de9ea218bf51152bc04786 (patch) | |
tree | d77004c983875886a00acd1561a74b8c3d5ce682 /tests | |
parent | b7221bec34fd49495234a18c26e4f5d81483e102 (diff) | |
download | gitea-5b9557aef59b190c55de9ea218bf51152bc04786.tar.gz gitea-5b9557aef59b190c55de9ea218bf51152bc04786.zip |
Refactor cookie (#24107)
Close #24062
At the beginning, I just wanted to fix the warning mentioned by #24062
But, the cookie code really doesn't look good to me, so clean up them.
Complete the TODO on `SetCookie`:
> TODO: Copied from gitea.com/macaron/macaron and should be improved
after macaron removed.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/integration/editor_test.go | 5 | ||||
-rw-r--r-- | tests/integration/git_test.go | 3 | ||||
-rw-r--r-- | tests/integration/integration_test.go | 3 | ||||
-rw-r--r-- | tests/integration/mirror_push_test.go | 5 |
4 files changed, 10 insertions, 6 deletions
diff --git a/tests/integration/editor_test.go b/tests/integration/editor_test.go index 791506d8f7..495290ed56 100644 --- a/tests/integration/editor_test.go +++ b/tests/integration/editor_test.go @@ -10,6 +10,7 @@ import ( "path" "testing" + gitea_context "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/json" "github.com/stretchr/testify/assert" @@ -52,7 +53,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) { }) session.MakeRequest(t, req, http.StatusSeeOther) // Check if master branch has been locked successfully - flashCookie := session.GetCookie("macaron_flash") + flashCookie := session.GetCookie(gitea_context.CookieNameFlash) assert.NotNil(t, flashCookie) assert.EqualValues(t, "success%3DBranch%2Bprotection%2Bfor%2Brule%2B%2527master%2527%2Bhas%2Bbeen%2Bupdated.", flashCookie.Value) @@ -92,7 +93,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) { assert.EqualValues(t, "/user2/repo1/settings/branches", res["redirect"]) // Check if master branch has been locked successfully - flashCookie = session.GetCookie("macaron_flash") + flashCookie = session.GetCookie(gitea_context.CookieNameFlash) assert.NotNil(t, flashCookie) assert.EqualValues(t, "error%3DRemoving%2Bbranch%2Bprotection%2Brule%2B%25271%2527%2Bfailed.", flashCookie.Value) }) diff --git a/tests/integration/git_test.go b/tests/integration/git_test.go index d21f3994a1..95c6d83e54 100644 --- a/tests/integration/git_test.go +++ b/tests/integration/git_test.go @@ -23,6 +23,7 @@ import ( repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" + gitea_context "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/lfs" "code.gitea.io/gitea/modules/setting" @@ -436,7 +437,7 @@ func doProtectBranch(ctx APITestContext, branch, userToWhitelist, unprotectedFil ctx.Session.MakeRequest(t, req, http.StatusSeeOther) } // Check if master branch has been locked successfully - flashCookie := ctx.Session.GetCookie("macaron_flash") + flashCookie := ctx.Session.GetCookie(gitea_context.CookieNameFlash) assert.NotNil(t, flashCookie) assert.EqualValues(t, "success%3DBranch%2Bprotection%2Bfor%2Brule%2B%2527"+url.QueryEscape(branch)+"%2527%2Bhas%2Bbeen%2Bupdated.", flashCookie.Value) } diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index 716f6d44ab..965bae576c 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -23,6 +23,7 @@ import ( "code.gitea.io/gitea/models/auth" "code.gitea.io/gitea/models/unittest" + gitea_context "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" @@ -290,7 +291,7 @@ func getTokenForLoggedInUser(t testing.TB, session *TestSession, scopes ...auth. // Log the flash values on failure if !assert.Equal(t, resp.Result().Header["Location"], []string{"/user/settings/applications"}) { for _, cookie := range resp.Result().Cookies() { - if cookie.Name != "macaron_flash" { + if cookie.Name != gitea_context.CookieNameFlash { continue } flash, _ := url.ParseQuery(cookie.Value) diff --git a/tests/integration/mirror_push_test.go b/tests/integration/mirror_push_test.go index b2ec6c0932..9abae63b0a 100644 --- a/tests/integration/mirror_push_test.go +++ b/tests/integration/mirror_push_test.go @@ -15,6 +15,7 @@ import ( repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" + gitea_context "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" @@ -91,7 +92,7 @@ func doCreatePushMirror(ctx APITestContext, address, username, password string) }) ctx.Session.MakeRequest(t, req, http.StatusSeeOther) - flashCookie := ctx.Session.GetCookie("macaron_flash") + flashCookie := ctx.Session.GetCookie(gitea_context.CookieNameFlash) assert.NotNil(t, flashCookie) assert.Contains(t, flashCookie.Value, "success") } @@ -112,7 +113,7 @@ func doRemovePushMirror(ctx APITestContext, address, username, password string, }) ctx.Session.MakeRequest(t, req, http.StatusSeeOther) - flashCookie := ctx.Session.GetCookie("macaron_flash") + flashCookie := ctx.Session.GetCookie(gitea_context.CookieNameFlash) assert.NotNil(t, flashCookie) assert.Contains(t, flashCookie.Value, "success") } |