Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed Jan 19, 2025
1 parent f3f60bc commit dd3a94c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/integration/signin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)()
Expand All @@ -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) {
Expand All @@ -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)
})
}

0 comments on commit dd3a94c

Please sign in to comment.