Skip to content

Commit dd3a94c

Browse files
committed
add tests
1 parent f3f60bc commit dd3a94c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/integration/signin_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ import (
1515
"code.gitea.io/gitea/modules/setting"
1616
"code.gitea.io/gitea/modules/test"
1717
"code.gitea.io/gitea/modules/translation"
18+
"code.gitea.io/gitea/modules/web"
19+
"code.gitea.io/gitea/services/context"
1820
"code.gitea.io/gitea/tests"
1921

22+
"github.com/markbates/goth"
2023
"github.com/stretchr/testify/assert"
2124
"github.com/stretchr/testify/require"
2225
)
@@ -98,6 +101,11 @@ func TestSigninWithRememberMe(t *testing.T) {
98101
func TestEnablePasswordSignInForm(t *testing.T) {
99102
defer tests.PrepareTestEnv(t)()
100103

104+
mockLinkAccount := func(ctx *context.Context) {
105+
gothUser := goth.User{Email: "invalid-email", Name: "."}
106+
_ = ctx.Session.Set("linkAccountGothUser", gothUser)
107+
}
108+
101109
t.Run("EnablePasswordSignInForm=false", func(t *testing.T) {
102110
defer tests.PrintCurrentTest(t)()
103111
defer test.MockVariableValue(&setting.Service.EnablePasswordSignInForm, false)()
@@ -108,6 +116,12 @@ func TestEnablePasswordSignInForm(t *testing.T) {
108116

109117
req = NewRequest(t, "POST", "/user/login")
110118
MakeRequest(t, req, http.StatusForbidden)
119+
120+
req = NewRequest(t, "GET", "/user/link_account")
121+
defer web.RouteMockReset()
122+
web.RouteMock(web.MockAfterMiddlewares, mockLinkAccount)
123+
resp = MakeRequest(t, req, http.StatusOK)
124+
NewHTMLParser(t, resp.Body).AssertElement(t, "form[action='/user/link_account_signin']", false)
111125
})
112126

113127
t.Run("EnablePasswordSignInForm=true", func(t *testing.T) {
@@ -120,5 +134,11 @@ func TestEnablePasswordSignInForm(t *testing.T) {
120134

121135
req = NewRequest(t, "POST", "/user/login")
122136
MakeRequest(t, req, http.StatusOK)
137+
138+
req = NewRequest(t, "GET", "/user/link_account")
139+
defer web.RouteMockReset()
140+
web.RouteMock(web.MockAfterMiddlewares, mockLinkAccount)
141+
resp = MakeRequest(t, req, http.StatusOK)
142+
NewHTMLParser(t, resp.Body).AssertElement(t, "form[action='/user/link_account_signin']", true)
123143
})
124144
}

0 commit comments

Comments
 (0)