Skip to content

Commit 4370499

Browse files
committed
fix incorrect tests
1 parent 6b3992b commit 4370499

File tree

3 files changed

+6
-25
lines changed

3 files changed

+6
-25
lines changed

routers/web/auth/auth.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,8 @@ func handleAccountActivation(ctx *context.Context, user *user_model.User) {
804804
return
805805
}
806806

807+
ctx.Csrf.PrepareForSessionUser(ctx)
808+
807809
if err := resetLocale(ctx, user); err != nil {
808810
ctx.ServerError("resetLocale", err)
809811
return

tests/integration/org_team_invite_test.go

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -262,46 +262,27 @@ func TestOrgTeamEmailInviteRedirectsNewUserWithActivation(t *testing.T) {
262262
assert.Len(t, invites, 1)
263263

264264
// accept the invite
265+
session = emptyTestSession(t)
266+
265267
inviteURL := fmt.Sprintf("/org/invite/%s", invites[0].Token)
266268
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)
269+
session.MakeRequest(t, req, http.StatusOK)
270270
req = NewRequestWithValues(t, "POST", "/user/sign_up", map[string]string{
271-
"_csrf": doc.GetCSRF(),
272271
"user_name": "doesnotexist",
273272
"email": "[email protected]",
274273
"password": "examplePassword!1",
275274
"retype": "examplePassword!1",
276275
})
277-
for _, c := range inviteResp.Result().Cookies() {
278-
req.AddCookie(c)
279-
}
280-
281-
resp = MakeRequest(t, req, http.StatusOK)
276+
resp = session.MakeRequest(t, req, http.StatusOK)
282277

283278
user, err := user_model.GetUserByName(db.DefaultContext, "doesnotexist")
284279
assert.NoError(t, err)
285280

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-
295281
activateURL := fmt.Sprintf("/user/activate?code=%s", user.GenerateEmailActivateCode("[email protected]"))
296282
req = NewRequestWithValues(t, "POST", activateURL, map[string]string{
297283
"password": "examplePassword!1",
298284
})
299285

300-
// use the cookies set by the signup request
301-
for _, c := range inviteResp.Result().Cookies() {
302-
req.AddCookie(c)
303-
}
304-
305286
resp = session.MakeRequest(t, req, http.StatusSeeOther)
306287
// should be redirected to accept the invite
307288
assert.Equal(t, inviteURL, test.RedirectURL(resp))

tests/integration/signin_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
func testLoginFailed(t *testing.T, username, password, message string) {
2222
session := emptyTestSession(t)
2323
req := NewRequestWithValues(t, "POST", "/user/login", map[string]string{
24-
"_csrf": GetUserCSRFToken(t, session),
2524
"user_name": username,
2625
"password": password,
2726
})
@@ -68,7 +67,6 @@ func TestSigninWithRememberMe(t *testing.T) {
6867

6968
session := emptyTestSession(t)
7069
req := NewRequestWithValues(t, "POST", "/user/login", map[string]string{
71-
"_csrf": GetUserCSRFToken(t, session),
7270
"user_name": user.Name,
7371
"password": userPassword,
7472
"remember": "on",

0 commit comments

Comments
 (0)