Merge branch '17995-filter-by-comparing-attrs'
[arvados.git] / lib / controller / router / router_test.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package router
6
7 import (
8         "bytes"
9         "encoding/json"
10         "io"
11         "net/http"
12         "net/http/httptest"
13         "net/url"
14         "os"
15         "strings"
16         "testing"
17         "time"
18
19         "git.arvados.org/arvados.git/lib/controller/rpc"
20         "git.arvados.org/arvados.git/sdk/go/arvados"
21         "git.arvados.org/arvados.git/sdk/go/arvadostest"
22         "github.com/gorilla/mux"
23         check "gopkg.in/check.v1"
24 )
25
26 // Gocheck boilerplate
27 func Test(t *testing.T) {
28         check.TestingT(t)
29 }
30
31 var _ = check.Suite(&RouterSuite{})
32
33 type RouterSuite struct {
34         rtr  *router
35         stub arvadostest.APIStub
36 }
37
38 func (s *RouterSuite) SetUpTest(c *check.C) {
39         s.stub = arvadostest.APIStub{}
40         s.rtr = &router{
41                 mux:     mux.NewRouter(),
42                 backend: &s.stub,
43         }
44         s.rtr.addRoutes()
45 }
46
47 func (s *RouterSuite) TestOptions(c *check.C) {
48         token := arvadostest.ActiveToken
49         for _, trial := range []struct {
50                 comment      string // unparsed -- only used to help match test failures to trials
51                 method       string
52                 path         string
53                 header       http.Header
54                 body         string
55                 shouldStatus int // zero value means 200
56                 shouldCall   string
57                 withOptions  interface{}
58         }{
59                 {
60                         method:      "GET",
61                         path:        "/arvados/v1/collections/" + arvadostest.FooCollection,
62                         shouldCall:  "CollectionGet",
63                         withOptions: arvados.GetOptions{UUID: arvadostest.FooCollection},
64                 },
65                 {
66                         method:      "PUT",
67                         path:        "/arvados/v1/collections/" + arvadostest.FooCollection,
68                         shouldCall:  "CollectionUpdate",
69                         withOptions: arvados.UpdateOptions{UUID: arvadostest.FooCollection},
70                 },
71                 {
72                         method:      "PATCH",
73                         path:        "/arvados/v1/collections/" + arvadostest.FooCollection,
74                         shouldCall:  "CollectionUpdate",
75                         withOptions: arvados.UpdateOptions{UUID: arvadostest.FooCollection},
76                 },
77                 {
78                         method:      "DELETE",
79                         path:        "/arvados/v1/collections/" + arvadostest.FooCollection,
80                         shouldCall:  "CollectionDelete",
81                         withOptions: arvados.DeleteOptions{UUID: arvadostest.FooCollection},
82                 },
83                 {
84                         method:      "POST",
85                         path:        "/arvados/v1/collections",
86                         shouldCall:  "CollectionCreate",
87                         withOptions: arvados.CreateOptions{},
88                 },
89                 {
90                         method:      "GET",
91                         path:        "/arvados/v1/collections",
92                         shouldCall:  "CollectionList",
93                         withOptions: arvados.ListOptions{Limit: -1},
94                 },
95                 {
96                         method:      "GET",
97                         path:        "/arvados/v1/collections?limit=123&offset=456&include_trash=true&include_old_versions=1",
98                         shouldCall:  "CollectionList",
99                         withOptions: arvados.ListOptions{Limit: 123, Offset: 456, IncludeTrash: true, IncludeOldVersions: true},
100                 },
101                 {
102                         method:      "POST",
103                         path:        "/arvados/v1/collections?limit=123&_method=GET",
104                         body:        `{"offset":456,"include_trash":true,"include_old_versions":true}`,
105                         shouldCall:  "CollectionList",
106                         withOptions: arvados.ListOptions{Limit: 123, Offset: 456, IncludeTrash: true, IncludeOldVersions: true},
107                 },
108                 {
109                         method:      "POST",
110                         path:        "/arvados/v1/collections?limit=123",
111                         body:        `{"offset":456,"include_trash":true,"include_old_versions":true}`,
112                         header:      http.Header{"X-Http-Method-Override": {"GET"}, "Content-Type": {"application/json"}},
113                         shouldCall:  "CollectionList",
114                         withOptions: arvados.ListOptions{Limit: 123, Offset: 456, IncludeTrash: true, IncludeOldVersions: true},
115                 },
116                 {
117                         method:      "POST",
118                         path:        "/arvados/v1/collections?limit=123",
119                         body:        "offset=456&include_trash=true&include_old_versions=1&_method=GET",
120                         header:      http.Header{"Content-Type": {"application/x-www-form-urlencoded"}},
121                         shouldCall:  "CollectionList",
122                         withOptions: arvados.ListOptions{Limit: 123, Offset: 456, IncludeTrash: true, IncludeOldVersions: true},
123                 },
124                 {
125                         comment:     "form-encoded expression filter in query string",
126                         method:      "GET",
127                         path:        "/arvados/v1/collections?filters=[%22(foo<bar)%22]",
128                         header:      http.Header{"Content-Type": {"application/x-www-form-urlencoded"}},
129                         shouldCall:  "CollectionList",
130                         withOptions: arvados.ListOptions{Limit: -1, Filters: []arvados.Filter{{"(foo<bar)", "=", true}}},
131                 },
132                 {
133                         comment:     "form-encoded expression filter in POST body",
134                         method:      "POST",
135                         path:        "/arvados/v1/collections",
136                         body:        "filters=[\"(foo<bar)\"]&_method=GET",
137                         header:      http.Header{"Content-Type": {"application/x-www-form-urlencoded"}},
138                         shouldCall:  "CollectionList",
139                         withOptions: arvados.ListOptions{Limit: -1, Filters: []arvados.Filter{{"(foo<bar)", "=", true}}},
140                 },
141                 {
142                         comment:     "json-encoded expression filter in POST body",
143                         method:      "POST",
144                         path:        "/arvados/v1/collections?_method=GET",
145                         body:        `{"filters":["(foo<bar)",["bar","=","baz"]],"limit":2}`,
146                         header:      http.Header{"Content-Type": {"application/json"}},
147                         shouldCall:  "CollectionList",
148                         withOptions: arvados.ListOptions{Limit: 2, Filters: []arvados.Filter{{"(foo<bar)", "=", true}, {"bar", "=", "baz"}}},
149                 },
150                 {
151                         method:       "PATCH",
152                         path:         "/arvados/v1/collections",
153                         shouldStatus: http.StatusMethodNotAllowed,
154                 },
155                 {
156                         method:       "PUT",
157                         path:         "/arvados/v1/collections",
158                         shouldStatus: http.StatusMethodNotAllowed,
159                 },
160                 {
161                         method:       "DELETE",
162                         path:         "/arvados/v1/collections",
163                         shouldStatus: http.StatusMethodNotAllowed,
164                 },
165         } {
166                 // Reset calls captured in previous trial
167                 s.stub = arvadostest.APIStub{}
168
169                 c.Logf("trial: %+v", trial)
170                 comment := check.Commentf("trial comment: %s", trial.comment)
171
172                 _, rr, _ := doRequest(c, s.rtr, token, trial.method, trial.path, trial.header, bytes.NewBufferString(trial.body))
173                 if trial.shouldStatus == 0 {
174                         c.Check(rr.Code, check.Equals, http.StatusOK, comment)
175                 } else {
176                         c.Check(rr.Code, check.Equals, trial.shouldStatus, comment)
177                 }
178                 calls := s.stub.Calls(nil)
179                 if trial.shouldCall == "" {
180                         c.Check(calls, check.HasLen, 0, comment)
181                 } else if len(calls) != 1 {
182                         c.Check(calls, check.HasLen, 1, comment)
183                 } else {
184                         c.Check(calls[0].Method, isMethodNamed, trial.shouldCall, comment)
185                         c.Check(calls[0].Options, check.DeepEquals, trial.withOptions, comment)
186                 }
187         }
188 }
189
190 var _ = check.Suite(&RouterIntegrationSuite{})
191
192 type RouterIntegrationSuite struct {
193         rtr *router
194 }
195
196 func (s *RouterIntegrationSuite) SetUpTest(c *check.C) {
197         cluster := &arvados.Cluster{}
198         cluster.TLS.Insecure = true
199         arvadostest.SetServiceURL(&cluster.Services.RailsAPI, "https://"+os.Getenv("ARVADOS_TEST_API_HOST"))
200         url, _ := url.Parse("https://" + os.Getenv("ARVADOS_TEST_API_HOST"))
201         s.rtr = New(rpc.NewConn("zzzzz", url, true, rpc.PassthroughTokenProvider), Config{})
202 }
203
204 func (s *RouterIntegrationSuite) TearDownSuite(c *check.C) {
205         err := arvados.NewClientFromEnv().RequestAndDecode(nil, "POST", "database/reset", nil, nil)
206         c.Check(err, check.IsNil)
207 }
208
209 func (s *RouterIntegrationSuite) TestCollectionResponses(c *check.C) {
210         token := arvadostest.ActiveTokenV2
211
212         // Check "get collection" response has "kind" key
213         _, rr, jresp := doRequest(c, s.rtr, token, "GET", `/arvados/v1/collections`, nil, bytes.NewBufferString(`{"include_trash":true}`))
214         c.Check(rr.Code, check.Equals, http.StatusOK)
215         c.Check(jresp["items"], check.FitsTypeOf, []interface{}{})
216         c.Check(jresp["kind"], check.Equals, "arvados#collectionList")
217         c.Check(jresp["items"].([]interface{})[0].(map[string]interface{})["kind"], check.Equals, "arvados#collection")
218
219         // Check items in list response have a "kind" key regardless
220         // of whether a uuid/pdh is selected.
221         for _, selectj := range []string{
222                 ``,
223                 `,"select":["portable_data_hash"]`,
224                 `,"select":["name"]`,
225                 `,"select":["uuid"]`,
226         } {
227                 _, rr, jresp = doRequest(c, s.rtr, token, "GET", `/arvados/v1/collections`, nil, bytes.NewBufferString(`{"where":{"uuid":["`+arvadostest.FooCollection+`"]}`+selectj+`}`))
228                 c.Check(rr.Code, check.Equals, http.StatusOK)
229                 c.Check(jresp["items"], check.FitsTypeOf, []interface{}{})
230                 c.Check(jresp["items_available"], check.FitsTypeOf, float64(0))
231                 c.Check(jresp["kind"], check.Equals, "arvados#collectionList")
232                 item0 := jresp["items"].([]interface{})[0].(map[string]interface{})
233                 c.Check(item0["kind"], check.Equals, "arvados#collection")
234                 if selectj == "" || strings.Contains(selectj, "portable_data_hash") {
235                         c.Check(item0["portable_data_hash"], check.Equals, arvadostest.FooCollectionPDH)
236                 } else {
237                         c.Check(item0["portable_data_hash"], check.IsNil)
238                 }
239                 if selectj == "" || strings.Contains(selectj, "name") {
240                         c.Check(item0["name"], check.FitsTypeOf, "")
241                 } else {
242                         c.Check(item0["name"], check.IsNil)
243                 }
244                 if selectj == "" || strings.Contains(selectj, "uuid") {
245                         c.Check(item0["uuid"], check.Equals, arvadostest.FooCollection)
246                 } else {
247                         c.Check(item0["uuid"], check.IsNil)
248                 }
249         }
250
251         // Check "create collection" response has "kind" key
252         _, rr, jresp = doRequest(c, s.rtr, token, "POST", `/arvados/v1/collections`, http.Header{"Content-Type": {"application/x-www-form-urlencoded"}}, bytes.NewBufferString(`ensure_unique_name=true`))
253         c.Check(rr.Code, check.Equals, http.StatusOK)
254         c.Check(jresp["uuid"], check.FitsTypeOf, "")
255         c.Check(jresp["kind"], check.Equals, "arvados#collection")
256 }
257
258 func (s *RouterIntegrationSuite) TestMaxRequestSize(c *check.C) {
259         token := arvadostest.ActiveTokenV2
260         for _, maxRequestSize := range []int{
261                 // Ensure 5M limit is enforced.
262                 5000000,
263                 // Ensure 50M limit is enforced, and that a >25M body
264                 // is accepted even though the default Go request size
265                 // limit is 10M.
266                 50000000,
267         } {
268                 s.rtr.config.MaxRequestSize = maxRequestSize
269                 okstr := "a"
270                 for len(okstr) < maxRequestSize/2 {
271                         okstr = okstr + okstr
272                 }
273
274                 hdr := http.Header{"Content-Type": {"application/x-www-form-urlencoded"}}
275
276                 body := bytes.NewBufferString(url.Values{"foo_bar": {okstr}}.Encode())
277                 _, rr, _ := doRequest(c, s.rtr, token, "POST", `/arvados/v1/collections`, hdr, body)
278                 c.Check(rr.Code, check.Equals, http.StatusOK)
279
280                 body = bytes.NewBufferString(url.Values{"foo_bar": {okstr + okstr}}.Encode())
281                 _, rr, _ = doRequest(c, s.rtr, token, "POST", `/arvados/v1/collections`, hdr, body)
282                 c.Check(rr.Code, check.Equals, http.StatusRequestEntityTooLarge)
283         }
284 }
285
286 func (s *RouterIntegrationSuite) TestContainerList(c *check.C) {
287         token := arvadostest.ActiveTokenV2
288
289         _, rr, jresp := doRequest(c, s.rtr, token, "GET", `/arvados/v1/containers?limit=0`, nil, nil)
290         c.Check(rr.Code, check.Equals, http.StatusOK)
291         c.Check(jresp["items_available"], check.FitsTypeOf, float64(0))
292         c.Check(jresp["items_available"].(float64) > 2, check.Equals, true)
293         c.Check(jresp["items"], check.NotNil)
294         c.Check(jresp["items"], check.HasLen, 0)
295
296         _, rr, jresp = doRequest(c, s.rtr, token, "GET", `/arvados/v1/containers?filters=[["uuid","in",[]]]`, nil, nil)
297         c.Check(rr.Code, check.Equals, http.StatusOK)
298         c.Check(jresp["items_available"], check.Equals, float64(0))
299         c.Check(jresp["items"], check.NotNil)
300         c.Check(jresp["items"], check.HasLen, 0)
301
302         _, rr, jresp = doRequest(c, s.rtr, token, "GET", `/arvados/v1/containers?limit=2&select=["uuid","command"]`, nil, nil)
303         c.Check(rr.Code, check.Equals, http.StatusOK)
304         c.Check(jresp["items_available"], check.FitsTypeOf, float64(0))
305         c.Check(jresp["items_available"].(float64) > 2, check.Equals, true)
306         c.Check(jresp["items"], check.HasLen, 2)
307         item0 := jresp["items"].([]interface{})[0].(map[string]interface{})
308         c.Check(item0["uuid"], check.HasLen, 27)
309         c.Check(item0["command"], check.FitsTypeOf, []interface{}{})
310         c.Check(item0["command"].([]interface{})[0], check.FitsTypeOf, "")
311         c.Check(item0["mounts"], check.IsNil)
312
313         _, rr, jresp = doRequest(c, s.rtr, token, "GET", `/arvados/v1/containers`, nil, nil)
314         c.Check(rr.Code, check.Equals, http.StatusOK)
315         c.Check(jresp["items_available"], check.FitsTypeOf, float64(0))
316         c.Check(jresp["items_available"].(float64) > 2, check.Equals, true)
317         avail := int(jresp["items_available"].(float64))
318         c.Check(jresp["items"], check.HasLen, avail)
319         item0 = jresp["items"].([]interface{})[0].(map[string]interface{})
320         c.Check(item0["uuid"], check.HasLen, 27)
321         c.Check(item0["command"], check.FitsTypeOf, []interface{}{})
322         c.Check(item0["command"].([]interface{})[0], check.FitsTypeOf, "")
323         c.Check(item0["mounts"], check.NotNil)
324 }
325
326 func (s *RouterIntegrationSuite) TestContainerLock(c *check.C) {
327         uuid := arvadostest.QueuedContainerUUID
328         token := arvadostest.AdminToken
329         _, rr, jresp := doRequest(c, s.rtr, token, "POST", "/arvados/v1/containers/"+uuid+"/lock", nil, nil)
330         c.Check(rr.Code, check.Equals, http.StatusOK)
331         c.Check(jresp["uuid"], check.HasLen, 27)
332         c.Check(jresp["state"], check.Equals, "Locked")
333         _, rr, _ = doRequest(c, s.rtr, token, "POST", "/arvados/v1/containers/"+uuid+"/lock", nil, nil)
334         c.Check(rr.Code, check.Equals, http.StatusUnprocessableEntity)
335         c.Check(rr.Body.String(), check.Not(check.Matches), `.*"uuid":.*`)
336         _, rr, jresp = doRequest(c, s.rtr, token, "POST", "/arvados/v1/containers/"+uuid+"/unlock", nil, nil)
337         c.Check(rr.Code, check.Equals, http.StatusOK)
338         c.Check(jresp["uuid"], check.HasLen, 27)
339         c.Check(jresp["state"], check.Equals, "Queued")
340         c.Check(jresp["environment"], check.IsNil)
341         _, rr, jresp = doRequest(c, s.rtr, token, "POST", "/arvados/v1/containers/"+uuid+"/unlock", nil, nil)
342         c.Check(rr.Code, check.Equals, http.StatusUnprocessableEntity)
343         c.Check(jresp["uuid"], check.IsNil)
344 }
345
346 func (s *RouterIntegrationSuite) TestWritableBy(c *check.C) {
347         _, rr, jresp := doRequest(c, s.rtr, arvadostest.ActiveTokenV2, "GET", `/arvados/v1/users/`+arvadostest.ActiveUserUUID, nil, nil)
348         c.Check(rr.Code, check.Equals, http.StatusOK)
349         c.Check(jresp["writable_by"], check.DeepEquals, []interface{}{"zzzzz-tpzed-000000000000000", "zzzzz-tpzed-xurymjxw79nv3jz", "zzzzz-j7d0g-48foin4vonvc2at"})
350 }
351
352 func (s *RouterIntegrationSuite) TestFullTimestampsInResponse(c *check.C) {
353         uuid := arvadostest.CollectionReplicationDesired2Confirmed2UUID
354         token := arvadostest.ActiveTokenV2
355
356         _, rr, jresp := doRequest(c, s.rtr, token, "GET", `/arvados/v1/collections/`+uuid, nil, nil)
357         c.Check(rr.Code, check.Equals, http.StatusOK)
358         c.Check(jresp["uuid"], check.Equals, uuid)
359         expectNS := map[string]int{
360                 "created_at":  596506000, // fixture says 596506247, but truncated by postgresql
361                 "modified_at": 596338000, // fixture says 596338465, but truncated by postgresql
362         }
363         for key, ns := range expectNS {
364                 mt, ok := jresp[key].(string)
365                 c.Logf("jresp[%q] == %q", key, mt)
366                 c.Assert(ok, check.Equals, true)
367                 t, err := time.Parse(time.RFC3339Nano, mt)
368                 c.Check(err, check.IsNil)
369                 c.Check(t.Nanosecond(), check.Equals, ns)
370         }
371 }
372
373 func (s *RouterIntegrationSuite) TestSelectParam(c *check.C) {
374         uuid := arvadostest.QueuedContainerUUID
375         token := arvadostest.ActiveTokenV2
376         for _, sel := range [][]string{
377                 {"uuid", "command"},
378                 {"uuid", "command", "uuid"},
379                 {"", "command", "uuid"},
380         } {
381                 j, err := json.Marshal(sel)
382                 c.Assert(err, check.IsNil)
383                 _, rr, resp := doRequest(c, s.rtr, token, "GET", "/arvados/v1/containers/"+uuid+"?select="+string(j), nil, nil)
384                 c.Check(rr.Code, check.Equals, http.StatusOK)
385
386                 c.Check(resp["kind"], check.Equals, "arvados#container")
387                 c.Check(resp["etag"], check.FitsTypeOf, "")
388                 c.Check(resp["etag"], check.Not(check.Equals), "")
389                 c.Check(resp["uuid"], check.HasLen, 27)
390                 c.Check(resp["command"], check.HasLen, 2)
391                 c.Check(resp["mounts"], check.IsNil)
392                 _, hasMounts := resp["mounts"]
393                 c.Check(hasMounts, check.Equals, false)
394         }
395 }
396
397 func (s *RouterIntegrationSuite) TestHEAD(c *check.C) {
398         _, rr, _ := doRequest(c, s.rtr, arvadostest.ActiveTokenV2, "HEAD", "/arvados/v1/containers/"+arvadostest.QueuedContainerUUID, nil, nil)
399         c.Check(rr.Code, check.Equals, http.StatusOK)
400 }
401
402 func (s *RouterIntegrationSuite) TestRouteNotFound(c *check.C) {
403         token := arvadostest.ActiveTokenV2
404         req := (&testReq{
405                 method: "POST",
406                 path:   "arvados/v1/collections/" + arvadostest.FooCollection + "/error404pls",
407                 token:  token,
408         }).Request()
409         rr := httptest.NewRecorder()
410         s.rtr.ServeHTTP(rr, req)
411         c.Check(rr.Code, check.Equals, http.StatusNotFound)
412         c.Logf("body: %q", rr.Body.String())
413         var j map[string]interface{}
414         err := json.Unmarshal(rr.Body.Bytes(), &j)
415         c.Check(err, check.IsNil)
416         c.Logf("decoded: %v", j)
417         c.Assert(j["errors"], check.FitsTypeOf, []interface{}{})
418         c.Check(j["errors"].([]interface{})[0], check.Equals, "API endpoint not found")
419 }
420
421 func (s *RouterIntegrationSuite) TestCORS(c *check.C) {
422         token := arvadostest.ActiveTokenV2
423         req := (&testReq{
424                 method: "OPTIONS",
425                 path:   "arvados/v1/collections/" + arvadostest.FooCollection,
426                 header: http.Header{"Origin": {"https://example.com"}},
427                 token:  token,
428         }).Request()
429         rr := httptest.NewRecorder()
430         s.rtr.ServeHTTP(rr, req)
431         c.Check(rr.Code, check.Equals, http.StatusOK)
432         c.Check(rr.Body.String(), check.HasLen, 0)
433         c.Check(rr.Result().Header.Get("Access-Control-Allow-Origin"), check.Equals, "*")
434         for _, hdr := range []string{"Authorization", "Content-Type"} {
435                 c.Check(rr.Result().Header.Get("Access-Control-Allow-Headers"), check.Matches, ".*"+hdr+".*")
436         }
437         for _, method := range []string{"GET", "HEAD", "PUT", "POST", "PATCH", "DELETE"} {
438                 c.Check(rr.Result().Header.Get("Access-Control-Allow-Methods"), check.Matches, ".*"+method+".*")
439         }
440
441         for _, unsafe := range []string{"login", "logout", "auth", "auth/foo", "login/?blah"} {
442                 req := (&testReq{
443                         method: "OPTIONS",
444                         path:   unsafe,
445                         header: http.Header{"Origin": {"https://example.com"}},
446                         token:  token,
447                 }).Request()
448                 rr := httptest.NewRecorder()
449                 s.rtr.ServeHTTP(rr, req)
450                 c.Check(rr.Code, check.Equals, http.StatusOK)
451                 c.Check(rr.Body.String(), check.HasLen, 0)
452                 c.Check(rr.Result().Header.Get("Access-Control-Allow-Origin"), check.Equals, "")
453                 c.Check(rr.Result().Header.Get("Access-Control-Allow-Methods"), check.Equals, "")
454                 c.Check(rr.Result().Header.Get("Access-Control-Allow-Headers"), check.Equals, "")
455
456                 req = (&testReq{
457                         method: "POST",
458                         path:   unsafe,
459                         header: http.Header{"Origin": {"https://example.com"}},
460                         token:  token,
461                 }).Request()
462                 rr = httptest.NewRecorder()
463                 s.rtr.ServeHTTP(rr, req)
464                 c.Check(rr.Result().Header.Get("Access-Control-Allow-Origin"), check.Equals, "")
465                 c.Check(rr.Result().Header.Get("Access-Control-Allow-Methods"), check.Equals, "")
466                 c.Check(rr.Result().Header.Get("Access-Control-Allow-Headers"), check.Equals, "")
467         }
468 }
469
470 func doRequest(c *check.C, rtr http.Handler, token, method, path string, hdrs http.Header, body io.Reader) (*http.Request, *httptest.ResponseRecorder, map[string]interface{}) {
471         req := httptest.NewRequest(method, path, body)
472         for k, v := range hdrs {
473                 req.Header[k] = v
474         }
475         req.Header.Set("Authorization", "Bearer "+token)
476         rr := httptest.NewRecorder()
477         rtr.ServeHTTP(rr, req)
478         c.Logf("response body: %s", rr.Body.String())
479         var jresp map[string]interface{}
480         err := json.Unmarshal(rr.Body.Bytes(), &jresp)
481         c.Check(err, check.IsNil)
482         return req, rr, jresp
483 }