Exemplo n.º 1
0
// Ensure the handler returns a status 401 if the user is not authorized.
func TestHandler_Query_ErrUnauthorized(t *testing.T) {
	h := NewHandler(false)
	h.QueryExecutor.ExecuteQueryFn = func(q *influxql.Query, db string, chunkSize int) (<-chan *influxql.Result, error) {
		return nil, meta.NewAuthError("marker")
	}

	w := httptest.NewRecorder()
	h.ServeHTTP(w, MustNewJSONRequest("GET", "/query?db=foo&q=SHOW+SERIES+FROM+bar", nil))
	if w.Code != http.StatusUnauthorized {
		t.Fatalf("unexpected status: %d", w.Code)
	}
}
Exemplo n.º 2
0
// Ensure the handler returns a status 401 if an auth error is returned from the result.
func TestHandler_Query_Result_ErrUnauthorized(t *testing.T) {
	h := NewHandler(false)
	h.QueryExecutor.ExecuteQueryFn = func(q *influxql.Query, db string, chunkSize int) (<-chan *influxql.Result, error) {
		return NewResultChan(&influxql.Result{Err: meta.NewAuthError("marker")}), nil
	}

	w := httptest.NewRecorder()
	h.ServeHTTP(w, MustNewJSONRequest("GET", "/query?db=foo&q=SHOW+SERIES+from+bin", nil))
	if w.Code != http.StatusUnauthorized {
		t.Fatalf("unexpected status: %d", w.Code)
	} else if w.Body.String() != `{"results":[{"error":"marker"}]}` {
		t.Fatalf("unexpected body: %s", w.Body.String())
	}
}