MCPcopy
hub / github.com/syncthing/syncthing / TestAccessControlAllowOriginHeader

Function TestAccessControlAllowOriginHeader

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

Source from the content-addressed store, hash-verified

1492}
1493
1494func TestAccessControlAllowOriginHeader(t *testing.T) {
1495 t.Parallel()
1496
1497 baseURL := startHTTP(t, apiCfg)
1498 cli := &http.Client{
1499 Timeout: time.Second,
1500 }
1501
1502 req, _ := http.NewRequest("GET", baseURL+"/rest/system/status", nil)
1503 req.Header.Set("X-API-Key", testAPIKey)
1504 resp, err := cli.Do(req)
1505 if err != nil {
1506 t.Fatal(err)
1507 }
1508
1509 resp.Body.Close()
1510 if resp.StatusCode != http.StatusOK {
1511 t.Fatal("GET on /rest/system/status should succeed, not", resp.Status)
1512 }
1513 if resp.Header.Get("Access-Control-Allow-Origin") != "*" {
1514 t.Fatal("GET on /rest/system/status should return a 'Access-Control-Allow-Origin: *' header")
1515 }
1516}
1517
1518func TestOptionsRequest(t *testing.T) {
1519 t.Parallel()

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected