-
Notifications
You must be signed in to change notification settings - Fork 35
/
cors_test.go
37 lines (32 loc) · 1010 Bytes
/
cors_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package gold
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCORSRequestHasOrigin(t *testing.T) {
requestOrigin := "https://example.com"
url := testServer.URL + "/_test/user1"
req, err := http.NewRequest("GET", url, nil)
assert.NoError(t, err)
req.Header.Set("Origin", requestOrigin)
resp, err := httpClient.Do(req)
assert.NoError(t, err)
assert.Equal(t, requestOrigin, resp.Header.Get("Access-Control-Allow-Origin"))
}
func TestCORSRequestHasNoOrigin(t *testing.T) {
url := testServer.URL + "/_test/user1"
req, err := http.NewRequest("GET", url, nil)
assert.NoError(t, err)
resp, err := httpClient.Do(req)
assert.NoError(t, err)
assert.Equal(t, "*", resp.Header.Get("Access-Control-Allow-Origin"))
}
func TestVaryHeader(t *testing.T) {
url := testServer.URL + "/_test/user1"
req, err := http.NewRequest("GET", url, nil)
assert.NoError(t, err)
resp, err := httpClient.Do(req)
assert.NoError(t, err)
assert.Equal(t, "Origin", resp.Header.Get("Vary"))
}