Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Make API update test resilient to stale cookies

rcourtmanca81f70afdbc
diff --git a/tests/integration/api/update_flow_test.go b/tests/integration/api/update_flow_test.go
index e57650af3b..98ad5aeca4 100644
--- a/tests/integration/api/update_flow_test.go
+++ b/tests/integration/api/update_flow_test.go
@@ -107,6 +107,9 @@ func login(t *testing.T, client *http.Client, baseURL, username, password string
resp := doJSONRequest(t, client, "POST", baseURL+"/api/login", payload)
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
+ if client != nil && client.Jar != nil {
+ clearCookies(client.Jar, resp.Request.URL)
+ }
t.Fatalf("login failed with status %s", resp.Status)
}
}
@@ -203,6 +206,8 @@ func doRequest(t *testing.T, client *http.Client, method, endpoint string, body
if client != nil && client.Jar != nil && methodRequiresCSRF(method) {
if token := csrfTokenForURL(client.Jar, req.URL); token != "" {
req.Header.Set("X-CSRF-Token", token)
+ } else {
+ req.Header.Del("X-CSRF-Token")
}
}
resp, err := client.Do(req)
@@ -246,3 +251,10 @@ func csrfTokenForURL(jar http.CookieJar, target *url.URL) string {
}
return ""
}
+
+func clearCookies(jar http.CookieJar, target *url.URL) {
+ if jar == nil || target == nil {
+ return
+ }
+ jar.SetCookies(target, []*http.Cookie{})
+}