1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
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"
28 // Gocheck boilerplate
29 var _ = check.Suite(&FederationSuite{})
31 type FederationSuite struct {
33 // testServer and testHandler are the controller being tested,
35 testServer *httpserver.Server
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
46 func (s *FederationSuite) SetUpTest(c *check.C) {
48 s.log.Formatter = &logrus.JSONFormatter{}
49 s.log.Out = &logWriter{c.Log}
51 s.remoteServer = newServerFromIntegrationTestEnv(c)
52 c.Assert(s.remoteServer.Start(), check.IsNil)
54 s.remoteMock = newServerFromIntegrationTestEnv(c)
55 s.remoteMock.Server.Handler = http.HandlerFunc(s.remoteMockHandler)
56 c.Assert(s.remoteMock.Start(), check.IsNil)
58 nodeProfile := arvados.NodeProfile{
59 Controller: arvados.SystemServiceInstance{Listen: ":"},
60 RailsAPI: arvados.SystemServiceInstance{Listen: ":1"}, // local reqs will error "connection refused"
62 s.testHandler = &Handler{Cluster: &arvados.Cluster{
64 PostgreSQL: integrationTestCluster().PostgreSQL,
65 NodeProfiles: map[string]arvados.NodeProfile{
68 RequestLimits: arvados.RequestLimits{
69 MaxItemsPerResponse: 1000,
70 MultiClusterRequestConcurrency: 4,
72 }, NodeProfile: &nodeProfile}
73 s.testServer = newServerFromIntegrationTestEnv(c)
74 s.testServer.Server.Handler = httpserver.AddRequestIDs(httpserver.LogRequests(s.log, s.testHandler))
76 s.testHandler.Cluster.RemoteClusters = map[string]arvados.RemoteCluster{
78 Host: s.remoteServer.Addr,
83 Host: s.remoteMock.Addr,
89 c.Assert(s.testServer.Start(), check.IsNil)
91 s.remoteMockRequests = nil
94 func (s *FederationSuite) remoteMockHandler(w http.ResponseWriter, req *http.Request) {
98 req.Body = ioutil.NopCloser(b)
99 s.remoteMockRequests = append(s.remoteMockRequests, *req)
102 func (s *FederationSuite) TearDownTest(c *check.C) {
103 if s.remoteServer != nil {
104 s.remoteServer.Close()
106 if s.testServer != nil {
111 func (s *FederationSuite) testRequest(req *http.Request) *http.Response {
112 resp := httptest.NewRecorder()
113 s.testServer.Server.Handler.ServeHTTP(resp, req)
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)
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`)
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`)
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`)
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`)
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`)
163 func (s *FederationSuite) TestRemoteError(c *check.C) {
164 rc := s.testHandler.Cluster.RemoteClusters["zzzzz"]
166 s.testHandler.Cluster.RemoteClusters["zzzzz"] = rc
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`)
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)
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+".*")
198 for _, method := range []string{"GET", "HEAD", "PUT", "POST", "DELETE"} {
199 c.Check(resp.Header.Get("Access-Control-Allow-Methods"), check.Matches, ".*"+method+".*")
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)
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")
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)
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")
226 func (s *FederationSuite) TestRemoteTokenNotSalted(c *check.C) {
227 // remoteToken can be any v1 token that doesn't appear in
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)
233 c.Assert(s.remoteMockRequests, check.HasLen, 1)
234 pr := s.remoteMockRequests[0]
235 c.Check(pr.Header.Get("Authorization"), check.Equals, "Bearer "+remoteToken)
238 func (s *FederationSuite) TestWorkflowCRUD(c *check.C) {
239 wf := arvados.Workflow{
240 Description: "TestCRUD",
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()},
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
253 s.checkResponseOK(c, resp)
254 json.NewDecoder(resp.Body).Decode(&wf)
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)
261 c.Check(wf.UUID, check.Not(check.Equals), "")
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)
267 for _, method := range []string{"PATCH", "PUT", "POST"} {
269 "workflow": {`{"description": "Updated with ` + method + `"}`},
271 if method == "POST" {
272 form["_method"] = []string{"PATCH"}
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)
282 c.Check(wf.Description, check.Equals, "Updated with "+method)
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)
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)
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)
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)
316 func (s *FederationSuite) localServiceHandler(c *check.C, h http.Handler) *httpserver.Server {
317 srv := &httpserver.Server{
323 c.Assert(srv.Start(), check.IsNil)
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
335 func (s *FederationSuite) localServiceReturns404(c *check.C) *httpserver.Server {
336 return s.localServiceHandler(c, http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
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
352 req := httptest.NewRequest("GET", "/arvados/v1/collections/"+arvadostest.UserAgreementCollection, nil)
353 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
354 resp := s.testRequest(req)
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
364 // HTTP POST with _method=GET as a form parameter
366 req = httptest.NewRequest("POST", "/arvados/v1/collections/"+arvadostest.UserAgreementCollection, bytes.NewBufferString((url.Values{
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)
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
382 func (s *FederationSuite) TestGetRemoteCollection(c *check.C) {
383 defer s.localServiceReturns404(c).Close()
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
397 func (s *FederationSuite) TestGetRemoteCollectionError(c *check.C) {
398 defer s.localServiceReturns404(c).Close()
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)
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`),
410 []string{"6a4ff0499484c6c79c95cd8c566bd25f+249025+B1+C2+A05227438989d04712ea9ca1c91b556cef01d5cc7@5ba5405b+D3+E4",
411 "6a4ff0499484c6c79c95cd8c566bd25f",
414 "+A05227438989d04712ea9ca1c91b556cef01d5cc7@5ba5405b",
415 "05227438989d04712ea9ca1c91b556cef01d5cc7", "5ba5405b",
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
427 req := httptest.NewRequest("GET", "/arvados/v1/collections/"+arvadostest.UserAgreementPDH, nil)
428 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
429 resp := s.testRequest(req)
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
440 func (s *FederationSuite) TestGetRemoteCollectionByPDH(c *check.C) {
441 defer s.localServiceReturns404(c).Close()
443 req := httptest.NewRequest("GET", "/arvados/v1/collections/"+arvadostest.UserAgreementPDH, nil)
444 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
445 resp := s.testRequest(req)
447 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
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
457 func (s *FederationSuite) TestGetCollectionByPDHError(c *check.C) {
458 defer s.localServiceReturns404(c).Close()
460 req := httptest.NewRequest("GET", "/arvados/v1/collections/99999999999999999999999999999999+99", nil)
461 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
463 resp := s.testRequest(req)
464 defer resp.Body.Close()
466 c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)
469 func (s *FederationSuite) TestGetCollectionByPDHErrorBadHash(c *check.C) {
470 defer s.localServiceReturns404(c).Close()
472 srv2 := &httpserver.Server{
474 Handler: http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
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
483 enc := json.NewEncoder(w)
489 c.Assert(srv2.Start(), check.IsNil)
492 // Direct zzzzz to service that returns a 200 result with a bogus manifest_text
493 s.testHandler.Cluster.RemoteClusters["zzzzz"] = arvados.RemoteCluster{
499 req := httptest.NewRequest("GET", "/arvados/v1/collections/99999999999999999999999999999999+99", nil)
500 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
502 resp := s.testRequest(req)
503 defer resp.Body.Close()
505 c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)
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
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)
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
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
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)
541 c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)
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)
556 func (s *FederationSuite) TestUpdateRemoteContainerRequest(c *check.C) {
557 defer s.localServiceReturns404(c).Close()
558 req := httptest.NewRequest("PATCH", "/arvados/v1/container_requests/"+arvadostest.QueuedContainerRequestUUID,
559 strings.NewReader(`{"container_request": {"priority": 696}}`))
560 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
561 req.Header.Set("Content-type", "application/json")
562 resp := s.testRequest(req)
563 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
564 var cr arvados.ContainerRequest
565 c.Check(json.NewDecoder(resp.Body).Decode(&cr), check.IsNil)
566 c.Check(cr.UUID, check.Equals, arvadostest.QueuedContainerRequestUUID)
567 c.Check(cr.Priority, check.Equals, 696)
570 func (s *FederationSuite) TestCreateRemoteContainerRequest(c *check.C) {
571 defer s.localServiceReturns404(c).Close()
572 // pass cluster_id via query parameter, this allows arvados-controller
573 // to avoid parsing the body
574 req := httptest.NewRequest("POST", "/arvados/v1/container_requests?cluster_id=zzzzz",
576 "container_request": {
577 "name": "hello world",
578 "state": "Uncommitted",
580 "container_image": "123",
585 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
586 req.Header.Set("Content-type", "application/json")
587 resp := s.testRequest(req)
588 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
589 var cr arvados.ContainerRequest
590 c.Check(json.NewDecoder(resp.Body).Decode(&cr), check.IsNil)
591 c.Check(cr.Name, check.Equals, "hello world")
592 c.Check(strings.HasPrefix(cr.UUID, "zzzzz-"), check.Equals, true)
595 func (s *FederationSuite) TestCreateRemoteContainerRequestCheckRuntimeToken(c *check.C) {
596 // Send request to zmock and check that outgoing request has
597 // runtime_token set with a new random v2 token.
599 defer s.localServiceReturns404(c).Close()
600 // pass cluster_id via query parameter, this allows arvados-controller
601 // to avoid parsing the body
602 req := httptest.NewRequest("POST", "/arvados/v1/container_requests?cluster_id=zmock",
604 "container_request": {
605 "name": "hello world",
606 "state": "Uncommitted",
608 "container_image": "123",
613 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveTokenV2)
614 req.Header.Set("Content-type", "application/json")
616 np := arvados.NodeProfile{
617 Controller: arvados.SystemServiceInstance{Listen: ":"},
618 RailsAPI: arvados.SystemServiceInstance{Listen: os.Getenv("ARVADOS_TEST_API_HOST"),
619 TLS: true, Insecure: true}}
620 s.testHandler.Cluster.ClusterID = "zzzzz"
621 s.testHandler.Cluster.NodeProfiles["*"] = np
622 s.testHandler.NodeProfile = &np
624 resp := s.testRequest(req)
625 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
627 arvados.ContainerRequest `json:"container_request"`
629 c.Check(json.NewDecoder(s.remoteMockRequests[0].Body).Decode(&cr), check.IsNil)
630 c.Check(strings.HasPrefix(cr.ContainerRequest.RuntimeToken, "v2/zzzzz-gj3su-"), check.Equals, true)
631 c.Check(cr.ContainerRequest.RuntimeToken, check.Not(check.Equals), arvadostest.ActiveTokenV2)
634 func (s *FederationSuite) TestCreateRemoteContainerRequestCheckSetRuntimeToken(c *check.C) {
635 // Send request to zmock and check that outgoing request has
636 // runtime_token set with the explicitly provided token.
638 defer s.localServiceReturns404(c).Close()
639 // pass cluster_id via query parameter, this allows arvados-controller
640 // to avoid parsing the body
641 req := httptest.NewRequest("POST", "/arvados/v1/container_requests?cluster_id=zmock",
643 "container_request": {
644 "name": "hello world",
645 "state": "Uncommitted",
647 "container_image": "123",
649 "runtime_token": "xyz"
653 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
654 req.Header.Set("Content-type", "application/json")
655 resp := s.testRequest(req)
656 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
658 arvados.ContainerRequest `json:"container_request"`
660 c.Check(json.NewDecoder(s.remoteMockRequests[0].Body).Decode(&cr), check.IsNil)
661 c.Check(cr.ContainerRequest.RuntimeToken, check.Equals, "xyz")
664 func (s *FederationSuite) TestCreateRemoteContainerRequestRuntimeTokenFromAuth(c *check.C) {
665 // Send request to zmock and check that outgoing request has
666 // runtime_token set using the Auth token because the user is remote.
668 defer s.localServiceReturns404(c).Close()
669 // pass cluster_id via query parameter, this allows arvados-controller
670 // to avoid parsing the body
671 req := httptest.NewRequest("POST", "/arvados/v1/container_requests?cluster_id=zmock",
673 "container_request": {
674 "name": "hello world",
675 "state": "Uncommitted",
677 "container_image": "123",
682 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveTokenV2+"/zzzzz-dz642-parentcontainer")
683 req.Header.Set("Content-type", "application/json")
684 resp := s.testRequest(req)
685 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
687 arvados.ContainerRequest `json:"container_request"`
689 c.Check(json.NewDecoder(s.remoteMockRequests[0].Body).Decode(&cr), check.IsNil)
690 c.Check(cr.ContainerRequest.RuntimeToken, check.Equals, arvadostest.ActiveTokenV2)
693 func (s *FederationSuite) TestCreateRemoteContainerRequestError(c *check.C) {
694 defer s.localServiceReturns404(c).Close()
695 // pass cluster_id via query parameter, this allows arvados-controller
696 // to avoid parsing the body
697 req := httptest.NewRequest("POST", "/arvados/v1/container_requests?cluster_id=zz404",
699 "container_request": {
700 "name": "hello world",
701 "state": "Uncommitted",
703 "container_image": "123",
708 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
709 req.Header.Set("Content-type", "application/json")
710 resp := s.testRequest(req)
711 c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)
714 func (s *FederationSuite) TestGetRemoteContainer(c *check.C) {
715 defer s.localServiceReturns404(c).Close()
716 req := httptest.NewRequest("GET", "/arvados/v1/containers/"+arvadostest.QueuedContainerUUID, nil)
717 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
718 resp := s.testRequest(req)
719 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
720 var cn arvados.Container
721 c.Check(json.NewDecoder(resp.Body).Decode(&cn), check.IsNil)
722 c.Check(cn.UUID, check.Equals, arvadostest.QueuedContainerUUID)
725 func (s *FederationSuite) TestListRemoteContainer(c *check.C) {
726 defer s.localServiceReturns404(c).Close()
727 req := httptest.NewRequest("GET", "/arvados/v1/containers?count=none&filters="+
728 url.QueryEscape(fmt.Sprintf(`[["uuid", "in", ["%v"]]]`, arvadostest.QueuedContainerUUID)), nil)
729 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
730 resp := s.testRequest(req)
731 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
732 var cn arvados.ContainerList
733 c.Check(json.NewDecoder(resp.Body).Decode(&cn), check.IsNil)
734 c.Check(cn.Items[0].UUID, check.Equals, arvadostest.QueuedContainerUUID)
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`)
742 w.Write([]byte(`{"kind": "arvados#containerList", "items": [{"uuid": "zhome-xvhdp-cr5queuedcontnr", "command": ["abc"]}]}`))
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"]`)),
749 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
750 resp := s.testRequest(req)
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 {
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, "")
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"]`)),
772 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
773 resp := s.testRequest(req)
774 c.Check(resp.StatusCode, check.Equals, http.StatusBadGateway)
775 s.checkJSONErrorMatches(c, resp, `error fetching from zhome \(404 Not Found\): EOF`)
778 func (s *FederationSuite) TestListMultiRemoteContainersPaged(c *check.C) {
781 defer s.localServiceHandler(c, http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
782 bd, _ := ioutil.ReadAll(req.Body)
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`)
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`)
790 w.Write([]byte(`{"kind": "arvados#containerList", "items": [{"uuid": "zhome-xvhdp-cr6queuedcontnr", "command": ["efg"]}]}`))
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))),
798 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
799 resp := s.testRequest(req)
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 {
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"})
814 func (s *FederationSuite) TestListMultiRemoteContainersMissing(c *check.C) {
817 defer s.localServiceHandler(c, http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
818 bd, _ := ioutil.ReadAll(req.Body)
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`)
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`)
826 w.Write([]byte(`{"kind": "arvados#containerList", "items": []}`))
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))),
834 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
835 resp := s.testRequest(req)
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 {
845 c.Check(mp[arvadostest.QueuedContainerUUID].Command, check.DeepEquals, []string{"echo", "hello"})
846 c.Check(mp["zhome-xvhdp-cr6queuedcontnr"].Command, check.DeepEquals, []string{"efg"})
849 func (s *FederationSuite) TestListMultiRemoteContainerPageSizeError(c *check.C) {
850 s.testHandler.Cluster.RequestLimits.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))),
855 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
856 resp := s.testRequest(req)
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.`)
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))),
866 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
867 resp := s.testRequest(req)
868 c.Check(resp.StatusCode, check.Equals, http.StatusBadRequest)
869 s.checkJSONErrorMatches(c, resp, `Federated multi-object may not provide 'limit', 'offset' or 'order'.`)
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))),
877 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
878 resp := s.testRequest(req)
879 c.Check(resp.StatusCode, check.Equals, http.StatusBadRequest)
880 s.checkJSONErrorMatches(c, resp, `Federated multi-object may not provide 'limit', 'offset' or 'order'.`)
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))),
888 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
889 resp := s.testRequest(req)
890 c.Check(resp.StatusCode, check.Equals, http.StatusBadRequest)
891 s.checkJSONErrorMatches(c, resp, `Federated multi-object may not provide 'limit', 'offset' or 'order'.`)
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"]`)),
900 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
901 resp := s.testRequest(req)
902 c.Check(resp.StatusCode, check.Equals, http.StatusBadRequest)
903 s.checkJSONErrorMatches(c, resp, `Federated multi-object request must include 'uuid' in 'select'`)