MCPcopy
hub / github.com/syncthing/syncthing / TestOptionsRequest

Function TestOptionsRequest

lib/api/api_test.go:1518–1545  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1516}
1517
1518func TestOptionsRequest(t *testing.T) {
1519 t.Parallel()
1520
1521 baseURL := startHTTP(t, apiCfg)
1522 cli := &http.Client{
1523 Timeout: time.Second,
1524 }
1525
1526 req, _ := http.NewRequest("OPTIONS", baseURL+"/rest/system/status", nil)
1527 resp, err := cli.Do(req)
1528 if err != nil {
1529 t.Fatal(err)
1530 }
1531
1532 resp.Body.Close()
1533 if resp.StatusCode != http.StatusNoContent {
1534 t.Fatal("OPTIONS on /rest/system/status should succeed, not", resp.Status)
1535 }
1536 if resp.Header.Get("Access-Control-Allow-Origin") != "*" {
1537 t.Fatal("OPTIONS on /rest/system/status should return a 'Access-Control-Allow-Origin: *' header")
1538 }
1539 if resp.Header.Get("Access-Control-Allow-Methods") != "GET, POST, PUT, PATCH, DELETE, OPTIONS" {
1540 t.Fatal("OPTIONS on /rest/system/status should return a 'Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE, OPTIONS' header")
1541 }
1542 if resp.Header.Get("Access-Control-Allow-Headers") != "Content-Type, X-API-Key" {
1543 t.Fatal("OPTIONS on /rest/system/status should return a 'Access-Control-Allow-Headers: Content-Type, X-API-KEY' header")
1544 }
1545}
1546
1547func TestEventMasks(t *testing.T) {
1548 t.Parallel()

Callers

nothing calls this directly

Calls 5

startHTTPFunction · 0.85
DoMethod · 0.80
FatalMethod · 0.80
CloseMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected