-
Notifications
You must be signed in to change notification settings - Fork 35
/
proxy_test.go
37 lines (33 loc) · 1.27 KB
/
proxy_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 (
"io/ioutil"
"net/http"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestProxyNoAuth(t *testing.T) {
request, err := http.NewRequest("GET", testServer.URL+"/"+ProxyPath+"?uri="+testServer.URL+"/_test/", nil)
assert.NoError(t, err)
request.Header.Add("Origin", "example.org")
response, err := httpClient.Do(request)
assert.NoError(t, err)
assert.Equal(t, 200, response.StatusCode)
assert.Contains(t, response.Header.Get("Content-Type"), "text/turtle")
assert.Equal(t, "example.org", response.Header.Get("Access-Control-Allow-Origin"))
body, err := ioutil.ReadAll(response.Body)
assert.NoError(t, err)
response.Body.Close()
assert.Contains(t, string(body), "<http://www.w3.org/ns/ldp#BasicContainer>")
}
func TestProxyQueryOPTION(t *testing.T) {
request, err := http.NewRequest("OPTIONS", testServer.URL+"/"+QueryPath, nil)
assert.NoError(t, err)
request.Header.Add("Origin", "example.org")
request.Header.Add("Content-Type", "test/tql")
response, err := httpClient.Do(request)
assert.NoError(t, err)
assert.Equal(t, 200, response.StatusCode)
assert.Equal(t, "example.org", response.Header.Get("Access-Control-Allow-Origin"))
assert.True(t, strings.Contains(response.Header.Get("Access-Control-Expose-Headers"), "Content-Type"))
}