proxy_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package gold
  2. import (
  3. "io/ioutil"
  4. "net/http"
  5. "strings"
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestProxyNoAuth(t *testing.T) {
  10. request, err := http.NewRequest("GET", testServer.URL+"/"+ProxyPath+"?uri="+testServer.URL+"/_test/", nil)
  11. assert.NoError(t, err)
  12. request.Header.Add("Origin", "example.org")
  13. response, err := httpClient.Do(request)
  14. assert.NoError(t, err)
  15. assert.Equal(t, 200, response.StatusCode)
  16. assert.Contains(t, response.Header.Get("Content-Type"), "text/turtle")
  17. assert.Equal(t, "example.org", response.Header.Get("Access-Control-Allow-Origin"))
  18. body, err := ioutil.ReadAll(response.Body)
  19. assert.NoError(t, err)
  20. response.Body.Close()
  21. assert.Contains(t, string(body), "<http://www.w3.org/ns/ldp#BasicContainer>")
  22. }
  23. func TestProxyQueryOPTION(t *testing.T) {
  24. request, err := http.NewRequest("OPTIONS", testServer.URL+"/"+QueryPath, nil)
  25. assert.NoError(t, err)
  26. request.Header.Add("Origin", "example.org")
  27. request.Header.Add("Content-Type", "test/tql")
  28. response, err := httpClient.Do(request)
  29. assert.NoError(t, err)
  30. assert.Equal(t, 200, response.StatusCode)
  31. assert.Equal(t, "example.org", response.Header.Get("Access-Control-Allow-Origin"))
  32. assert.True(t, strings.Contains(response.Header.Get("Access-Control-Expose-Headers"), "Content-Type"))
  33. }