Merge branch '15454-stop-building-debian8-and-ubuntu1404'
[arvados.git] / lib / controller / federation_test.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package controller
6
7 import (
8         "bytes"
9         "context"
10         "encoding/json"
11         "fmt"
12         "io"
13         "io/ioutil"
14         "net/http"
15         "net/http/httptest"
16         "net/url"
17         "os"
18         "strings"
19         "time"
20
21         "git.curoverse.com/arvados.git/sdk/go/arvados"
22         "git.curoverse.com/arvados.git/sdk/go/arvadostest"
23         "git.curoverse.com/arvados.git/sdk/go/ctxlog"
24         "git.curoverse.com/arvados.git/sdk/go/httpserver"
25         "git.curoverse.com/arvados.git/sdk/go/keepclient"
26         "github.com/sirupsen/logrus"
27         check "gopkg.in/check.v1"
28 )
29
30 // Gocheck boilerplate
31 var _ = check.Suite(&FederationSuite{})
32
33 type FederationSuite struct {
34         log logrus.FieldLogger
35         // testServer and testHandler are the controller being tested,
36         // "zhome".
37         testServer  *httpserver.Server
38         testHandler *Handler
39         // remoteServer ("zzzzz") forwards requests to the Rails API
40         // provided by the integration test environment.
41         remoteServer *httpserver.Server
42         // remoteMock ("zmock") appends each incoming request to
43         // remoteMockRequests, and returns 200 with an empty JSON
44         // object.
45         remoteMock         *httpserver.Server
46         remoteMockRequests []http.Request
47 }
48
49 func (s *FederationSuite) SetUpTest(c *check.C) {
50         s.log = ctxlog.TestLogger(c)
51
52         s.remoteServer = newServerFromIntegrationTestEnv(c)
53         c.Assert(s.remoteServer.Start(), check.IsNil)
54
55         s.remoteMock = newServerFromIntegrationTestEnv(c)
56         s.remoteMock.Server.Handler = http.HandlerFunc(s.remoteMockHandler)
57         c.Assert(s.remoteMock.Start(), check.IsNil)
58
59         cluster := &arvados.Cluster{
60                 ClusterID:                 "zhome",
61                 PostgreSQL:                integrationTestCluster().PostgreSQL,
62                 EnableBetaController14287: enableBetaController14287,
63         }
64         cluster.TLS.Insecure = true
65         cluster.API.MaxItemsPerResponse = 1000
66         cluster.API.MaxRequestAmplification = 4
67         arvadostest.SetServiceURL(&cluster.Services.RailsAPI, "http://localhost:1/")
68         arvadostest.SetServiceURL(&cluster.Services.Controller, "http://localhost:/")
69         s.testHandler = &Handler{Cluster: cluster}
70         s.testServer = newServerFromIntegrationTestEnv(c)
71         s.testServer.Server.Handler = httpserver.HandlerWithContext(
72                 ctxlog.Context(context.Background(), s.log),
73                 httpserver.AddRequestIDs(httpserver.LogRequests(s.testHandler)))
74
75         cluster.RemoteClusters = map[string]arvados.RemoteCluster{
76                 "zzzzz": {
77                         Host:   s.remoteServer.Addr,
78                         Proxy:  true,
79                         Scheme: "http",
80                 },
81                 "zmock": {
82                         Host:   s.remoteMock.Addr,
83                         Proxy:  true,
84                         Scheme: "http",
85                 },
86         }
87
88         c.Assert(s.testServer.Start(), check.IsNil)
89
90         s.remoteMockRequests = nil
91 }
92
93 func (s *FederationSuite) remoteMockHandler(w http.ResponseWriter, req *http.Request) {
94         b := &bytes.Buffer{}
95         io.Copy(b, req.Body)
96         req.Body.Close()
97         req.Body = ioutil.NopCloser(b)
98         s.remoteMockRequests = append(s.remoteMockRequests, *req)
99         // Repond 200 with a valid JSON object
100         fmt.Fprint(w, "{}")
101 }
102
103 func (s *FederationSuite) TearDownTest(c *check.C) {
104         if s.remoteServer != nil {
105                 s.remoteServer.Close()
106         }
107         if s.testServer != nil {
108                 s.testServer.Close()
109         }
110 }
111
112 func (s *FederationSuite) testRequest(req *http.Request) *httptest.ResponseRecorder {
113         resp := httptest.NewRecorder()
114         s.testServer.Server.Handler.ServeHTTP(resp, req)
115         return resp
116 }
117
118 func (s *FederationSuite) TestLocalRequest(c *check.C) {
119         req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+strings.Replace(arvadostest.WorkflowWithDefinitionYAMLUUID, "zzzzz-", "zhome-", 1), nil)
120         resp := s.testRequest(req).Result()
121         s.checkHandledLocally(c, resp)
122 }
123
124 func (s *FederationSuite) checkHandledLocally(c *check.C, resp *http.Response) {
125         // Our "home" controller can't handle local requests because
126         // it doesn't have its own stub/test Rails API, so we rely on
127         // "connection refused" to indicate the controller tried to
128         // proxy the request to its local Rails API.
129         c.Check(resp.StatusCode, check.Equals, http.StatusBadGateway)
130         s.checkJSONErrorMatches(c, resp, `.*connection refused`)
131 }
132
133 func (s *FederationSuite) TestNoAuth(c *check.C) {
134         req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+arvadostest.WorkflowWithDefinitionYAMLUUID, nil)
135         resp := s.testRequest(req).Result()
136         c.Check(resp.StatusCode, check.Equals, http.StatusUnauthorized)
137         s.checkJSONErrorMatches(c, resp, `Not logged in.*`)
138 }
139
140 func (s *FederationSuite) TestBadAuth(c *check.C) {
141         req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+arvadostest.WorkflowWithDefinitionYAMLUUID, nil)
142         req.Header.Set("Authorization", "Bearer aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
143         resp := s.testRequest(req).Result()
144         c.Check(resp.StatusCode, check.Equals, http.StatusUnauthorized)
145         s.checkJSONErrorMatches(c, resp, `Not logged in.*`)
146 }
147
148 func (s *FederationSuite) TestNoAccess(c *check.C) {
149         req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+arvadostest.WorkflowWithDefinitionYAMLUUID, nil)
150         req.Header.Set("Authorization", "Bearer "+arvadostest.SpectatorToken)
151         resp := s.testRequest(req).Result()
152         c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)
153         s.checkJSONErrorMatches(c, resp, `.*not found.*`)
154 }
155
156 func (s *FederationSuite) TestGetUnknownRemote(c *check.C) {
157         req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+strings.Replace(arvadostest.WorkflowWithDefinitionYAMLUUID, "zzzzz-", "zz404-", 1), nil)
158         req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
159         resp := s.testRequest(req).Result()
160         c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)
161         s.checkJSONErrorMatches(c, resp, `.*no proxy available for cluster zz404`)
162 }
163
164 func (s *FederationSuite) TestRemoteError(c *check.C) {
165         rc := s.testHandler.Cluster.RemoteClusters["zzzzz"]
166         rc.Scheme = "https"
167         s.testHandler.Cluster.RemoteClusters["zzzzz"] = rc
168
169         req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+arvadostest.WorkflowWithDefinitionYAMLUUID, nil)
170         req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
171         resp := s.testRequest(req).Result()
172         c.Check(resp.StatusCode, check.Equals, http.StatusBadGateway)
173         s.checkJSONErrorMatches(c, resp, `.*HTTP response to HTTPS client`)
174 }
175
176 func (s *FederationSuite) TestGetRemoteWorkflow(c *check.C) {
177         req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+arvadostest.WorkflowWithDefinitionYAMLUUID, nil)
178         req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
179         resp := s.testRequest(req).Result()
180         c.Check(resp.StatusCode, check.Equals, http.StatusOK)
181         var wf arvados.Workflow
182         c.Check(json.NewDecoder(resp.Body).Decode(&wf), check.IsNil)
183         c.Check(wf.UUID, check.Equals, arvadostest.WorkflowWithDefinitionYAMLUUID)
184         c.Check(wf.OwnerUUID, check.Equals, arvadostest.ActiveUserUUID)
185 }
186
187 func (s *FederationSuite) TestOptionsMethod(c *check.C) {
188         req := httptest.NewRequest("OPTIONS", "/arvados/v1/workflows/"+arvadostest.WorkflowWithDefinitionYAMLUUID, nil)
189         req.Header.Set("Origin", "https://example.com")
190         resp := s.testRequest(req).Result()
191         c.Check(resp.StatusCode, check.Equals, http.StatusOK)
192         body, err := ioutil.ReadAll(resp.Body)
193         c.Check(err, check.IsNil)
194         c.Check(string(body), check.Equals, "")
195         c.Check(resp.Header.Get("Access-Control-Allow-Origin"), check.Equals, "*")
196         for _, hdr := range []string{"Authorization", "Content-Type"} {
197                 c.Check(resp.Header.Get("Access-Control-Allow-Headers"), check.Matches, ".*"+hdr+".*")
198         }
199         for _, method := range []string{"GET", "HEAD", "PUT", "POST", "DELETE"} {
200                 c.Check(resp.Header.Get("Access-Control-Allow-Methods"), check.Matches, ".*"+method+".*")
201         }
202 }
203
204 func (s *FederationSuite) TestRemoteWithTokenInQuery(c *check.C) {
205         req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+strings.Replace(arvadostest.WorkflowWithDefinitionYAMLUUID, "zzzzz-", "zmock-", 1)+"?api_token="+arvadostest.ActiveToken, nil)
206         s.testRequest(req).Result()
207         c.Assert(s.remoteMockRequests, check.HasLen, 1)
208         pr := s.remoteMockRequests[0]
209         // Token is salted and moved from query to Authorization header.
210         c.Check(pr.URL.String(), check.Not(check.Matches), `.*api_token=.*`)
211         c.Check(pr.Header.Get("Authorization"), check.Equals, "Bearer v2/zzzzz-gj3su-077z32aux8dg2s1/7fd31b61f39c0e82a4155592163218272cedacdc")
212 }
213
214 func (s *FederationSuite) TestLocalTokenSalted(c *check.C) {
215         defer s.localServiceReturns404(c).Close()
216         for _, path := range []string{
217                 // During the transition to the strongly typed
218                 // controller implementation (#14287), workflows and
219                 // collections test different code paths.
220                 "/arvados/v1/workflows/" + strings.Replace(arvadostest.WorkflowWithDefinitionYAMLUUID, "zzzzz-", "zmock-", 1),
221                 "/arvados/v1/collections/" + strings.Replace(arvadostest.UserAgreementCollection, "zzzzz-", "zmock-", 1),
222         } {
223                 c.Log("testing path ", path)
224                 s.remoteMockRequests = nil
225                 req := httptest.NewRequest("GET", path, nil)
226                 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
227                 s.testRequest(req).Result()
228                 c.Assert(s.remoteMockRequests, check.HasLen, 1)
229                 pr := s.remoteMockRequests[0]
230                 // The salted token here has a "zzzzz-" UUID instead of a
231                 // "ztest-" UUID because ztest's local database has the
232                 // "zzzzz-" test fixtures. The "secret" part is HMAC(sha1,
233                 // arvadostest.ActiveToken, "zmock") = "7fd3...".
234                 c.Check(pr.Header.Get("Authorization"), check.Equals, "Bearer v2/zzzzz-gj3su-077z32aux8dg2s1/7fd31b61f39c0e82a4155592163218272cedacdc")
235         }
236 }
237
238 func (s *FederationSuite) TestRemoteTokenNotSalted(c *check.C) {
239         defer s.localServiceReturns404(c).Close()
240         // remoteToken can be any v1 token that doesn't appear in
241         // ztest's local db.
242         remoteToken := "abcdef00000000000000000000000000000000000000000000"
243
244         for _, path := range []string{
245                 // During the transition to the strongly typed
246                 // controller implementation (#14287), workflows and
247                 // collections test different code paths.
248                 "/arvados/v1/workflows/" + strings.Replace(arvadostest.WorkflowWithDefinitionYAMLUUID, "zzzzz-", "zmock-", 1),
249                 "/arvados/v1/collections/" + strings.Replace(arvadostest.UserAgreementCollection, "zzzzz-", "zmock-", 1),
250         } {
251                 c.Log("testing path ", path)
252                 s.remoteMockRequests = nil
253                 req := httptest.NewRequest("GET", path, nil)
254                 req.Header.Set("Authorization", "Bearer "+remoteToken)
255                 s.testRequest(req).Result()
256                 c.Assert(s.remoteMockRequests, check.HasLen, 1)
257                 pr := s.remoteMockRequests[0]
258                 c.Check(pr.Header.Get("Authorization"), check.Equals, "Bearer "+remoteToken)
259         }
260 }
261
262 func (s *FederationSuite) TestWorkflowCRUD(c *check.C) {
263         var wf arvados.Workflow
264         {
265                 req := httptest.NewRequest("POST", "/arvados/v1/workflows", strings.NewReader(url.Values{
266                         "workflow": {`{"description": "TestCRUD"}`},
267                 }.Encode()))
268                 req.Header.Set("Content-type", "application/x-www-form-urlencoded")
269                 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
270                 rec := httptest.NewRecorder()
271                 s.remoteServer.Server.Handler.ServeHTTP(rec, req) // direct to remote -- can't proxy a create req because no uuid
272                 resp := rec.Result()
273                 s.checkResponseOK(c, resp)
274                 json.NewDecoder(resp.Body).Decode(&wf)
275
276                 defer func() {
277                         req := httptest.NewRequest("DELETE", "/arvados/v1/workflows/"+wf.UUID, nil)
278                         req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
279                         s.remoteServer.Server.Handler.ServeHTTP(httptest.NewRecorder(), req)
280                 }()
281                 c.Check(wf.UUID, check.Not(check.Equals), "")
282
283                 c.Assert(wf.ModifiedAt, check.NotNil)
284                 c.Logf("wf.ModifiedAt: %v", wf.ModifiedAt)
285                 c.Check(time.Since(*wf.ModifiedAt) < time.Minute, check.Equals, true)
286         }
287         for _, method := range []string{"PATCH", "PUT", "POST"} {
288                 form := url.Values{
289                         "workflow": {`{"description": "Updated with ` + method + `"}`},
290                 }
291                 if method == "POST" {
292                         form["_method"] = []string{"PATCH"}
293                 }
294                 req := httptest.NewRequest(method, "/arvados/v1/workflows/"+wf.UUID, strings.NewReader(form.Encode()))
295                 req.Header.Set("Content-type", "application/x-www-form-urlencoded")
296                 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
297                 resp := s.testRequest(req).Result()
298                 s.checkResponseOK(c, resp)
299                 err := json.NewDecoder(resp.Body).Decode(&wf)
300                 c.Check(err, check.IsNil)
301
302                 c.Check(wf.Description, check.Equals, "Updated with "+method)
303         }
304         {
305                 req := httptest.NewRequest("DELETE", "/arvados/v1/workflows/"+wf.UUID, nil)
306                 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
307                 resp := s.testRequest(req).Result()
308                 s.checkResponseOK(c, resp)
309                 err := json.NewDecoder(resp.Body).Decode(&wf)
310                 c.Check(err, check.IsNil)
311         }
312         {
313                 req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+wf.UUID, nil)
314                 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
315                 resp := s.testRequest(req).Result()
316                 c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)
317         }
318 }
319
320 func (s *FederationSuite) checkResponseOK(c *check.C, resp *http.Response) {
321         c.Check(resp.StatusCode, check.Equals, http.StatusOK)
322         if resp.StatusCode != http.StatusOK {
323                 body, err := ioutil.ReadAll(resp.Body)
324                 c.Logf("... response body = %q, %v\n", body, err)
325         }
326 }
327
328 func (s *FederationSuite) checkJSONErrorMatches(c *check.C, resp *http.Response, re string) {
329         var jresp httpserver.ErrorResponse
330         err := json.NewDecoder(resp.Body).Decode(&jresp)
331         c.Check(err, check.IsNil)
332         c.Assert(jresp.Errors, check.HasLen, 1)
333         c.Check(jresp.Errors[0], check.Matches, re)
334 }
335
336 func (s *FederationSuite) localServiceHandler(c *check.C, h http.Handler) *httpserver.Server {
337         srv := &httpserver.Server{
338                 Server: http.Server{
339                         Handler: h,
340                 },
341         }
342         c.Assert(srv.Start(), check.IsNil)
343         arvadostest.SetServiceURL(&s.testHandler.Cluster.Services.RailsAPI, "http://"+srv.Addr)
344         return srv
345 }
346
347 func (s *FederationSuite) localServiceReturns404(c *check.C) *httpserver.Server {
348         return s.localServiceHandler(c, http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
349                 if req.URL.Path == "/arvados/v1/api_client_authorizations/current" {
350                         if req.Header.Get("Authorization") == "Bearer "+arvadostest.ActiveToken {
351                                 json.NewEncoder(w).Encode(arvados.APIClientAuthorization{UUID: arvadostest.ActiveTokenUUID, APIToken: arvadostest.ActiveToken})
352                         } else {
353                                 w.WriteHeader(http.StatusUnauthorized)
354                         }
355                 } else {
356                         w.WriteHeader(404)
357                 }
358         }))
359 }
360
361 func (s *FederationSuite) TestGetLocalCollection(c *check.C) {
362         s.testHandler.Cluster.ClusterID = "zzzzz"
363         arvadostest.SetServiceURL(&s.testHandler.Cluster.Services.RailsAPI, "https://"+os.Getenv("ARVADOS_TEST_API_HOST"))
364
365         // HTTP GET
366
367         req := httptest.NewRequest("GET", "/arvados/v1/collections/"+arvadostest.UserAgreementCollection, nil)
368         req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
369         resp := s.testRequest(req).Result()
370
371         c.Check(resp.StatusCode, check.Equals, http.StatusOK)
372         var col arvados.Collection
373         c.Check(json.NewDecoder(resp.Body).Decode(&col), check.IsNil)
374         c.Check(col.UUID, check.Equals, arvadostest.UserAgreementCollection)
375         c.Check(col.ManifestText, check.Matches,
376                 `\. 6a4ff0499484c6c79c95cd8c566bd25f\+249025\+A[0-9a-f]{40}@[0-9a-f]{8} 0:249025:GNU_General_Public_License,_version_3.pdf
377 `)
378
379         // HTTP POST with _method=GET as a form parameter
380
381         req = httptest.NewRequest("POST", "/arvados/v1/collections/"+arvadostest.UserAgreementCollection, bytes.NewBufferString((url.Values{
382                 "_method": {"GET"},
383         }).Encode()))
384         req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
385         req.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
386         resp = s.testRequest(req).Result()
387
388         c.Check(resp.StatusCode, check.Equals, http.StatusOK)
389         col = arvados.Collection{}
390         c.Check(json.NewDecoder(resp.Body).Decode(&col), check.IsNil)
391         c.Check(col.UUID, check.Equals, arvadostest.UserAgreementCollection)
392         c.Check(col.ManifestText, check.Matches,
393                 `\. 6a4ff0499484c6c79c95cd8c566bd25f\+249025\+A[0-9a-f]{40}@[0-9a-f]{8} 0:249025:GNU_General_Public_License,_version_3.pdf
394 `)
395 }
396
397 func (s *FederationSuite) TestGetRemoteCollection(c *check.C) {
398         defer s.localServiceReturns404(c).Close()
399
400         req := httptest.NewRequest("GET", "/arvados/v1/collections/"+arvadostest.UserAgreementCollection, nil)
401         req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
402         resp := s.testRequest(req).Result()
403         c.Check(resp.StatusCode, check.Equals, http.StatusOK)
404         var col arvados.Collection
405         c.Check(json.NewDecoder(resp.Body).Decode(&col), check.IsNil)
406         c.Check(col.UUID, check.Equals, arvadostest.UserAgreementCollection)
407         c.Check(col.ManifestText, check.Matches,
408                 `\. 6a4ff0499484c6c79c95cd8c566bd25f\+249025\+Rzzzzz-[0-9a-f]{40}@[0-9a-f]{8} 0:249025:GNU_General_Public_License,_version_3.pdf
409 `)
410 }
411
412 func (s *FederationSuite) TestGetRemoteCollectionError(c *check.C) {
413         defer s.localServiceReturns404(c).Close()
414
415         req := httptest.NewRequest("GET", "/arvados/v1/collections/zzzzz-4zz18-fakefakefakefak", nil)
416         req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
417         resp := s.testRequest(req).Result()
418         c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)
419 }
420
421 func (s *FederationSuite) TestSignedLocatorPattern(c *check.C) {
422         // Confirm the regular expression identifies other groups of hints correctly
423         c.Check(keepclient.SignedLocatorRe.FindStringSubmatch(`6a4ff0499484c6c79c95cd8c566bd25f+249025+B1+C2+A05227438989d04712ea9ca1c91b556cef01d5cc7@5ba5405b+D3+E4`),
424                 check.DeepEquals,
425                 []string{"6a4ff0499484c6c79c95cd8c566bd25f+249025+B1+C2+A05227438989d04712ea9ca1c91b556cef01d5cc7@5ba5405b+D3+E4",
426                         "6a4ff0499484c6c79c95cd8c566bd25f",
427                         "+249025",
428                         "+B1+C2", "+C2",
429                         "+A05227438989d04712ea9ca1c91b556cef01d5cc7@5ba5405b",
430                         "05227438989d04712ea9ca1c91b556cef01d5cc7", "5ba5405b",
431                         "+D3+E4", "+E4"})
432 }
433
434 func (s *FederationSuite) TestGetLocalCollectionByPDH(c *check.C) {
435         arvadostest.SetServiceURL(&s.testHandler.Cluster.Services.RailsAPI, "https://"+os.Getenv("ARVADOS_TEST_API_HOST"))
436
437         req := httptest.NewRequest("GET", "/arvados/v1/collections/"+arvadostest.UserAgreementPDH, nil)
438         req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
439         resp := s.testRequest(req).Result()
440
441         c.Check(resp.StatusCode, check.Equals, http.StatusOK)
442         var col arvados.Collection
443         c.Check(json.NewDecoder(resp.Body).Decode(&col), check.IsNil)
444         c.Check(col.PortableDataHash, check.Equals, arvadostest.UserAgreementPDH)
445         c.Check(col.ManifestText, check.Matches,
446                 `\. 6a4ff0499484c6c79c95cd8c566bd25f\+249025\+A[0-9a-f]{40}@[0-9a-f]{8} 0:249025:GNU_General_Public_License,_version_3.pdf
447 `)
448 }
449
450 func (s *FederationSuite) TestGetRemoteCollectionByPDH(c *check.C) {
451         defer s.localServiceReturns404(c).Close()
452
453         req := httptest.NewRequest("GET", "/arvados/v1/collections/"+arvadostest.UserAgreementPDH, nil)
454         req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
455         resp := s.testRequest(req).Result()
456
457         c.Check(resp.StatusCode, check.Equals, http.StatusOK)
458
459         var col arvados.Collection
460         c.Check(json.NewDecoder(resp.Body).Decode(&col), check.IsNil)
461         c.Check(col.PortableDataHash, check.Equals, arvadostest.UserAgreementPDH)
462         c.Check(col.ManifestText, check.Matches,
463                 `\. 6a4ff0499484c6c79c95cd8c566bd25f\+249025\+Rzzzzz-[0-9a-f]{40}@[0-9a-f]{8} 0:249025:GNU_General_Public_License,_version_3.pdf
464 `)
465 }
466
467 func (s *FederationSuite) TestGetCollectionByPDHError(c *check.C) {
468         defer s.localServiceReturns404(c).Close()
469
470         req := httptest.NewRequest("GET", "/arvados/v1/collections/99999999999999999999999999999999+99", nil)
471         req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
472
473         resp := s.testRequest(req).Result()
474         defer resp.Body.Close()
475
476         c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)
477 }
478
479 func (s *FederationSuite) TestGetCollectionByPDHErrorBadHash(c *check.C) {
480         defer s.localServiceReturns404(c).Close()
481
482         srv2 := &httpserver.Server{
483                 Server: http.Server{
484                         Handler: http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
485                                 w.WriteHeader(200)
486                                 // Return a collection where the hash
487                                 // of the manifest text doesn't match
488                                 // PDH that was requested.
489                                 var col arvados.Collection
490                                 col.PortableDataHash = "99999999999999999999999999999999+99"
491                                 col.ManifestText = `. 6a4ff0499484c6c79c95cd8c566bd25f\+249025 0:249025:GNU_General_Public_License,_version_3.pdf
492 `
493                                 enc := json.NewEncoder(w)
494                                 enc.Encode(col)
495                         }),
496                 },
497         }
498
499         c.Assert(srv2.Start(), check.IsNil)
500         defer srv2.Close()
501
502         // Direct zzzzz to service that returns a 200 result with a bogus manifest_text
503         s.testHandler.Cluster.RemoteClusters["zzzzz"] = arvados.RemoteCluster{
504                 Host:   srv2.Addr,
505                 Proxy:  true,
506                 Scheme: "http",
507         }
508
509         req := httptest.NewRequest("GET", "/arvados/v1/collections/99999999999999999999999999999999+99", nil)
510         req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
511
512         resp := s.testRequest(req).Result()
513         defer resp.Body.Close()
514
515         c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)
516 }
517
518 func (s *FederationSuite) TestSaltedTokenGetCollectionByPDH(c *check.C) {
519         arvadostest.SetServiceURL(&s.testHandler.Cluster.Services.RailsAPI, "https://"+os.Getenv("ARVADOS_TEST_API_HOST"))
520
521         req := httptest.NewRequest("GET", "/arvados/v1/collections/"+arvadostest.UserAgreementPDH, nil)
522         req.Header.Set("Authorization", "Bearer v2/zzzzz-gj3su-077z32aux8dg2s1/282d7d172b6cfdce364c5ed12ddf7417b2d00065")
523         resp := s.testRequest(req).Result()
524
525         c.Check(resp.StatusCode, check.Equals, http.StatusOK)
526         var col arvados.Collection
527         c.Check(json.NewDecoder(resp.Body).Decode(&col), check.IsNil)
528         c.Check(col.PortableDataHash, check.Equals, arvadostest.UserAgreementPDH)
529         c.Check(col.ManifestText, check.Matches,
530                 `\. 6a4ff0499484c6c79c95cd8c566bd25f\+249025\+A[0-9a-f]{40}@[0-9a-f]{8} 0:249025:GNU_General_Public_License,_version_3.pdf
531 `)
532 }
533
534 func (s *FederationSuite) TestSaltedTokenGetCollectionByPDHError(c *check.C) {
535         arvadostest.SetServiceURL(&s.testHandler.Cluster.Services.RailsAPI, "https://"+os.Getenv("ARVADOS_TEST_API_HOST"))
536
537         req := httptest.NewRequest("GET", "/arvados/v1/collections/99999999999999999999999999999999+99", nil)
538         req.Header.Set("Authorization", "Bearer v2/zzzzz-gj3su-077z32aux8dg2s1/282d7d172b6cfdce364c5ed12ddf7417b2d00065")
539         resp := s.testRequest(req).Result()
540
541         c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)
542 }
543
544 func (s *FederationSuite) TestGetRemoteContainerRequest(c *check.C) {
545         defer s.localServiceReturns404(c).Close()
546         req := httptest.NewRequest("GET", "/arvados/v1/container_requests/"+arvadostest.QueuedContainerRequestUUID, nil)
547         req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
548         resp := s.testRequest(req).Result()
549         c.Check(resp.StatusCode, check.Equals, http.StatusOK)
550         var cr arvados.ContainerRequest
551         c.Check(json.NewDecoder(resp.Body).Decode(&cr), check.IsNil)
552         c.Check(cr.UUID, check.Equals, arvadostest.QueuedContainerRequestUUID)
553         c.Check(cr.Priority, check.Equals, 1)
554 }
555
556 func (s *FederationSuite) TestUpdateRemoteContainerRequest(c *check.C) {
557         defer s.localServiceReturns404(c).Close()
558         setPri := func(pri int) {
559                 req := httptest.NewRequest("PATCH", "/arvados/v1/container_requests/"+arvadostest.QueuedContainerRequestUUID,
560                         strings.NewReader(fmt.Sprintf(`{"container_request": {"priority": %d}}`, pri)))
561                 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
562                 req.Header.Set("Content-type", "application/json")
563                 resp := s.testRequest(req).Result()
564                 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
565                 var cr arvados.ContainerRequest
566                 c.Check(json.NewDecoder(resp.Body).Decode(&cr), check.IsNil)
567                 c.Check(cr.UUID, check.Equals, arvadostest.QueuedContainerRequestUUID)
568                 c.Check(cr.Priority, check.Equals, pri)
569         }
570         setPri(696)
571         setPri(1) // Reset fixture so side effect doesn't break other tests.
572 }
573
574 func (s *FederationSuite) TestCreateRemoteContainerRequest(c *check.C) {
575         defer s.localServiceReturns404(c).Close()
576         // pass cluster_id via query parameter, this allows arvados-controller
577         // to avoid parsing the body
578         req := httptest.NewRequest("POST", "/arvados/v1/container_requests?cluster_id=zzzzz",
579                 strings.NewReader(`{
580   "container_request": {
581     "name": "hello world",
582     "state": "Uncommitted",
583     "output_path": "/",
584     "container_image": "123",
585     "command": ["abc"]
586   }
587 }
588 `))
589         req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
590         req.Header.Set("Content-type", "application/json")
591         resp := s.testRequest(req).Result()
592         c.Check(resp.StatusCode, check.Equals, http.StatusOK)
593         var cr arvados.ContainerRequest
594         c.Check(json.NewDecoder(resp.Body).Decode(&cr), check.IsNil)
595         c.Check(cr.Name, check.Equals, "hello world")
596         c.Check(strings.HasPrefix(cr.UUID, "zzzzz-"), check.Equals, true)
597 }
598
599 func (s *FederationSuite) TestCreateRemoteContainerRequestCheckRuntimeToken(c *check.C) {
600         // Send request to zmock and check that outgoing request has
601         // runtime_token set with a new random v2 token.
602
603         defer s.localServiceReturns404(c).Close()
604         // pass cluster_id via query parameter, this allows arvados-controller
605         // to avoid parsing the body
606         req := httptest.NewRequest("POST", "/arvados/v1/container_requests?cluster_id=zmock",
607                 strings.NewReader(`{
608   "container_request": {
609     "name": "hello world",
610     "state": "Uncommitted",
611     "output_path": "/",
612     "container_image": "123",
613     "command": ["abc"]
614   }
615 }
616 `))
617         req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveTokenV2)
618         req.Header.Set("Content-type", "application/json")
619
620         arvadostest.SetServiceURL(&s.testHandler.Cluster.Services.RailsAPI, "https://"+os.Getenv("ARVADOS_TEST_API_HOST"))
621         s.testHandler.Cluster.ClusterID = "zzzzz"
622
623         resp := s.testRequest(req).Result()
624         c.Check(resp.StatusCode, check.Equals, http.StatusOK)
625         var cr struct {
626                 arvados.ContainerRequest `json:"container_request"`
627         }
628         c.Check(json.NewDecoder(s.remoteMockRequests[0].Body).Decode(&cr), check.IsNil)
629         c.Check(strings.HasPrefix(cr.ContainerRequest.RuntimeToken, "v2/zzzzz-gj3su-"), check.Equals, true)
630         c.Check(cr.ContainerRequest.RuntimeToken, check.Not(check.Equals), arvadostest.ActiveTokenV2)
631 }
632
633 func (s *FederationSuite) TestCreateRemoteContainerRequestCheckSetRuntimeToken(c *check.C) {
634         // Send request to zmock and check that outgoing request has
635         // runtime_token set with the explicitly provided token.
636
637         defer s.localServiceReturns404(c).Close()
638         // pass cluster_id via query parameter, this allows arvados-controller
639         // to avoid parsing the body
640         req := httptest.NewRequest("POST", "/arvados/v1/container_requests?cluster_id=zmock",
641                 strings.NewReader(`{
642   "container_request": {
643     "name": "hello world",
644     "state": "Uncommitted",
645     "output_path": "/",
646     "container_image": "123",
647     "command": ["abc"],
648     "runtime_token": "xyz"
649   }
650 }
651 `))
652         req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
653         req.Header.Set("Content-type", "application/json")
654         resp := s.testRequest(req).Result()
655         c.Check(resp.StatusCode, check.Equals, http.StatusOK)
656         var cr struct {
657                 arvados.ContainerRequest `json:"container_request"`
658         }
659         c.Check(json.NewDecoder(s.remoteMockRequests[0].Body).Decode(&cr), check.IsNil)
660         c.Check(cr.ContainerRequest.RuntimeToken, check.Equals, "xyz")
661 }
662
663 func (s *FederationSuite) TestCreateRemoteContainerRequestRuntimeTokenFromAuth(c *check.C) {
664         // Send request to zmock and check that outgoing request has
665         // runtime_token set using the Auth token because the user is remote.
666
667         defer s.localServiceReturns404(c).Close()
668         // pass cluster_id via query parameter, this allows arvados-controller
669         // to avoid parsing the body
670         req := httptest.NewRequest("POST", "/arvados/v1/container_requests?cluster_id=zmock",
671                 strings.NewReader(`{
672   "container_request": {
673     "name": "hello world",
674     "state": "Uncommitted",
675     "output_path": "/",
676     "container_image": "123",
677     "command": ["abc"]
678   }
679 }
680 `))
681         req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveTokenV2+"/zzzzz-dz642-parentcontainer")
682         req.Header.Set("Content-type", "application/json")
683         resp := s.testRequest(req).Result()
684         c.Check(resp.StatusCode, check.Equals, http.StatusOK)
685         var cr struct {
686                 arvados.ContainerRequest `json:"container_request"`
687         }
688         c.Check(json.NewDecoder(s.remoteMockRequests[0].Body).Decode(&cr), check.IsNil)
689         c.Check(cr.ContainerRequest.RuntimeToken, check.Equals, arvadostest.ActiveTokenV2)
690 }
691
692 func (s *FederationSuite) TestCreateRemoteContainerRequestError(c *check.C) {
693         defer s.localServiceReturns404(c).Close()
694         // pass cluster_id via query parameter, this allows arvados-controller
695         // to avoid parsing the body
696         req := httptest.NewRequest("POST", "/arvados/v1/container_requests?cluster_id=zz404",
697                 strings.NewReader(`{
698   "container_request": {
699     "name": "hello world",
700     "state": "Uncommitted",
701     "output_path": "/",
702     "container_image": "123",
703     "command": ["abc"]
704   }
705 }
706 `))
707         req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
708         req.Header.Set("Content-type", "application/json")
709         resp := s.testRequest(req).Result()
710         c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)
711 }
712
713 func (s *FederationSuite) TestGetRemoteContainer(c *check.C) {
714         defer s.localServiceReturns404(c).Close()
715         req := httptest.NewRequest("GET", "/arvados/v1/containers/"+arvadostest.QueuedContainerUUID, nil)
716         req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
717         resp := s.testRequest(req)
718         c.Check(resp.Code, check.Equals, http.StatusOK)
719         var cn arvados.Container
720         c.Check(json.NewDecoder(resp.Body).Decode(&cn), check.IsNil)
721         c.Check(cn.UUID, check.Equals, arvadostest.QueuedContainerUUID)
722 }
723
724 func (s *FederationSuite) TestListRemoteContainer(c *check.C) {
725         defer s.localServiceReturns404(c).Close()
726         req := httptest.NewRequest("GET", "/arvados/v1/containers?count=none&filters="+
727                 url.QueryEscape(fmt.Sprintf(`[["uuid", "in", ["%v"]]]`, arvadostest.QueuedContainerUUID)), nil)
728         req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
729         resp := s.testRequest(req).Result()
730         c.Check(resp.StatusCode, check.Equals, http.StatusOK)
731         var cn arvados.ContainerList
732         c.Check(json.NewDecoder(resp.Body).Decode(&cn), check.IsNil)
733         c.Assert(cn.Items, check.HasLen, 1)
734         c.Check(cn.Items[0].UUID, check.Equals, arvadostest.QueuedContainerUUID)
735 }
736
737 func (s *FederationSuite) TestListMultiRemoteContainers(c *check.C) {
738         defer s.localServiceHandler(c, http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
739                 bd, _ := ioutil.ReadAll(req.Body)
740                 c.Check(string(bd), check.Equals, `_method=GET&count=none&filters=%5B%5B%22uuid%22%2C+%22in%22%2C+%5B%22zhome-xvhdp-cr5queuedcontnr%22%5D%5D%5D&select=%5B%22uuid%22%2C+%22command%22%5D`)
741                 w.WriteHeader(200)
742                 w.Write([]byte(`{"kind": "arvados#containerList", "items": [{"uuid": "zhome-xvhdp-cr5queuedcontnr", "command": ["abc"]}]}`))
743         })).Close()
744         req := httptest.NewRequest("GET", fmt.Sprintf("/arvados/v1/containers?count=none&filters=%s&select=%s",
745                 url.QueryEscape(fmt.Sprintf(`[["uuid", "in", ["%v", "zhome-xvhdp-cr5queuedcontnr"]]]`,
746                         arvadostest.QueuedContainerUUID)),
747                 url.QueryEscape(`["uuid", "command"]`)),
748                 nil)
749         req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
750         resp := s.testRequest(req).Result()
751         c.Check(resp.StatusCode, check.Equals, http.StatusOK)
752         var cn arvados.ContainerList
753         c.Check(json.NewDecoder(resp.Body).Decode(&cn), check.IsNil)
754         c.Check(cn.Items, check.HasLen, 2)
755         mp := make(map[string]arvados.Container)
756         for _, cr := range cn.Items {
757                 mp[cr.UUID] = cr
758         }
759         c.Check(mp[arvadostest.QueuedContainerUUID].Command, check.DeepEquals, []string{"echo", "hello"})
760         c.Check(mp[arvadostest.QueuedContainerUUID].ContainerImage, check.Equals, "")
761         c.Check(mp["zhome-xvhdp-cr5queuedcontnr"].Command, check.DeepEquals, []string{"abc"})
762         c.Check(mp["zhome-xvhdp-cr5queuedcontnr"].ContainerImage, check.Equals, "")
763 }
764
765 func (s *FederationSuite) TestListMultiRemoteContainerError(c *check.C) {
766         defer s.localServiceReturns404(c).Close()
767         req := httptest.NewRequest("GET", fmt.Sprintf("/arvados/v1/containers?count=none&filters=%s&select=%s",
768                 url.QueryEscape(fmt.Sprintf(`[["uuid", "in", ["%v", "zhome-xvhdp-cr5queuedcontnr"]]]`,
769                         arvadostest.QueuedContainerUUID)),
770                 url.QueryEscape(`["uuid", "command"]`)),
771                 nil)
772         req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
773         resp := s.testRequest(req).Result()
774         c.Check(resp.StatusCode, check.Equals, http.StatusBadGateway)
775         s.checkJSONErrorMatches(c, resp, `error fetching from zhome \(404 Not Found\): EOF`)
776 }
777
778 func (s *FederationSuite) TestListMultiRemoteContainersPaged(c *check.C) {
779
780         callCount := 0
781         defer s.localServiceHandler(c, http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
782                 bd, _ := ioutil.ReadAll(req.Body)
783                 if callCount == 0 {
784                         c.Check(string(bd), check.Equals, `_method=GET&count=none&filters=%5B%5B%22uuid%22%2C+%22in%22%2C+%5B%22zhome-xvhdp-cr5queuedcontnr%22%2C%22zhome-xvhdp-cr6queuedcontnr%22%5D%5D%5D`)
785                         w.WriteHeader(200)
786                         w.Write([]byte(`{"kind": "arvados#containerList", "items": [{"uuid": "zhome-xvhdp-cr5queuedcontnr", "command": ["abc"]}]}`))
787                 } else if callCount == 1 {
788                         c.Check(string(bd), check.Equals, `_method=GET&count=none&filters=%5B%5B%22uuid%22%2C+%22in%22%2C+%5B%22zhome-xvhdp-cr6queuedcontnr%22%5D%5D%5D`)
789                         w.WriteHeader(200)
790                         w.Write([]byte(`{"kind": "arvados#containerList", "items": [{"uuid": "zhome-xvhdp-cr6queuedcontnr", "command": ["efg"]}]}`))
791                 }
792                 callCount += 1
793         })).Close()
794         req := httptest.NewRequest("GET", fmt.Sprintf("/arvados/v1/containers?count=none&filters=%s",
795                 url.QueryEscape(fmt.Sprintf(`[["uuid", "in", ["%v", "zhome-xvhdp-cr5queuedcontnr", "zhome-xvhdp-cr6queuedcontnr"]]]`,
796                         arvadostest.QueuedContainerUUID))),
797                 nil)
798         req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
799         resp := s.testRequest(req).Result()
800         c.Check(resp.StatusCode, check.Equals, http.StatusOK)
801         c.Check(callCount, check.Equals, 2)
802         var cn arvados.ContainerList
803         c.Check(json.NewDecoder(resp.Body).Decode(&cn), check.IsNil)
804         c.Check(cn.Items, check.HasLen, 3)
805         mp := make(map[string]arvados.Container)
806         for _, cr := range cn.Items {
807                 mp[cr.UUID] = cr
808         }
809         c.Check(mp[arvadostest.QueuedContainerUUID].Command, check.DeepEquals, []string{"echo", "hello"})
810         c.Check(mp["zhome-xvhdp-cr5queuedcontnr"].Command, check.DeepEquals, []string{"abc"})
811         c.Check(mp["zhome-xvhdp-cr6queuedcontnr"].Command, check.DeepEquals, []string{"efg"})
812 }
813
814 func (s *FederationSuite) TestListMultiRemoteContainersMissing(c *check.C) {
815
816         callCount := 0
817         defer s.localServiceHandler(c, http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
818                 bd, _ := ioutil.ReadAll(req.Body)
819                 if callCount == 0 {
820                         c.Check(string(bd), check.Equals, `_method=GET&count=none&filters=%5B%5B%22uuid%22%2C+%22in%22%2C+%5B%22zhome-xvhdp-cr5queuedcontnr%22%2C%22zhome-xvhdp-cr6queuedcontnr%22%5D%5D%5D`)
821                         w.WriteHeader(200)
822                         w.Write([]byte(`{"kind": "arvados#containerList", "items": [{"uuid": "zhome-xvhdp-cr6queuedcontnr", "command": ["efg"]}]}`))
823                 } else if callCount == 1 {
824                         c.Check(string(bd), check.Equals, `_method=GET&count=none&filters=%5B%5B%22uuid%22%2C+%22in%22%2C+%5B%22zhome-xvhdp-cr5queuedcontnr%22%5D%5D%5D`)
825                         w.WriteHeader(200)
826                         w.Write([]byte(`{"kind": "arvados#containerList", "items": []}`))
827                 }
828                 callCount += 1
829         })).Close()
830         req := httptest.NewRequest("GET", fmt.Sprintf("/arvados/v1/containers?count=none&filters=%s",
831                 url.QueryEscape(fmt.Sprintf(`[["uuid", "in", ["%v", "zhome-xvhdp-cr5queuedcontnr", "zhome-xvhdp-cr6queuedcontnr"]]]`,
832                         arvadostest.QueuedContainerUUID))),
833                 nil)
834         req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
835         resp := s.testRequest(req).Result()
836         c.Check(resp.StatusCode, check.Equals, http.StatusOK)
837         c.Check(callCount, check.Equals, 2)
838         var cn arvados.ContainerList
839         c.Check(json.NewDecoder(resp.Body).Decode(&cn), check.IsNil)
840         c.Check(cn.Items, check.HasLen, 2)
841         mp := make(map[string]arvados.Container)
842         for _, cr := range cn.Items {
843                 mp[cr.UUID] = cr
844         }
845         c.Check(mp[arvadostest.QueuedContainerUUID].Command, check.DeepEquals, []string{"echo", "hello"})
846         c.Check(mp["zhome-xvhdp-cr6queuedcontnr"].Command, check.DeepEquals, []string{"efg"})
847 }
848
849 func (s *FederationSuite) TestListMultiRemoteContainerPageSizeError(c *check.C) {
850         s.testHandler.Cluster.API.MaxItemsPerResponse = 1
851         req := httptest.NewRequest("GET", fmt.Sprintf("/arvados/v1/containers?count=none&filters=%s",
852                 url.QueryEscape(fmt.Sprintf(`[["uuid", "in", ["%v", "zhome-xvhdp-cr5queuedcontnr"]]]`,
853                         arvadostest.QueuedContainerUUID))),
854                 nil)
855         req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
856         resp := s.testRequest(req).Result()
857         c.Check(resp.StatusCode, check.Equals, http.StatusBadRequest)
858         s.checkJSONErrorMatches(c, resp, `Federated multi-object request for 2 objects which is more than max page size 1.`)
859 }
860
861 func (s *FederationSuite) TestListMultiRemoteContainerLimitError(c *check.C) {
862         req := httptest.NewRequest("GET", fmt.Sprintf("/arvados/v1/containers?count=none&filters=%s&limit=1",
863                 url.QueryEscape(fmt.Sprintf(`[["uuid", "in", ["%v", "zhome-xvhdp-cr5queuedcontnr"]]]`,
864                         arvadostest.QueuedContainerUUID))),
865                 nil)
866         req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
867         resp := s.testRequest(req).Result()
868         c.Check(resp.StatusCode, check.Equals, http.StatusBadRequest)
869         s.checkJSONErrorMatches(c, resp, `Federated multi-object may not provide 'limit', 'offset' or 'order'.`)
870 }
871
872 func (s *FederationSuite) TestListMultiRemoteContainerOffsetError(c *check.C) {
873         req := httptest.NewRequest("GET", fmt.Sprintf("/arvados/v1/containers?count=none&filters=%s&offset=1",
874                 url.QueryEscape(fmt.Sprintf(`[["uuid", "in", ["%v", "zhome-xvhdp-cr5queuedcontnr"]]]`,
875                         arvadostest.QueuedContainerUUID))),
876                 nil)
877         req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
878         resp := s.testRequest(req).Result()
879         c.Check(resp.StatusCode, check.Equals, http.StatusBadRequest)
880         s.checkJSONErrorMatches(c, resp, `Federated multi-object may not provide 'limit', 'offset' or 'order'.`)
881 }
882
883 func (s *FederationSuite) TestListMultiRemoteContainerOrderError(c *check.C) {
884         req := httptest.NewRequest("GET", fmt.Sprintf("/arvados/v1/containers?count=none&filters=%s&order=uuid",
885                 url.QueryEscape(fmt.Sprintf(`[["uuid", "in", ["%v", "zhome-xvhdp-cr5queuedcontnr"]]]`,
886                         arvadostest.QueuedContainerUUID))),
887                 nil)
888         req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
889         resp := s.testRequest(req).Result()
890         c.Check(resp.StatusCode, check.Equals, http.StatusBadRequest)
891         s.checkJSONErrorMatches(c, resp, `Federated multi-object may not provide 'limit', 'offset' or 'order'.`)
892 }
893
894 func (s *FederationSuite) TestListMultiRemoteContainerSelectError(c *check.C) {
895         req := httptest.NewRequest("GET", fmt.Sprintf("/arvados/v1/containers?count=none&filters=%s&select=%s",
896                 url.QueryEscape(fmt.Sprintf(`[["uuid", "in", ["%v", "zhome-xvhdp-cr5queuedcontnr"]]]`,
897                         arvadostest.QueuedContainerUUID)),
898                 url.QueryEscape(`["command"]`)),
899                 nil)
900         req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
901         resp := s.testRequest(req).Result()
902         c.Check(resp.StatusCode, check.Equals, http.StatusBadRequest)
903         s.checkJSONErrorMatches(c, resp, `Federated multi-object request must include 'uuid' in 'select'`)
904 }