Add a CORS handler to deal with preflight OPTIONS requests

This commit is contained in:
Laurent Etiemble
2016-01-26 08:05:24 +01:00
committed by Jakob Borg
parent 56db1d3dfa
commit fed374fcb6
2 changed files with 52 additions and 4 deletions

View File

@@ -172,6 +172,24 @@ func TestGetJSON(t *testing.T) {
}
}
func TestOptions(t *testing.T) {
p := startInstance(t, 2)
defer checkedStop(t, p)
req, err := http.NewRequest("OPTIONS", "http://127.0.0.1:8082/rest/system/error/clear", nil)
if err != nil {
t.Fatal(err)
}
res, err := http.DefaultClient.Do(req)
if err != nil {
t.Fatal(err)
}
res.Body.Close()
if res.StatusCode != 204 {
t.Fatalf("Status %d != 204 for OPTIONS", res.StatusCode)
}
}
func TestPOSTWithoutCSRF(t *testing.T) {
p := startInstance(t, 2)
defer checkedStop(t, p)