mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Fix Account linking page (#33325)
Fix password form missing whilst linking account even with `ENABLE_PASSWORD_SIGNIN_FORM = true`. Remove redundant empty box in account linking sign up page when `LinkAccountMode` is true. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -15,8 +15,11 @@ import (
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
"code.gitea.io/gitea/modules/translation"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/services/context"
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
"github.com/markbates/goth"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -98,6 +101,11 @@ func TestSigninWithRememberMe(t *testing.T) {
|
||||
func TestEnablePasswordSignInForm(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
mockLinkAccount := func(ctx *context.Context) {
|
||||
gothUser := goth.User{Email: "invalid-email", Name: "."}
|
||||
_ = ctx.Session.Set("linkAccountGothUser", gothUser)
|
||||
}
|
||||
|
||||
t.Run("EnablePasswordSignInForm=false", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
defer test.MockVariableValue(&setting.Service.EnablePasswordSignInForm, false)()
|
||||
@@ -108,6 +116,12 @@ func TestEnablePasswordSignInForm(t *testing.T) {
|
||||
|
||||
req = NewRequest(t, "POST", "/user/login")
|
||||
MakeRequest(t, req, http.StatusForbidden)
|
||||
|
||||
req = NewRequest(t, "GET", "/user/link_account")
|
||||
defer web.RouteMockReset()
|
||||
web.RouteMock(web.MockAfterMiddlewares, mockLinkAccount)
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
NewHTMLParser(t, resp.Body).AssertElement(t, "form[action='/user/link_account_signin']", false)
|
||||
})
|
||||
|
||||
t.Run("EnablePasswordSignInForm=true", func(t *testing.T) {
|
||||
@@ -120,5 +134,11 @@ func TestEnablePasswordSignInForm(t *testing.T) {
|
||||
|
||||
req = NewRequest(t, "POST", "/user/login")
|
||||
MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
req = NewRequest(t, "GET", "/user/link_account")
|
||||
defer web.RouteMockReset()
|
||||
web.RouteMock(web.MockAfterMiddlewares, mockLinkAccount)
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
NewHTMLParser(t, resp.Body).AssertElement(t, "form[action='/user/link_account_signin']", true)
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user