@@ -233,17 +233,13 @@ func TestOrgTeamEmailInviteRedirectsNewUserWithActivation(t *testing.T) {
233233 }
234234
235235 // enable email confirmation temporarily
236- defer func (prevVal bool ) {
237- setting .Service .RegisterEmailConfirm = prevVal
238- }(setting .Service .RegisterEmailConfirm )
239- setting .Service .RegisterEmailConfirm = true
240-
236+ defer test .MockVariableValue (& setting .Service .RegisterEmailConfirm , true )()
241237 defer tests .PrepareTestEnv (t )()
242238
243239 org := unittest .AssertExistsAndLoadBean (t , & organization.Organization {ID : 3 })
244240 team := unittest .AssertExistsAndLoadBean (t , & organization.Team {ID : 2 })
245241
246- // create the invite
242+ // user1: create the invite
247243 session := loginUser (t , "user1" )
248244
249245 teamURL := fmt .Sprintf ("/org/%s/teams/%s" , org .Name , team .Name )
@@ -261,47 +257,28 @@ func TestOrgTeamEmailInviteRedirectsNewUserWithActivation(t *testing.T) {
261257 assert .NoError (t , err )
262258 assert .Len (t , invites , 1 )
263259
264- // accept the invite
260+ // new user: accept the invite
261+ session = emptyTestSession (t )
262+
265263 inviteURL := fmt .Sprintf ("/org/invite/%s" , invites [0 ].Token )
266264 req = NewRequest (t , "GET" , fmt .Sprintf ("/user/sign_up?redirect_to=%s" , url .QueryEscape (inviteURL )))
267- inviteResp := MakeRequest (t , req , http .StatusOK )
268-
269- doc := NewHTMLParser (t , resp .Body )
265+ session .MakeRequest (t , req , http .StatusOK )
270266 req = NewRequestWithValues (t , "POST" , "/user/sign_up" , map [string ]string {
271- "_csrf" : doc .GetCSRF (),
272267 "user_name" : "doesnotexist" ,
273268274269 "password" : "examplePassword!1" ,
275270 "retype" : "examplePassword!1" ,
276271 })
277- for _ , c := range inviteResp .Result ().Cookies () {
278- req .AddCookie (c )
279- }
280-
281- resp = MakeRequest (t , req , http .StatusOK )
272+ session .MakeRequest (t , req , http .StatusOK )
282273
283274 user , err := user_model .GetUserByName (db .DefaultContext , "doesnotexist" )
284275 assert .NoError (t , err )
285276
286- ch := http.Header {}
287- ch .Add ("Cookie" , strings .Join (resp .Header ()["Set-Cookie" ], ";" ))
288- cr := http.Request {Header : ch }
289-
290- session = emptyTestSession (t )
291- baseURL , err := url .Parse (setting .AppURL )
292- assert .NoError (t , err )
293- session .jar .SetCookies (baseURL , cr .Cookies ())
294-
295277 activateURL := fmt .
Sprintf (
"/user/activate?code=%s" ,
user .
GenerateEmailActivateCode (
"[email protected] " ))
296278 req = NewRequestWithValues (t , "POST" , activateURL , map [string ]string {
297279 "password" : "examplePassword!1" ,
298280 })
299281
300- // use the cookies set by the signup request
301- for _ , c := range inviteResp .Result ().Cookies () {
302- req .AddCookie (c )
303- }
304-
305282 resp = session .MakeRequest (t , req , http .StatusSeeOther )
306283 // should be redirected to accept the invite
307284 assert .Equal (t , inviteURL , test .RedirectURL (resp ))
0 commit comments