@@ -15,8 +15,11 @@ import (
15
15
"code.gitea.io/gitea/modules/setting"
16
16
"code.gitea.io/gitea/modules/test"
17
17
"code.gitea.io/gitea/modules/translation"
18
+ "code.gitea.io/gitea/modules/web"
19
+ "code.gitea.io/gitea/services/context"
18
20
"code.gitea.io/gitea/tests"
19
21
22
+ "github.com/markbates/goth"
20
23
"github.com/stretchr/testify/assert"
21
24
"github.com/stretchr/testify/require"
22
25
)
@@ -98,6 +101,11 @@ func TestSigninWithRememberMe(t *testing.T) {
98
101
func TestEnablePasswordSignInForm (t * testing.T ) {
99
102
defer tests .PrepareTestEnv (t )()
100
103
104
+ mockLinkAccount := func (ctx * context.Context ) {
105
+ gothUser := goth.User {Email : "invalid-email" , Name : "." }
106
+ _ = ctx .Session .Set ("linkAccountGothUser" , gothUser )
107
+ }
108
+
101
109
t .Run ("EnablePasswordSignInForm=false" , func (t * testing.T ) {
102
110
defer tests .PrintCurrentTest (t )()
103
111
defer test .MockVariableValue (& setting .Service .EnablePasswordSignInForm , false )()
@@ -108,6 +116,12 @@ func TestEnablePasswordSignInForm(t *testing.T) {
108
116
109
117
req = NewRequest (t , "POST" , "/user/login" )
110
118
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 )
111
125
})
112
126
113
127
t .Run ("EnablePasswordSignInForm=true" , func (t * testing.T ) {
@@ -120,5 +134,11 @@ func TestEnablePasswordSignInForm(t *testing.T) {
120
134
121
135
req = NewRequest (t , "POST" , "/user/login" )
122
136
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 )
123
143
})
124
144
}
0 commit comments