mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-11 15:21:02 +00:00
grpc-web cors test
This commit is contained in:
parent
31cd119a7e
commit
a2ee047868
1 changed files with 30 additions and 0 deletions
|
|
@ -1357,6 +1357,36 @@ func TestHandler_Endpoints(t *testing.T) {
|
|||
t.Fatalf("%v != %v", target, resp.IDs)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("grpc-web-cors", func(t *testing.T) {
|
||||
req := test.MustNewHTTPRequest("OPTIONS", "/pilosa.Pilosa/QueryPQL", nil)
|
||||
req.Header.Add("Origin", "http://test/")
|
||||
req.Header.Add("Access-Control-Request-Method", "POST")
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
h.ServeHTTP(w, req)
|
||||
result := w.Result()
|
||||
|
||||
// Fail CORS preflight
|
||||
if result.Header["Access-Control-Allow-Origin"] != nil {
|
||||
t.Fatalf("CORS preflight includes Access-Control-Allow-Origin but should not.")
|
||||
}
|
||||
|
||||
clus := test.MustRunCluster(t, 1, []server.CommandOption{test.OptAllowedOrigins([]string{"http://test/"})})
|
||||
defer clus.Close()
|
||||
w = httptest.NewRecorder()
|
||||
h := clus.GetNode(0).Handler.(*http.Handler).Handler
|
||||
h.ServeHTTP(w, req)
|
||||
result = w.Result()
|
||||
|
||||
if result.Header["Access-Control-Allow-Origin"] == nil {
|
||||
t.Fatalf("CORS preflight does not include Access-Control-Allow-Origin.")
|
||||
}
|
||||
|
||||
if result.Header["Access-Control-Allow-Origin"][0] != "http://test/" {
|
||||
t.Fatal("CORS header not present")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestCluster_TranslateStore(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue