From: Tom Clegg Date: Tue, 7 May 2019 13:39:58 +0000 (-0400) Subject: 14287: Fix accepting boolean params via query string. X-Git-Tag: 2.0.0~282^2~58 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/5ccc56b87f78f73830a04eb265dc7f04743984f5 14287: Fix accepting boolean params via query string. Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- diff --git a/lib/controller/router/request.go b/lib/controller/router/request.go index 67d4e0ffb6..8ea253e6c4 100644 --- a/lib/controller/router/request.go +++ b/lib/controller/router/request.go @@ -29,6 +29,8 @@ func (rtr *router) loadRequestParams(req *http.Request, attrsKey string) (map[st for k, values := range req.Form { for _, v := range values { switch { + case boolParams[k]: + params[k] = stringToBool(v) case v == "null" || v == "": params[k] = nil case strings.HasPrefix(v, "["): @@ -110,3 +112,18 @@ func (rtr *router) transcode(src interface{}, dst interface{}) error { } return err } + +var boolParams = map[string]bool{ + "ensure_unique_name": true, + "include_trash": true, + "include_old_versions": true, +} + +func stringToBool(s string) bool { + switch s { + case "", "false", "0": + return false + default: + return true + } +} diff --git a/lib/controller/router/router_test.go b/lib/controller/router/router_test.go index e7355dc544..22d08c8423 100644 --- a/lib/controller/router/router_test.go +++ b/lib/controller/router/router_test.go @@ -5,6 +5,7 @@ package router import ( + "bytes" "encoding/json" "io" "net/http" @@ -56,6 +57,26 @@ func (s *RouterSuite) doRequest(c *check.C, token, method, path string, hdrs htt return req, rw, jresp } +func (s *RouterSuite) TestCollectionParams(c *check.C) { + token := arvadostest.ActiveTokenV2 + + _, rw, jresp := s.doRequest(c, token, "GET", `/arvados/v1/collections?include_trash=true`, nil, nil) + c.Check(rw.Code, check.Equals, http.StatusOK) + c.Check(jresp["items_available"], check.FitsTypeOf, float64(0)) + + _, rw, jresp = s.doRequest(c, token, "GET", `/arvados/v1/collections`, nil, bytes.NewBufferString(`{"include_trash":true}`)) + c.Check(rw.Code, check.Equals, http.StatusOK) + c.Check(jresp["items"], check.FitsTypeOf, []interface{}{}) + + _, rw, jresp = s.doRequest(c, token, "POST", `/arvados/v1/collections`, nil, bytes.NewBufferString(`ensure_unique_name=true`)) + c.Check(rw.Code, check.Equals, http.StatusOK) + c.Check(jresp["uuid"], check.FitsTypeOf, "") + + _, rw, jresp = s.doRequest(c, token, "POST", `/arvados/v1/collections?ensure_unique_name=true`, nil, nil) + c.Check(rw.Code, check.Equals, http.StatusOK) + c.Check(jresp["uuid"], check.FitsTypeOf, "") +} + func (s *RouterSuite) TestContainerList(c *check.C) { token := arvadostest.ActiveTokenV2