Skip to content

Commit fe6608f

Browse files
zeripathlunnyjolheisertechknowlogickdelvh
authored
Attempt to fix TestExportUserGPGKeys (#22159)
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 #22105 Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: Lunny Xiao <[email protected]> Co-authored-by: John Olheiser <[email protected]> Co-authored-by: techknowlogick <[email protected]> Co-authored-by: delvh <[email protected]>
1 parent 90572c5 commit fe6608f

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

tests/integration/integration_test.go

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,18 +264,45 @@ 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+
// Log the flash values on failure
290+
if !assert.Equal(t, resp.Result().Header["Location"], []string{"/user/settings/applications"}) {
291+
for _, cookie := range resp.Result().Cookies() {
292+
if cookie.Name != "macaron_flash" {
293+
continue
294+
}
295+
flash, _ := url.ParseQuery(cookie.Value)
296+
for key, value := range flash {
297+
t.Logf("Flash %q: %q", key, value)
298+
}
299+
}
300+
}
301+
275302
req = NewRequest(t, "GET", "/user/settings/applications")
276303
resp = session.MakeRequest(t, req, http.StatusOK)
277304
htmlDoc := NewHTMLParser(t, resp.Body)
278-
token := htmlDoc.doc.Find(".ui.info p").Text()
305+
token = htmlDoc.doc.Find(".ui.info p").Text()
279306
assert.NotEmpty(t, token)
280307
return token
281308
}

0 commit comments

Comments
 (0)