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