Skip to content

Commit

Permalink
Merge pull request #1975 from influxdb/http-query-require-param
Browse files Browse the repository at this point in the history
Require parameter for query endpoint
  • Loading branch information
toddboom committed Mar 16, 2015
2 parents 21cbd84 + e2bd1c3 commit d8b8a8c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

### Bugfixes
- [#1971](https://github.com/influxdb/influxdb/pull/1971): Fix leader id initialization.
- [#1975](https://github.com/influxdb/influxdb/pull/1975): Require `q` parameter for query endpoint.

## v0.9.0-rc12 [2015-03-15]

Expand Down
12 changes: 10 additions & 2 deletions httpd/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,18 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// serveQuery parses an incoming query and, if valid, executes the query.
func (h *Handler) serveQuery(w http.ResponseWriter, r *http.Request, user *influxdb.User) {
q := r.URL.Query()
p := influxql.NewParser(strings.NewReader(q.Get("q")))
db := q.Get("db")

pretty := q.Get("pretty") == "true"

qp := strings.TrimSpace(q.Get("q"))
if qp == "" {
httpError(w, `missing required parameter "q"`, pretty, http.StatusBadRequest)
return
}

p := influxql.NewParser(strings.NewReader(qp))
db := q.Get("db")

// Parse query from query string.
query, err := p.ParseQuery()
if err != nil {
Expand Down
15 changes: 15 additions & 0 deletions httpd/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,21 @@ func TestHandler_AuthenticatedDatabases_Unauthorized(t *testing.T) {
}
}

func TestHandler_QueryParamenterMissing(t *testing.T) {
c := test.NewMessagingClient()
defer c.Close()
srvr := OpenAuthlessServer(c)
s := NewHTTPServer(srvr)
defer s.Close()

status, body := MustHTTP("GET", s.URL+`/query`, nil, nil, "")
if status != http.StatusBadRequest {
t.Fatalf("unexpected status: %d", status)
} else if body != `{"error":"missing required parameter \"q\""}` {
t.Fatalf("unexpected body: %s", body)
}
}

func TestHandler_AuthenticatedDatabases_AuthorizedQueryParams(t *testing.T) {
c := test.NewMessagingClient()
defer c.Close()
Expand Down

0 comments on commit d8b8a8c

Please sign in to comment.