forked from keratin/authn-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouting_test.go
35 lines (28 loc) · 891 Bytes
/
routing_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
package main
import (
"fmt"
"net/http/httptest"
"testing"
"github.com/keratin/authn-server/api/test"
"github.com/keratin/authn-server/lib/route"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestCORS(t *testing.T) {
app := test.App()
domain := app.Config.ApplicationDomains[0]
server := httptest.NewServer(router(app))
defer server.Close()
client := route.NewClient(server.URL)
res, err := client.Preflight(&domain, "PATCH", "/path")
require.NoError(t, err)
scheme := "http"
if domain.Port == "443" {
scheme = "https"
}
origin := fmt.Sprintf("%s://%s", scheme, domain.String())
fmt.Println(res.Header)
assert.Equal(t, "true", res.Header.Get("Access-Control-Allow-Credentials"))
assert.Equal(t, "PATCH", res.Header.Get("Access-Control-Allow-Methods"))
assert.Equal(t, origin, res.Header.Get("Access-Control-Allow-Origin"))
}