From f45a04cf6096af1b85499bfb6ae85f2d7f0a6158 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Sun, 18 Dec 2022 12:01:06 +0000 Subject: [PATCH 1/2] 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 #22105 Signed-off-by: Andrew Thornton --- tests/integration/integration_test.go | 34 +++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index d5fbb393b5bc5..85a50a13b3d72 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -264,18 +264,44 @@ var tokenCounter int64 func getTokenForLoggedInUser(t testing.TB, session *TestSession) string { t.Helper() + var token string req := NewRequest(t, "GET", "/user/settings/applications") resp := session.MakeRequest(t, req, http.StatusOK) - doc := NewHTMLParser(t, resp.Body) + var csrf string + for _, cookie := range resp.Result().Cookies() { + if cookie.Name != "_csrf" { + continue + } + csrf = cookie.Value + break + } + if csrf == "" { + doc := NewHTMLParser(t, resp.Body) + csrf = doc.GetCSRF() + } + assert.NotEmpty(t, csrf) req = NewRequestWithValues(t, "POST", "/user/settings/applications", map[string]string{ - "_csrf": doc.GetCSRF(), + "_csrf": csrf, "name": fmt.Sprintf("api-testing-token-%d", atomic.AddInt64(&tokenCounter, 1)), }) - session.MakeRequest(t, req, http.StatusSeeOther) + resp = session.MakeRequest(t, req, http.StatusSeeOther) + + if !assert.Equal(t, resp.Result().Header["Location"], []string{"/user/settings/applications"}) { + for _, cookie := range resp.Result().Cookies() { + if cookie.Name != "macaron_flash" { + continue + } + flash, _ := url.ParseQuery(cookie.Value) + for key, value := range flash { + t.Logf("Flash %q: %q", key, value) + } + } + } + req = NewRequest(t, "GET", "/user/settings/applications") resp = session.MakeRequest(t, req, http.StatusOK) htmlDoc := NewHTMLParser(t, resp.Body) - token := htmlDoc.doc.Find(".ui.info p").Text() + token = htmlDoc.doc.Find(".ui.info p").Text() assert.NotEmpty(t, token) return token } From d425e129bff80022d361611fd70986f246a67a16 Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Tue, 20 Dec 2022 17:26:44 -0500 Subject: [PATCH 2/2] Update tests/integration/integration_test.go Co-authored-by: delvh --- tests/integration/integration_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index 85a50a13b3d72..3537409aebf26 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -286,6 +286,7 @@ func getTokenForLoggedInUser(t testing.TB, session *TestSession) string { }) resp = session.MakeRequest(t, req, http.StatusSeeOther) + // Log the flash values on failure if !assert.Equal(t, resp.Result().Header["Location"], []string{"/user/settings/applications"}) { for _, cookie := range resp.Result().Cookies() { if cookie.Name != "macaron_flash" {