Skip to content

Commit f45a04c

Browse files
committed
Attempt to fix TestExportUserGPGKeys
There are repeated failures with this test which appear related to failures in getTokenForLoggedInUser. It is difficult to further evaluate the cause of these failures as we do not get given further information. This PR will attempt to fix this. First it adds some extra logging and it uses the csrf cookie primarily for the csrf value. If the problem does not occur again with those changes we could merge, assume that it is fixed and hope that if it occurs in future the additional logging will be helpful. If not I will add more changes in attempt to fix. Fix go-gitea#22105 Signed-off-by: Andrew Thornton <[email protected]>
1 parent f3370ee commit f45a04c

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

tests/integration/integration_test.go

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,18 +264,44 @@ var tokenCounter int64
264264

265265
func getTokenForLoggedInUser(t testing.TB, session *TestSession) string {
266266
t.Helper()
267+
var token string
267268
req := NewRequest(t, "GET", "/user/settings/applications")
268269
resp := session.MakeRequest(t, req, http.StatusOK)
269-
doc := NewHTMLParser(t, resp.Body)
270+
var csrf string
271+
for _, cookie := range resp.Result().Cookies() {
272+
if cookie.Name != "_csrf" {
273+
continue
274+
}
275+
csrf = cookie.Value
276+
break
277+
}
278+
if csrf == "" {
279+
doc := NewHTMLParser(t, resp.Body)
280+
csrf = doc.GetCSRF()
281+
}
282+
assert.NotEmpty(t, csrf)
270283
req = NewRequestWithValues(t, "POST", "/user/settings/applications", map[string]string{
271-
"_csrf": doc.GetCSRF(),
284+
"_csrf": csrf,
272285
"name": fmt.Sprintf("api-testing-token-%d", atomic.AddInt64(&tokenCounter, 1)),
273286
})
274-
session.MakeRequest(t, req, http.StatusSeeOther)
287+
resp = session.MakeRequest(t, req, http.StatusSeeOther)
288+
289+
if !assert.Equal(t, resp.Result().Header["Location"], []string{"/user/settings/applications"}) {
290+
for _, cookie := range resp.Result().Cookies() {
291+
if cookie.Name != "macaron_flash" {
292+
continue
293+
}
294+
flash, _ := url.ParseQuery(cookie.Value)
295+
for key, value := range flash {
296+
t.Logf("Flash %q: %q", key, value)
297+
}
298+
}
299+
}
300+
275301
req = NewRequest(t, "GET", "/user/settings/applications")
276302
resp = session.MakeRequest(t, req, http.StatusOK)
277303
htmlDoc := NewHTMLParser(t, resp.Body)
278-
token := htmlDoc.doc.Find(".ui.info p").Text()
304+
token = htmlDoc.doc.Find(".ui.info p").Text()
279305
assert.NotEmpty(t, token)
280306
return token
281307
}

0 commit comments

Comments
 (0)