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/ctxlog"
23 "git.curoverse.com/arvados.git/sdk/go/httpserver"
24 "git.curoverse.com/arvados.git/sdk/go/keepclient"
25 "github.com/sirupsen/logrus"
26 check "gopkg.in/check.v1"
29 // Gocheck boilerplate
30 var _ = check.Suite(&FederationSuite{})
32 type FederationSuite struct {
33 log logrus.FieldLogger
34 // testServer and testHandler are the controller being tested,
36 testServer *httpserver.Server
38 // remoteServer ("zzzzz") forwards requests to the Rails API
39 // provided by the integration test environment.
40 remoteServer *httpserver.Server
41 // remoteMock ("zmock") appends each incoming request to
42 // remoteMockRequests, and returns an empty 200 response.
43 remoteMock *httpserver.Server
44 remoteMockRequests []http.Request
47 func (s *FederationSuite) SetUpTest(c *check.C) {
48 s.log = ctxlog.TestLogger(c)
50 s.remoteServer = newServerFromIntegrationTestEnv(c)
51 c.Assert(s.remoteServer.Start(), check.IsNil)
53 s.remoteMock = newServerFromIntegrationTestEnv(c)
54 s.remoteMock.Server.Handler = http.HandlerFunc(s.remoteMockHandler)
55 c.Assert(s.remoteMock.Start(), check.IsNil)
57 nodeProfile := arvados.NodeProfile{
58 Controller: arvados.SystemServiceInstance{Listen: ":"},
59 RailsAPI: arvados.SystemServiceInstance{Listen: ":1"}, // local reqs will error "connection refused"
61 s.testHandler = &Handler{Cluster: &arvados.Cluster{
63 PostgreSQL: integrationTestCluster().PostgreSQL,
64 NodeProfiles: map[string]arvados.NodeProfile{
67 RequestLimits: arvados.RequestLimits{
68 MaxItemsPerResponse: 1000,
69 MultiClusterRequestConcurrency: 4,
71 }, NodeProfile: &nodeProfile}
72 s.testServer = newServerFromIntegrationTestEnv(c)
73 s.testServer.Server.Handler = httpserver.AddRequestIDs(httpserver.LogRequests(s.log, s.testHandler))
75 s.testHandler.Cluster.RemoteClusters = map[string]arvados.RemoteCluster{
77 Host: s.remoteServer.Addr,
82 Host: s.remoteMock.Addr,
88 c.Assert(s.testServer.Start(), check.IsNil)
90 s.remoteMockRequests = nil
93 func (s *FederationSuite) remoteMockHandler(w http.ResponseWriter, req *http.Request) {
97 req.Body = ioutil.NopCloser(b)
98 s.remoteMockRequests = append(s.remoteMockRequests, *req)
101 func (s *FederationSuite) TearDownTest(c *check.C) {
102 if s.remoteServer != nil {
103 s.remoteServer.Close()
105 if s.testServer != nil {
110 func (s *FederationSuite) testRequest(req *http.Request) *http.Response {
111 resp := httptest.NewRecorder()
112 s.testServer.Server.Handler.ServeHTTP(resp, req)
116 func (s *FederationSuite) TestLocalRequest(c *check.C) {
117 req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+strings.Replace(arvadostest.WorkflowWithDefinitionYAMLUUID, "zzzzz-", "zhome-", 1), nil)
118 resp := s.testRequest(req)
119 s.checkHandledLocally(c, resp)
122 func (s *FederationSuite) checkHandledLocally(c *check.C, resp *http.Response) {
123 // Our "home" controller can't handle local requests because
124 // it doesn't have its own stub/test Rails API, so we rely on
125 // "connection refused" to indicate the controller tried to
126 // proxy the request to its local Rails API.
127 c.Check(resp.StatusCode, check.Equals, http.StatusBadGateway)
128 s.checkJSONErrorMatches(c, resp, `.*connection refused`)
131 func (s *FederationSuite) TestNoAuth(c *check.C) {
132 req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+arvadostest.WorkflowWithDefinitionYAMLUUID, nil)
133 resp := s.testRequest(req)
134 c.Check(resp.StatusCode, check.Equals, http.StatusUnauthorized)
135 s.checkJSONErrorMatches(c, resp, `Not logged in`)
138 func (s *FederationSuite) TestBadAuth(c *check.C) {
139 req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+arvadostest.WorkflowWithDefinitionYAMLUUID, nil)
140 req.Header.Set("Authorization", "Bearer aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
141 resp := s.testRequest(req)
142 c.Check(resp.StatusCode, check.Equals, http.StatusUnauthorized)
143 s.checkJSONErrorMatches(c, resp, `Not logged in`)
146 func (s *FederationSuite) TestNoAccess(c *check.C) {
147 req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+arvadostest.WorkflowWithDefinitionYAMLUUID, nil)
148 req.Header.Set("Authorization", "Bearer "+arvadostest.SpectatorToken)
149 resp := s.testRequest(req)
150 c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)
151 s.checkJSONErrorMatches(c, resp, `.*not found`)
154 func (s *FederationSuite) TestGetUnknownRemote(c *check.C) {
155 req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+strings.Replace(arvadostest.WorkflowWithDefinitionYAMLUUID, "zzzzz-", "zz404-", 1), nil)
156 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
157 resp := s.testRequest(req)
158 c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)
159 s.checkJSONErrorMatches(c, resp, `.*no proxy available for cluster zz404`)
162 func (s *FederationSuite) TestRemoteError(c *check.C) {
163 rc := s.testHandler.Cluster.RemoteClusters["zzzzz"]
165 s.testHandler.Cluster.RemoteClusters["zzzzz"] = rc
167 req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+arvadostest.WorkflowWithDefinitionYAMLUUID, nil)
168 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
169 resp := s.testRequest(req)
170 c.Check(resp.StatusCode, check.Equals, http.StatusBadGateway)
171 s.checkJSONErrorMatches(c, resp, `.*HTTP response to HTTPS client`)
174 func (s *FederationSuite) TestGetRemoteWorkflow(c *check.C) {
175 req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+arvadostest.WorkflowWithDefinitionYAMLUUID, nil)
176 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
177 resp := s.testRequest(req)
178 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
179 var wf arvados.Workflow
180 c.Check(json.NewDecoder(resp.Body).Decode(&wf), check.IsNil)
181 c.Check(wf.UUID, check.Equals, arvadostest.WorkflowWithDefinitionYAMLUUID)
182 c.Check(wf.OwnerUUID, check.Equals, arvadostest.ActiveUserUUID)
185 func (s *FederationSuite) TestOptionsMethod(c *check.C) {
186 req := httptest.NewRequest("OPTIONS", "/arvados/v1/workflows/"+arvadostest.WorkflowWithDefinitionYAMLUUID, nil)
187 req.Header.Set("Origin", "https://example.com")
188 resp := s.testRequest(req)
189 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
190 body, err := ioutil.ReadAll(resp.Body)
191 c.Check(err, check.IsNil)
192 c.Check(string(body), check.Equals, "")
193 c.Check(resp.Header.Get("Access-Control-Allow-Origin"), check.Equals, "*")
194 for _, hdr := range []string{"Authorization", "Content-Type"} {
195 c.Check(resp.Header.Get("Access-Control-Allow-Headers"), check.Matches, ".*"+hdr+".*")
197 for _, method := range []string{"GET", "HEAD", "PUT", "POST", "DELETE"} {
198 c.Check(resp.Header.Get("Access-Control-Allow-Methods"), check.Matches, ".*"+method+".*")
202 func (s *FederationSuite) TestRemoteWithTokenInQuery(c *check.C) {
203 req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+strings.Replace(arvadostest.WorkflowWithDefinitionYAMLUUID, "zzzzz-", "zmock-", 1)+"?api_token="+arvadostest.ActiveToken, nil)
205 c.Assert(s.remoteMockRequests, check.HasLen, 1)
206 pr := s.remoteMockRequests[0]
207 // Token is salted and moved from query to Authorization header.
208 c.Check(pr.URL.String(), check.Not(check.Matches), `.*api_token=.*`)
209 c.Check(pr.Header.Get("Authorization"), check.Equals, "Bearer v2/zzzzz-gj3su-077z32aux8dg2s1/7fd31b61f39c0e82a4155592163218272cedacdc")
212 func (s *FederationSuite) TestLocalTokenSalted(c *check.C) {
213 req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+strings.Replace(arvadostest.WorkflowWithDefinitionYAMLUUID, "zzzzz-", "zmock-", 1), nil)
214 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
216 c.Assert(s.remoteMockRequests, check.HasLen, 1)
217 pr := s.remoteMockRequests[0]
218 // The salted token here has a "zzzzz-" UUID instead of a
219 // "ztest-" UUID because ztest's local database has the
220 // "zzzzz-" test fixtures. The "secret" part is HMAC(sha1,
221 // arvadostest.ActiveToken, "zmock") = "7fd3...".
222 c.Check(pr.Header.Get("Authorization"), check.Equals, "Bearer v2/zzzzz-gj3su-077z32aux8dg2s1/7fd31b61f39c0e82a4155592163218272cedacdc")
225 func (s *FederationSuite) TestRemoteTokenNotSalted(c *check.C) {
226 // remoteToken can be any v1 token that doesn't appear in
228 remoteToken := "abcdef00000000000000000000000000000000000000000000"
229 req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+strings.Replace(arvadostest.WorkflowWithDefinitionYAMLUUID, "zzzzz-", "zmock-", 1), nil)
230 req.Header.Set("Authorization", "Bearer "+remoteToken)
232 c.Assert(s.remoteMockRequests, check.HasLen, 1)
233 pr := s.remoteMockRequests[0]
234 c.Check(pr.Header.Get("Authorization"), check.Equals, "Bearer "+remoteToken)
237 func (s *FederationSuite) TestWorkflowCRUD(c *check.C) {
238 wf := arvados.Workflow{
239 Description: "TestCRUD",
242 body := &strings.Builder{}
243 json.NewEncoder(body).Encode(&wf)
244 req := httptest.NewRequest("POST", "/arvados/v1/workflows", strings.NewReader(url.Values{
245 "workflow": {body.String()},
247 req.Header.Set("Content-type", "application/x-www-form-urlencoded")
248 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
249 rec := httptest.NewRecorder()
250 s.remoteServer.Server.Handler.ServeHTTP(rec, req) // direct to remote -- can't proxy a create req because no uuid
252 s.checkResponseOK(c, resp)
253 json.NewDecoder(resp.Body).Decode(&wf)
256 req := httptest.NewRequest("DELETE", "/arvados/v1/workflows/"+wf.UUID, nil)
257 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
258 s.remoteServer.Server.Handler.ServeHTTP(httptest.NewRecorder(), req)
260 c.Check(wf.UUID, check.Not(check.Equals), "")
262 c.Assert(wf.ModifiedAt, check.NotNil)
263 c.Logf("wf.ModifiedAt: %v", wf.ModifiedAt)
264 c.Check(time.Since(*wf.ModifiedAt) < time.Minute, check.Equals, true)
266 for _, method := range []string{"PATCH", "PUT", "POST"} {
268 "workflow": {`{"description": "Updated with ` + method + `"}`},
270 if method == "POST" {
271 form["_method"] = []string{"PATCH"}
273 req := httptest.NewRequest(method, "/arvados/v1/workflows/"+wf.UUID, strings.NewReader(form.Encode()))
274 req.Header.Set("Content-type", "application/x-www-form-urlencoded")
275 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
276 resp := s.testRequest(req)
277 s.checkResponseOK(c, resp)
278 err := json.NewDecoder(resp.Body).Decode(&wf)
279 c.Check(err, check.IsNil)
281 c.Check(wf.Description, check.Equals, "Updated with "+method)
284 req := httptest.NewRequest("DELETE", "/arvados/v1/workflows/"+wf.UUID, nil)
285 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
286 resp := s.testRequest(req)
287 s.checkResponseOK(c, resp)
288 err := json.NewDecoder(resp.Body).Decode(&wf)
289 c.Check(err, check.IsNil)
292 req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+wf.UUID, nil)
293 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
294 resp := s.testRequest(req)
295 c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)
299 func (s *FederationSuite) checkResponseOK(c *check.C, resp *http.Response) {
300 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
301 if resp.StatusCode != http.StatusOK {
302 body, err := ioutil.ReadAll(resp.Body)
303 c.Logf("... response body = %q, %v\n", body, err)
307 func (s *FederationSuite) checkJSONErrorMatches(c *check.C, resp *http.Response, re string) {
308 var jresp httpserver.ErrorResponse
309 err := json.NewDecoder(resp.Body).Decode(&jresp)
310 c.Check(err, check.IsNil)
311 c.Assert(jresp.Errors, check.HasLen, 1)
312 c.Check(jresp.Errors[0], check.Matches, re)
315 func (s *FederationSuite) localServiceHandler(c *check.C, h http.Handler) *httpserver.Server {
316 srv := &httpserver.Server{
322 c.Assert(srv.Start(), check.IsNil)
324 np := arvados.NodeProfile{
325 Controller: arvados.SystemServiceInstance{Listen: ":"},
326 RailsAPI: arvados.SystemServiceInstance{Listen: srv.Addr,
327 TLS: false, Insecure: true}}
328 s.testHandler.Cluster.NodeProfiles["*"] = np
329 s.testHandler.NodeProfile = &np
334 func (s *FederationSuite) localServiceReturns404(c *check.C) *httpserver.Server {
335 return s.localServiceHandler(c, http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
340 func (s *FederationSuite) TestGetLocalCollection(c *check.C) {
341 np := arvados.NodeProfile{
342 Controller: arvados.SystemServiceInstance{Listen: ":"},
343 RailsAPI: arvados.SystemServiceInstance{Listen: os.Getenv("ARVADOS_TEST_API_HOST"),
344 TLS: true, Insecure: true}}
345 s.testHandler.Cluster.ClusterID = "zzzzz"
346 s.testHandler.Cluster.NodeProfiles["*"] = np
347 s.testHandler.NodeProfile = &np
351 req := httptest.NewRequest("GET", "/arvados/v1/collections/"+arvadostest.UserAgreementCollection, nil)
352 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
353 resp := s.testRequest(req)
355 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
356 var col arvados.Collection
357 c.Check(json.NewDecoder(resp.Body).Decode(&col), check.IsNil)
358 c.Check(col.UUID, check.Equals, arvadostest.UserAgreementCollection)
359 c.Check(col.ManifestText, check.Matches,
360 `\. 6a4ff0499484c6c79c95cd8c566bd25f\+249025\+A[0-9a-f]{40}@[0-9a-f]{8} 0:249025:GNU_General_Public_License,_version_3.pdf
363 // HTTP POST with _method=GET as a form parameter
365 req = httptest.NewRequest("POST", "/arvados/v1/collections/"+arvadostest.UserAgreementCollection, bytes.NewBufferString((url.Values{
368 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
369 req.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
370 resp = s.testRequest(req)
372 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
373 col = arvados.Collection{}
374 c.Check(json.NewDecoder(resp.Body).Decode(&col), check.IsNil)
375 c.Check(col.UUID, check.Equals, arvadostest.UserAgreementCollection)
376 c.Check(col.ManifestText, check.Matches,
377 `\. 6a4ff0499484c6c79c95cd8c566bd25f\+249025\+A[0-9a-f]{40}@[0-9a-f]{8} 0:249025:GNU_General_Public_License,_version_3.pdf
381 func (s *FederationSuite) TestGetRemoteCollection(c *check.C) {
382 defer s.localServiceReturns404(c).Close()
384 req := httptest.NewRequest("GET", "/arvados/v1/collections/"+arvadostest.UserAgreementCollection, nil)
385 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
386 resp := s.testRequest(req)
387 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
388 var col arvados.Collection
389 c.Check(json.NewDecoder(resp.Body).Decode(&col), check.IsNil)
390 c.Check(col.UUID, check.Equals, arvadostest.UserAgreementCollection)
391 c.Check(col.ManifestText, check.Matches,
392 `\. 6a4ff0499484c6c79c95cd8c566bd25f\+249025\+Rzzzzz-[0-9a-f]{40}@[0-9a-f]{8} 0:249025:GNU_General_Public_License,_version_3.pdf
396 func (s *FederationSuite) TestGetRemoteCollectionError(c *check.C) {
397 defer s.localServiceReturns404(c).Close()
399 req := httptest.NewRequest("GET", "/arvados/v1/collections/zzzzz-4zz18-fakefakefakefak", nil)
400 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
401 resp := s.testRequest(req)
402 c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)
405 func (s *FederationSuite) TestSignedLocatorPattern(c *check.C) {
406 // Confirm the regular expression identifies other groups of hints correctly
407 c.Check(keepclient.SignedLocatorRe.FindStringSubmatch(`6a4ff0499484c6c79c95cd8c566bd25f+249025+B1+C2+A05227438989d04712ea9ca1c91b556cef01d5cc7@5ba5405b+D3+E4`),
409 []string{"6a4ff0499484c6c79c95cd8c566bd25f+249025+B1+C2+A05227438989d04712ea9ca1c91b556cef01d5cc7@5ba5405b+D3+E4",
410 "6a4ff0499484c6c79c95cd8c566bd25f",
413 "+A05227438989d04712ea9ca1c91b556cef01d5cc7@5ba5405b",
414 "05227438989d04712ea9ca1c91b556cef01d5cc7", "5ba5405b",
418 func (s *FederationSuite) TestGetLocalCollectionByPDH(c *check.C) {
419 np := arvados.NodeProfile{
420 Controller: arvados.SystemServiceInstance{Listen: ":"},
421 RailsAPI: arvados.SystemServiceInstance{Listen: os.Getenv("ARVADOS_TEST_API_HOST"),
422 TLS: true, Insecure: true}}
423 s.testHandler.Cluster.NodeProfiles["*"] = np
424 s.testHandler.NodeProfile = &np
426 req := httptest.NewRequest("GET", "/arvados/v1/collections/"+arvadostest.UserAgreementPDH, nil)
427 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
428 resp := s.testRequest(req)
430 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
431 var col arvados.Collection
432 c.Check(json.NewDecoder(resp.Body).Decode(&col), check.IsNil)
433 c.Check(col.PortableDataHash, check.Equals, arvadostest.UserAgreementPDH)
434 c.Check(col.ManifestText, check.Matches,
435 `\. 6a4ff0499484c6c79c95cd8c566bd25f\+249025\+A[0-9a-f]{40}@[0-9a-f]{8} 0:249025:GNU_General_Public_License,_version_3.pdf
439 func (s *FederationSuite) TestGetRemoteCollectionByPDH(c *check.C) {
440 defer s.localServiceReturns404(c).Close()
442 req := httptest.NewRequest("GET", "/arvados/v1/collections/"+arvadostest.UserAgreementPDH, nil)
443 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
444 resp := s.testRequest(req)
446 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
448 var col arvados.Collection
449 c.Check(json.NewDecoder(resp.Body).Decode(&col), check.IsNil)
450 c.Check(col.PortableDataHash, check.Equals, arvadostest.UserAgreementPDH)
451 c.Check(col.ManifestText, check.Matches,
452 `\. 6a4ff0499484c6c79c95cd8c566bd25f\+249025\+Rzzzzz-[0-9a-f]{40}@[0-9a-f]{8} 0:249025:GNU_General_Public_License,_version_3.pdf
456 func (s *FederationSuite) TestGetCollectionByPDHError(c *check.C) {
457 defer s.localServiceReturns404(c).Close()
459 req := httptest.NewRequest("GET", "/arvados/v1/collections/99999999999999999999999999999999+99", nil)
460 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
462 resp := s.testRequest(req)
463 defer resp.Body.Close()
465 c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)
468 func (s *FederationSuite) TestGetCollectionByPDHErrorBadHash(c *check.C) {
469 defer s.localServiceReturns404(c).Close()
471 srv2 := &httpserver.Server{
473 Handler: http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
475 // Return a collection where the hash
476 // of the manifest text doesn't match
477 // PDH that was requested.
478 var col arvados.Collection
479 col.PortableDataHash = "99999999999999999999999999999999+99"
480 col.ManifestText = `. 6a4ff0499484c6c79c95cd8c566bd25f\+249025 0:249025:GNU_General_Public_License,_version_3.pdf
482 enc := json.NewEncoder(w)
488 c.Assert(srv2.Start(), check.IsNil)
491 // Direct zzzzz to service that returns a 200 result with a bogus manifest_text
492 s.testHandler.Cluster.RemoteClusters["zzzzz"] = arvados.RemoteCluster{
498 req := httptest.NewRequest("GET", "/arvados/v1/collections/99999999999999999999999999999999+99", nil)
499 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
501 resp := s.testRequest(req)
502 defer resp.Body.Close()
504 c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)
507 func (s *FederationSuite) TestSaltedTokenGetCollectionByPDH(c *check.C) {
508 np := arvados.NodeProfile{
509 Controller: arvados.SystemServiceInstance{Listen: ":"},
510 RailsAPI: arvados.SystemServiceInstance{Listen: os.Getenv("ARVADOS_TEST_API_HOST"),
511 TLS: true, Insecure: true}}
512 s.testHandler.Cluster.NodeProfiles["*"] = np
513 s.testHandler.NodeProfile = &np
515 req := httptest.NewRequest("GET", "/arvados/v1/collections/"+arvadostest.UserAgreementPDH, nil)
516 req.Header.Set("Authorization", "Bearer v2/zzzzz-gj3su-077z32aux8dg2s1/282d7d172b6cfdce364c5ed12ddf7417b2d00065")
517 resp := s.testRequest(req)
519 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
520 var col arvados.Collection
521 c.Check(json.NewDecoder(resp.Body).Decode(&col), check.IsNil)
522 c.Check(col.PortableDataHash, check.Equals, arvadostest.UserAgreementPDH)
523 c.Check(col.ManifestText, check.Matches,
524 `\. 6a4ff0499484c6c79c95cd8c566bd25f\+249025\+A[0-9a-f]{40}@[0-9a-f]{8} 0:249025:GNU_General_Public_License,_version_3.pdf
528 func (s *FederationSuite) TestSaltedTokenGetCollectionByPDHError(c *check.C) {
529 np := arvados.NodeProfile{
530 Controller: arvados.SystemServiceInstance{Listen: ":"},
531 RailsAPI: arvados.SystemServiceInstance{Listen: os.Getenv("ARVADOS_TEST_API_HOST"),
532 TLS: true, Insecure: true}}
533 s.testHandler.Cluster.NodeProfiles["*"] = np
534 s.testHandler.NodeProfile = &np
536 req := httptest.NewRequest("GET", "/arvados/v1/collections/99999999999999999999999999999999+99", nil)
537 req.Header.Set("Authorization", "Bearer v2/zzzzz-gj3su-077z32aux8dg2s1/282d7d172b6cfdce364c5ed12ddf7417b2d00065")
538 resp := s.testRequest(req)
540 c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)
543 func (s *FederationSuite) TestGetRemoteContainerRequest(c *check.C) {
544 defer s.localServiceReturns404(c).Close()
545 req := httptest.NewRequest("GET", "/arvados/v1/container_requests/"+arvadostest.QueuedContainerRequestUUID, nil)
546 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
547 resp := s.testRequest(req)
548 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
549 var cr arvados.ContainerRequest
550 c.Check(json.NewDecoder(resp.Body).Decode(&cr), check.IsNil)
551 c.Check(cr.UUID, check.Equals, arvadostest.QueuedContainerRequestUUID)
552 c.Check(cr.Priority, check.Equals, 1)
555 func (s *FederationSuite) TestUpdateRemoteContainerRequest(c *check.C) {
556 defer s.localServiceReturns404(c).Close()
557 setPri := func(pri int) {
558 req := httptest.NewRequest("PATCH", "/arvados/v1/container_requests/"+arvadostest.QueuedContainerRequestUUID,
559 strings.NewReader(fmt.Sprintf(`{"container_request": {"priority": %d}}`, pri)))
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, pri)
570 setPri(1) // Reset fixture so side effect doesn't break other tests.
573 func (s *FederationSuite) TestCreateRemoteContainerRequest(c *check.C) {
574 defer s.localServiceReturns404(c).Close()
575 // pass cluster_id via query parameter, this allows arvados-controller
576 // to avoid parsing the body
577 req := httptest.NewRequest("POST", "/arvados/v1/container_requests?cluster_id=zzzzz",
579 "container_request": {
580 "name": "hello world",
581 "state": "Uncommitted",
583 "container_image": "123",
588 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
589 req.Header.Set("Content-type", "application/json")
590 resp := s.testRequest(req)
591 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
592 var cr arvados.ContainerRequest
593 c.Check(json.NewDecoder(resp.Body).Decode(&cr), check.IsNil)
594 c.Check(cr.Name, check.Equals, "hello world")
595 c.Check(strings.HasPrefix(cr.UUID, "zzzzz-"), check.Equals, true)
598 func (s *FederationSuite) TestCreateRemoteContainerRequestCheckRuntimeToken(c *check.C) {
599 // Send request to zmock and check that outgoing request has
600 // runtime_token set with a new random v2 token.
602 defer s.localServiceReturns404(c).Close()
603 // pass cluster_id via query parameter, this allows arvados-controller
604 // to avoid parsing the body
605 req := httptest.NewRequest("POST", "/arvados/v1/container_requests?cluster_id=zmock",
607 "container_request": {
608 "name": "hello world",
609 "state": "Uncommitted",
611 "container_image": "123",
616 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveTokenV2)
617 req.Header.Set("Content-type", "application/json")
619 np := arvados.NodeProfile{
620 Controller: arvados.SystemServiceInstance{Listen: ":"},
621 RailsAPI: arvados.SystemServiceInstance{Listen: os.Getenv("ARVADOS_TEST_API_HOST"),
622 TLS: true, Insecure: true}}
623 s.testHandler.Cluster.ClusterID = "zzzzz"
624 s.testHandler.Cluster.NodeProfiles["*"] = np
625 s.testHandler.NodeProfile = &np
627 resp := s.testRequest(req)
628 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
630 arvados.ContainerRequest `json:"container_request"`
632 c.Check(json.NewDecoder(s.remoteMockRequests[0].Body).Decode(&cr), check.IsNil)
633 c.Check(strings.HasPrefix(cr.ContainerRequest.RuntimeToken, "v2/zzzzz-gj3su-"), check.Equals, true)
634 c.Check(cr.ContainerRequest.RuntimeToken, check.Not(check.Equals), arvadostest.ActiveTokenV2)
637 func (s *FederationSuite) TestCreateRemoteContainerRequestCheckSetRuntimeToken(c *check.C) {
638 // Send request to zmock and check that outgoing request has
639 // runtime_token set with the explicitly provided token.
641 defer s.localServiceReturns404(c).Close()
642 // pass cluster_id via query parameter, this allows arvados-controller
643 // to avoid parsing the body
644 req := httptest.NewRequest("POST", "/arvados/v1/container_requests?cluster_id=zmock",
646 "container_request": {
647 "name": "hello world",
648 "state": "Uncommitted",
650 "container_image": "123",
652 "runtime_token": "xyz"
656 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
657 req.Header.Set("Content-type", "application/json")
658 resp := s.testRequest(req)
659 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
661 arvados.ContainerRequest `json:"container_request"`
663 c.Check(json.NewDecoder(s.remoteMockRequests[0].Body).Decode(&cr), check.IsNil)
664 c.Check(cr.ContainerRequest.RuntimeToken, check.Equals, "xyz")
667 func (s *FederationSuite) TestCreateRemoteContainerRequestRuntimeTokenFromAuth(c *check.C) {
668 // Send request to zmock and check that outgoing request has
669 // runtime_token set using the Auth token because the user is remote.
671 defer s.localServiceReturns404(c).Close()
672 // pass cluster_id via query parameter, this allows arvados-controller
673 // to avoid parsing the body
674 req := httptest.NewRequest("POST", "/arvados/v1/container_requests?cluster_id=zmock",
676 "container_request": {
677 "name": "hello world",
678 "state": "Uncommitted",
680 "container_image": "123",
685 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveTokenV2+"/zzzzz-dz642-parentcontainer")
686 req.Header.Set("Content-type", "application/json")
687 resp := s.testRequest(req)
688 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
690 arvados.ContainerRequest `json:"container_request"`
692 c.Check(json.NewDecoder(s.remoteMockRequests[0].Body).Decode(&cr), check.IsNil)
693 c.Check(cr.ContainerRequest.RuntimeToken, check.Equals, arvadostest.ActiveTokenV2)
696 func (s *FederationSuite) TestCreateRemoteContainerRequestError(c *check.C) {
697 defer s.localServiceReturns404(c).Close()
698 // pass cluster_id via query parameter, this allows arvados-controller
699 // to avoid parsing the body
700 req := httptest.NewRequest("POST", "/arvados/v1/container_requests?cluster_id=zz404",
702 "container_request": {
703 "name": "hello world",
704 "state": "Uncommitted",
706 "container_image": "123",
711 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
712 req.Header.Set("Content-type", "application/json")
713 resp := s.testRequest(req)
714 c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)
717 func (s *FederationSuite) TestGetRemoteContainer(c *check.C) {
718 defer s.localServiceReturns404(c).Close()
719 req := httptest.NewRequest("GET", "/arvados/v1/containers/"+arvadostest.QueuedContainerUUID, nil)
720 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
721 resp := s.testRequest(req)
722 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
723 var cn arvados.Container
724 c.Check(json.NewDecoder(resp.Body).Decode(&cn), check.IsNil)
725 c.Check(cn.UUID, check.Equals, arvadostest.QueuedContainerUUID)
728 func (s *FederationSuite) TestListRemoteContainer(c *check.C) {
729 defer s.localServiceReturns404(c).Close()
730 req := httptest.NewRequest("GET", "/arvados/v1/containers?count=none&filters="+
731 url.QueryEscape(fmt.Sprintf(`[["uuid", "in", ["%v"]]]`, arvadostest.QueuedContainerUUID)), nil)
732 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
733 resp := s.testRequest(req)
734 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
735 var cn arvados.ContainerList
736 c.Check(json.NewDecoder(resp.Body).Decode(&cn), check.IsNil)
737 c.Check(cn.Items[0].UUID, check.Equals, arvadostest.QueuedContainerUUID)
740 func (s *FederationSuite) TestListMultiRemoteContainers(c *check.C) {
741 defer s.localServiceHandler(c, http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
742 bd, _ := ioutil.ReadAll(req.Body)
743 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.Write([]byte(`{"kind": "arvados#containerList", "items": [{"uuid": "zhome-xvhdp-cr5queuedcontnr", "command": ["abc"]}]}`))
747 req := httptest.NewRequest("GET", fmt.Sprintf("/arvados/v1/containers?count=none&filters=%s&select=%s",
748 url.QueryEscape(fmt.Sprintf(`[["uuid", "in", ["%v", "zhome-xvhdp-cr5queuedcontnr"]]]`,
749 arvadostest.QueuedContainerUUID)),
750 url.QueryEscape(`["uuid", "command"]`)),
752 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
753 resp := s.testRequest(req)
754 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
755 var cn arvados.ContainerList
756 c.Check(json.NewDecoder(resp.Body).Decode(&cn), check.IsNil)
757 c.Check(cn.Items, check.HasLen, 2)
758 mp := make(map[string]arvados.Container)
759 for _, cr := range cn.Items {
762 c.Check(mp[arvadostest.QueuedContainerUUID].Command, check.DeepEquals, []string{"echo", "hello"})
763 c.Check(mp[arvadostest.QueuedContainerUUID].ContainerImage, check.Equals, "")
764 c.Check(mp["zhome-xvhdp-cr5queuedcontnr"].Command, check.DeepEquals, []string{"abc"})
765 c.Check(mp["zhome-xvhdp-cr5queuedcontnr"].ContainerImage, check.Equals, "")
768 func (s *FederationSuite) TestListMultiRemoteContainerError(c *check.C) {
769 defer s.localServiceReturns404(c).Close()
770 req := httptest.NewRequest("GET", fmt.Sprintf("/arvados/v1/containers?count=none&filters=%s&select=%s",
771 url.QueryEscape(fmt.Sprintf(`[["uuid", "in", ["%v", "zhome-xvhdp-cr5queuedcontnr"]]]`,
772 arvadostest.QueuedContainerUUID)),
773 url.QueryEscape(`["uuid", "command"]`)),
775 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
776 resp := s.testRequest(req)
777 c.Check(resp.StatusCode, check.Equals, http.StatusBadGateway)
778 s.checkJSONErrorMatches(c, resp, `error fetching from zhome \(404 Not Found\): EOF`)
781 func (s *FederationSuite) TestListMultiRemoteContainersPaged(c *check.C) {
784 defer s.localServiceHandler(c, http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
785 bd, _ := ioutil.ReadAll(req.Body)
787 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.Write([]byte(`{"kind": "arvados#containerList", "items": [{"uuid": "zhome-xvhdp-cr5queuedcontnr", "command": ["abc"]}]}`))
790 } else if callCount == 1 {
791 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.Write([]byte(`{"kind": "arvados#containerList", "items": [{"uuid": "zhome-xvhdp-cr6queuedcontnr", "command": ["efg"]}]}`))
797 req := httptest.NewRequest("GET", fmt.Sprintf("/arvados/v1/containers?count=none&filters=%s",
798 url.QueryEscape(fmt.Sprintf(`[["uuid", "in", ["%v", "zhome-xvhdp-cr5queuedcontnr", "zhome-xvhdp-cr6queuedcontnr"]]]`,
799 arvadostest.QueuedContainerUUID))),
801 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
802 resp := s.testRequest(req)
803 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
804 c.Check(callCount, check.Equals, 2)
805 var cn arvados.ContainerList
806 c.Check(json.NewDecoder(resp.Body).Decode(&cn), check.IsNil)
807 c.Check(cn.Items, check.HasLen, 3)
808 mp := make(map[string]arvados.Container)
809 for _, cr := range cn.Items {
812 c.Check(mp[arvadostest.QueuedContainerUUID].Command, check.DeepEquals, []string{"echo", "hello"})
813 c.Check(mp["zhome-xvhdp-cr5queuedcontnr"].Command, check.DeepEquals, []string{"abc"})
814 c.Check(mp["zhome-xvhdp-cr6queuedcontnr"].Command, check.DeepEquals, []string{"efg"})
817 func (s *FederationSuite) TestListMultiRemoteContainersMissing(c *check.C) {
820 defer s.localServiceHandler(c, http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
821 bd, _ := ioutil.ReadAll(req.Body)
823 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.Write([]byte(`{"kind": "arvados#containerList", "items": [{"uuid": "zhome-xvhdp-cr6queuedcontnr", "command": ["efg"]}]}`))
826 } else if callCount == 1 {
827 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.Write([]byte(`{"kind": "arvados#containerList", "items": []}`))
833 req := httptest.NewRequest("GET", fmt.Sprintf("/arvados/v1/containers?count=none&filters=%s",
834 url.QueryEscape(fmt.Sprintf(`[["uuid", "in", ["%v", "zhome-xvhdp-cr5queuedcontnr", "zhome-xvhdp-cr6queuedcontnr"]]]`,
835 arvadostest.QueuedContainerUUID))),
837 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
838 resp := s.testRequest(req)
839 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
840 c.Check(callCount, check.Equals, 2)
841 var cn arvados.ContainerList
842 c.Check(json.NewDecoder(resp.Body).Decode(&cn), check.IsNil)
843 c.Check(cn.Items, check.HasLen, 2)
844 mp := make(map[string]arvados.Container)
845 for _, cr := range cn.Items {
848 c.Check(mp[arvadostest.QueuedContainerUUID].Command, check.DeepEquals, []string{"echo", "hello"})
849 c.Check(mp["zhome-xvhdp-cr6queuedcontnr"].Command, check.DeepEquals, []string{"efg"})
852 func (s *FederationSuite) TestListMultiRemoteContainerPageSizeError(c *check.C) {
853 s.testHandler.Cluster.RequestLimits.MaxItemsPerResponse = 1
854 req := httptest.NewRequest("GET", fmt.Sprintf("/arvados/v1/containers?count=none&filters=%s",
855 url.QueryEscape(fmt.Sprintf(`[["uuid", "in", ["%v", "zhome-xvhdp-cr5queuedcontnr"]]]`,
856 arvadostest.QueuedContainerUUID))),
858 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
859 resp := s.testRequest(req)
860 c.Check(resp.StatusCode, check.Equals, http.StatusBadRequest)
861 s.checkJSONErrorMatches(c, resp, `Federated multi-object request for 2 objects which is more than max page size 1.`)
864 func (s *FederationSuite) TestListMultiRemoteContainerLimitError(c *check.C) {
865 req := httptest.NewRequest("GET", fmt.Sprintf("/arvados/v1/containers?count=none&filters=%s&limit=1",
866 url.QueryEscape(fmt.Sprintf(`[["uuid", "in", ["%v", "zhome-xvhdp-cr5queuedcontnr"]]]`,
867 arvadostest.QueuedContainerUUID))),
869 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
870 resp := s.testRequest(req)
871 c.Check(resp.StatusCode, check.Equals, http.StatusBadRequest)
872 s.checkJSONErrorMatches(c, resp, `Federated multi-object may not provide 'limit', 'offset' or 'order'.`)
875 func (s *FederationSuite) TestListMultiRemoteContainerOffsetError(c *check.C) {
876 req := httptest.NewRequest("GET", fmt.Sprintf("/arvados/v1/containers?count=none&filters=%s&offset=1",
877 url.QueryEscape(fmt.Sprintf(`[["uuid", "in", ["%v", "zhome-xvhdp-cr5queuedcontnr"]]]`,
878 arvadostest.QueuedContainerUUID))),
880 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
881 resp := s.testRequest(req)
882 c.Check(resp.StatusCode, check.Equals, http.StatusBadRequest)
883 s.checkJSONErrorMatches(c, resp, `Federated multi-object may not provide 'limit', 'offset' or 'order'.`)
886 func (s *FederationSuite) TestListMultiRemoteContainerOrderError(c *check.C) {
887 req := httptest.NewRequest("GET", fmt.Sprintf("/arvados/v1/containers?count=none&filters=%s&order=uuid",
888 url.QueryEscape(fmt.Sprintf(`[["uuid", "in", ["%v", "zhome-xvhdp-cr5queuedcontnr"]]]`,
889 arvadostest.QueuedContainerUUID))),
891 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
892 resp := s.testRequest(req)
893 c.Check(resp.StatusCode, check.Equals, http.StatusBadRequest)
894 s.checkJSONErrorMatches(c, resp, `Federated multi-object may not provide 'limit', 'offset' or 'order'.`)
897 func (s *FederationSuite) TestListMultiRemoteContainerSelectError(c *check.C) {
898 req := httptest.NewRequest("GET", fmt.Sprintf("/arvados/v1/containers?count=none&filters=%s&select=%s",
899 url.QueryEscape(fmt.Sprintf(`[["uuid", "in", ["%v", "zhome-xvhdp-cr5queuedcontnr"]]]`,
900 arvadostest.QueuedContainerUUID)),
901 url.QueryEscape(`["command"]`)),
903 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
904 resp := s.testRequest(req)
905 c.Check(resp.StatusCode, check.Equals, http.StatusBadRequest)
906 s.checkJSONErrorMatches(c, resp, `Federated multi-object request must include 'uuid' in 'select'`)