Ensure GetCSRF
doesn't return an empty token (#32130)
Since page templates keep changing, some pages that contained forms with
CSRF token no longer have them.
It leads to some calls of `GetCSRF` returning an empty string, which
fails the tests. Like
3269b04d61/tests/integration/attachment_test.go (L62-L63)
The test did try to get the CSRF token and provided it, but it was
empty.
(cherry picked from commit 13283873e9d523d5a5557f55d64f702c1a9f76ec)
Conflicts:
tests/integration/integration_test.go
trivial context conflict
This commit is contained in:
parent
4337b8321b
commit
2bc47e81a3
3 changed files with 9 additions and 11 deletions
|
@ -663,12 +663,17 @@ func VerifyJSONSchema(t testing.TB, resp *httptest.ResponseRecorder, schemaFile
|
|||
require.NoError(t, schemaValidation)
|
||||
}
|
||||
|
||||
// GetCSRF returns CSRF token from body
|
||||
// If it fails, it means the CSRF token is not found in the response body returned by the url with the given session.
|
||||
// In this case, you should find a better url to get it.
|
||||
func GetCSRF(t testing.TB, session *TestSession, urlStr string) string {
|
||||
t.Helper()
|
||||
req := NewRequest(t, "GET", urlStr)
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
doc := NewHTMLParser(t, resp.Body)
|
||||
return doc.GetCSRF()
|
||||
csrf := doc.GetCSRF()
|
||||
require.NotEmpty(t, csrf)
|
||||
return csrf
|
||||
}
|
||||
|
||||
func GetHTMLTitle(t testing.TB, session *TestSession, urlStr string) string {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue