Fix CSRF tests (fixes #2009)

This commit is contained in:
Audrius Butkevicius 2015-06-30 19:38:27 +01:00
parent a03c9f9457
commit 37a42dc408

View File

@ -204,6 +204,7 @@ func TestPOSTWithoutCSRF(t *testing.T) {
}
res.Body.Close()
hdr := res.Header.Get("Set-Cookie")
id := res.Header.Get("X-Syncthing-ID")[:5]
if !strings.Contains(hdr, "CSRF-Token") {
t.Error("Missing CSRF-Token in", hdr)
}
@ -214,7 +215,8 @@ func TestPOSTWithoutCSRF(t *testing.T) {
if err != nil {
t.Fatal(err)
}
req.Header.Set("X-CSRF-Token", hdr[len("CSRF-Token="):])
req.Header.Set("X-CSRF-Token-"+id, hdr[len("CSRF-Token-"+id+"="):])
res, err = http.DefaultClient.Do(req)
if err != nil {
t.Fatal(err)
@ -230,7 +232,7 @@ func TestPOSTWithoutCSRF(t *testing.T) {
if err != nil {
t.Fatal(err)
}
req.Header.Set("X-CSRF-Token", hdr[len("CSRF-Token="):]+"X")
req.Header.Set("X-CSRF-Token-"+id, hdr[len("CSRF-Token-"+id+"="):]+"X")
res, err = http.DefaultClient.Do(req)
if err != nil {
t.Fatal(err)