1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
17 "git.curoverse.com/arvados.git/sdk/go/arvados"
18 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
19 "git.curoverse.com/arvados.git/sdk/go/httpserver"
20 "git.curoverse.com/arvados.git/sdk/go/keepclient"
21 "github.com/Sirupsen/logrus"
22 check "gopkg.in/check.v1"
25 // Gocheck boilerplate
26 var _ = check.Suite(&FederationSuite{})
28 type FederationSuite struct {
30 // testServer and testHandler are the controller being tested,
32 testServer *httpserver.Server
34 // remoteServer ("zzzzz") forwards requests to the Rails API
35 // provided by the integration test environment.
36 remoteServer *httpserver.Server
37 // remoteMock ("zmock") appends each incoming request to
38 // remoteMockRequests, and returns an empty 200 response.
39 remoteMock *httpserver.Server
40 remoteMockRequests []http.Request
43 func (s *FederationSuite) SetUpTest(c *check.C) {
45 s.log.Formatter = &logrus.JSONFormatter{}
46 s.log.Out = &logWriter{c.Log}
48 s.remoteServer = newServerFromIntegrationTestEnv(c)
49 c.Assert(s.remoteServer.Start(), check.IsNil)
51 s.remoteMock = newServerFromIntegrationTestEnv(c)
52 s.remoteMock.Server.Handler = http.HandlerFunc(s.remoteMockHandler)
53 c.Assert(s.remoteMock.Start(), check.IsNil)
55 nodeProfile := arvados.NodeProfile{
56 Controller: arvados.SystemServiceInstance{Listen: ":"},
57 RailsAPI: arvados.SystemServiceInstance{Listen: ":1"}, // local reqs will error "connection refused"
59 s.testHandler = &Handler{Cluster: &arvados.Cluster{
61 PostgreSQL: integrationTestCluster().PostgreSQL,
62 NodeProfiles: map[string]arvados.NodeProfile{
65 }, NodeProfile: &nodeProfile}
66 s.testServer = newServerFromIntegrationTestEnv(c)
67 s.testServer.Server.Handler = httpserver.AddRequestIDs(httpserver.LogRequests(s.log, s.testHandler))
69 s.testHandler.Cluster.RemoteClusters = map[string]arvados.RemoteCluster{
71 Host: s.remoteServer.Addr,
76 Host: s.remoteMock.Addr,
82 c.Assert(s.testServer.Start(), check.IsNil)
84 s.remoteMockRequests = nil
87 func (s *FederationSuite) remoteMockHandler(w http.ResponseWriter, req *http.Request) {
88 s.remoteMockRequests = append(s.remoteMockRequests, *req)
91 func (s *FederationSuite) TearDownTest(c *check.C) {
92 if s.remoteServer != nil {
93 s.remoteServer.Close()
95 if s.testServer != nil {
100 func (s *FederationSuite) testRequest(req *http.Request) *http.Response {
101 resp := httptest.NewRecorder()
102 s.testServer.Server.Handler.ServeHTTP(resp, req)
106 func (s *FederationSuite) TestLocalRequest(c *check.C) {
107 req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+strings.Replace(arvadostest.WorkflowWithDefinitionYAMLUUID, "zzzzz-", "zhome-", 1), nil)
108 resp := s.testRequest(req)
109 s.checkHandledLocally(c, resp)
112 func (s *FederationSuite) checkHandledLocally(c *check.C, resp *http.Response) {
113 // Our "home" controller can't handle local requests because
114 // it doesn't have its own stub/test Rails API, so we rely on
115 // "connection refused" to indicate the controller tried to
116 // proxy the request to its local Rails API.
117 c.Check(resp.StatusCode, check.Equals, http.StatusBadGateway)
118 s.checkJSONErrorMatches(c, resp, `.*connection refused`)
121 func (s *FederationSuite) TestNoAuth(c *check.C) {
122 req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+arvadostest.WorkflowWithDefinitionYAMLUUID, nil)
123 resp := s.testRequest(req)
124 c.Check(resp.StatusCode, check.Equals, http.StatusUnauthorized)
125 s.checkJSONErrorMatches(c, resp, `Not logged in`)
128 func (s *FederationSuite) TestBadAuth(c *check.C) {
129 req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+arvadostest.WorkflowWithDefinitionYAMLUUID, nil)
130 req.Header.Set("Authorization", "Bearer aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
131 resp := s.testRequest(req)
132 c.Check(resp.StatusCode, check.Equals, http.StatusUnauthorized)
133 s.checkJSONErrorMatches(c, resp, `Not logged in`)
136 func (s *FederationSuite) TestNoAccess(c *check.C) {
137 req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+arvadostest.WorkflowWithDefinitionYAMLUUID, nil)
138 req.Header.Set("Authorization", "Bearer "+arvadostest.SpectatorToken)
139 resp := s.testRequest(req)
140 c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)
141 s.checkJSONErrorMatches(c, resp, `.*not found`)
144 func (s *FederationSuite) TestGetUnknownRemote(c *check.C) {
145 req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+strings.Replace(arvadostest.WorkflowWithDefinitionYAMLUUID, "zzzzz-", "zz404-", 1), nil)
146 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
147 resp := s.testRequest(req)
148 c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)
149 s.checkJSONErrorMatches(c, resp, `.*no proxy available for cluster zz404`)
152 func (s *FederationSuite) TestRemoteError(c *check.C) {
153 rc := s.testHandler.Cluster.RemoteClusters["zzzzz"]
155 s.testHandler.Cluster.RemoteClusters["zzzzz"] = rc
157 req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+arvadostest.WorkflowWithDefinitionYAMLUUID, nil)
158 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
159 resp := s.testRequest(req)
160 c.Check(resp.StatusCode, check.Equals, http.StatusBadGateway)
161 s.checkJSONErrorMatches(c, resp, `.*HTTP response to HTTPS client`)
164 func (s *FederationSuite) TestGetRemoteWorkflow(c *check.C) {
165 req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+arvadostest.WorkflowWithDefinitionYAMLUUID, nil)
166 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
167 resp := s.testRequest(req)
168 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
169 var wf arvados.Workflow
170 c.Check(json.NewDecoder(resp.Body).Decode(&wf), check.IsNil)
171 c.Check(wf.UUID, check.Equals, arvadostest.WorkflowWithDefinitionYAMLUUID)
172 c.Check(wf.OwnerUUID, check.Equals, arvadostest.ActiveUserUUID)
175 func (s *FederationSuite) TestOptionsMethod(c *check.C) {
176 req := httptest.NewRequest("OPTIONS", "/arvados/v1/workflows/"+arvadostest.WorkflowWithDefinitionYAMLUUID, nil)
177 req.Header.Set("Origin", "https://example.com")
178 resp := s.testRequest(req)
179 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
180 body, err := ioutil.ReadAll(resp.Body)
181 c.Check(err, check.IsNil)
182 c.Check(string(body), check.Equals, "")
183 c.Check(resp.Header.Get("Access-Control-Allow-Origin"), check.Equals, "*")
184 for _, hdr := range []string{"Authorization", "Content-Type"} {
185 c.Check(resp.Header.Get("Access-Control-Allow-Headers"), check.Matches, ".*"+hdr+".*")
187 for _, method := range []string{"GET", "HEAD", "PUT", "POST", "DELETE"} {
188 c.Check(resp.Header.Get("Access-Control-Allow-Methods"), check.Matches, ".*"+method+".*")
192 func (s *FederationSuite) TestRemoteWithTokenInQuery(c *check.C) {
193 req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+strings.Replace(arvadostest.WorkflowWithDefinitionYAMLUUID, "zzzzz-", "zmock-", 1)+"?api_token="+arvadostest.ActiveToken, nil)
195 c.Assert(len(s.remoteMockRequests), check.Equals, 1)
196 pr := s.remoteMockRequests[0]
197 // Token is salted and moved from query to Authorization header.
198 c.Check(pr.URL.String(), check.Not(check.Matches), `.*api_token=.*`)
199 c.Check(pr.Header.Get("Authorization"), check.Equals, "Bearer v2/zzzzz-gj3su-077z32aux8dg2s1/7fd31b61f39c0e82a4155592163218272cedacdc")
202 func (s *FederationSuite) TestLocalTokenSalted(c *check.C) {
203 req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+strings.Replace(arvadostest.WorkflowWithDefinitionYAMLUUID, "zzzzz-", "zmock-", 1), nil)
204 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
206 c.Assert(len(s.remoteMockRequests), check.Equals, 1)
207 pr := s.remoteMockRequests[0]
208 // The salted token here has a "zzzzz-" UUID instead of a
209 // "ztest-" UUID because ztest's local database has the
210 // "zzzzz-" test fixtures. The "secret" part is HMAC(sha1,
211 // arvadostest.ActiveToken, "zmock") = "7fd3...".
212 c.Check(pr.Header.Get("Authorization"), check.Equals, "Bearer v2/zzzzz-gj3su-077z32aux8dg2s1/7fd31b61f39c0e82a4155592163218272cedacdc")
215 func (s *FederationSuite) TestRemoteTokenNotSalted(c *check.C) {
216 // remoteToken can be any v1 token that doesn't appear in
218 remoteToken := "abcdef00000000000000000000000000000000000000000000"
219 req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+strings.Replace(arvadostest.WorkflowWithDefinitionYAMLUUID, "zzzzz-", "zmock-", 1), nil)
220 req.Header.Set("Authorization", "Bearer "+remoteToken)
222 c.Assert(len(s.remoteMockRequests), check.Equals, 1)
223 pr := s.remoteMockRequests[0]
224 c.Check(pr.Header.Get("Authorization"), check.Equals, "Bearer "+remoteToken)
227 func (s *FederationSuite) TestWorkflowCRUD(c *check.C) {
228 wf := arvados.Workflow{
229 Description: "TestCRUD",
232 body := &strings.Builder{}
233 json.NewEncoder(body).Encode(&wf)
234 req := httptest.NewRequest("POST", "/arvados/v1/workflows", strings.NewReader(url.Values{
235 "workflow": {body.String()},
237 req.Header.Set("Content-type", "application/x-www-form-urlencoded")
238 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
239 rec := httptest.NewRecorder()
240 s.remoteServer.Server.Handler.ServeHTTP(rec, req) // direct to remote -- can't proxy a create req because no uuid
242 s.checkResponseOK(c, resp)
243 json.NewDecoder(resp.Body).Decode(&wf)
246 req := httptest.NewRequest("DELETE", "/arvados/v1/workflows/"+wf.UUID, nil)
247 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
248 s.remoteServer.Server.Handler.ServeHTTP(httptest.NewRecorder(), req)
250 c.Check(wf.UUID, check.Not(check.Equals), "")
252 c.Assert(wf.ModifiedAt, check.NotNil)
253 c.Logf("wf.ModifiedAt: %v", wf.ModifiedAt)
254 c.Check(time.Since(*wf.ModifiedAt) < time.Minute, check.Equals, true)
256 for _, method := range []string{"PATCH", "PUT", "POST"} {
258 "workflow": {`{"description": "Updated with ` + method + `"}`},
260 if method == "POST" {
261 form["_method"] = []string{"PATCH"}
263 req := httptest.NewRequest(method, "/arvados/v1/workflows/"+wf.UUID, strings.NewReader(form.Encode()))
264 req.Header.Set("Content-type", "application/x-www-form-urlencoded")
265 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
266 resp := s.testRequest(req)
267 s.checkResponseOK(c, resp)
268 err := json.NewDecoder(resp.Body).Decode(&wf)
269 c.Check(err, check.IsNil)
271 c.Check(wf.Description, check.Equals, "Updated with "+method)
274 req := httptest.NewRequest("DELETE", "/arvados/v1/workflows/"+wf.UUID, nil)
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)
282 req := httptest.NewRequest("GET", "/arvados/v1/workflows/"+wf.UUID, nil)
283 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
284 resp := s.testRequest(req)
285 c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)
289 func (s *FederationSuite) checkResponseOK(c *check.C, resp *http.Response) {
290 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
291 if resp.StatusCode != http.StatusOK {
292 body, err := ioutil.ReadAll(resp.Body)
293 c.Logf("... response body = %q, %v\n", body, err)
297 func (s *FederationSuite) checkJSONErrorMatches(c *check.C, resp *http.Response, re string) {
298 var jresp httpserver.ErrorResponse
299 err := json.NewDecoder(resp.Body).Decode(&jresp)
300 c.Check(err, check.IsNil)
301 c.Assert(len(jresp.Errors), check.Equals, 1)
302 c.Check(jresp.Errors[0], check.Matches, re)
305 func (s *FederationSuite) localServiceReturns404(c *check.C) *httpserver.Server {
306 srv := &httpserver.Server{
308 Handler: http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
314 c.Assert(srv.Start(), check.IsNil)
316 np := arvados.NodeProfile{
317 Controller: arvados.SystemServiceInstance{Listen: ":"},
318 RailsAPI: arvados.SystemServiceInstance{Listen: srv.Addr,
319 TLS: false, Insecure: true}}
320 s.testHandler.Cluster.NodeProfiles["*"] = np
321 s.testHandler.NodeProfile = &np
326 func (s *FederationSuite) TestGetLocalCollection(c *check.C) {
327 np := arvados.NodeProfile{
328 Controller: arvados.SystemServiceInstance{Listen: ":"},
329 RailsAPI: arvados.SystemServiceInstance{Listen: os.Getenv("ARVADOS_TEST_API_HOST"),
330 TLS: true, Insecure: true}}
331 s.testHandler.Cluster.ClusterID = "zzzzz"
332 s.testHandler.Cluster.NodeProfiles["*"] = np
333 s.testHandler.NodeProfile = &np
335 req := httptest.NewRequest("GET", "/arvados/v1/collections/"+arvadostest.UserAgreementCollection, nil)
336 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
337 resp := s.testRequest(req)
339 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
340 var col arvados.Collection
341 c.Check(json.NewDecoder(resp.Body).Decode(&col), check.IsNil)
342 c.Check(col.UUID, check.Equals, arvadostest.UserAgreementCollection)
343 c.Check(col.ManifestText, check.Matches,
344 `\. 6a4ff0499484c6c79c95cd8c566bd25f\+249025\+A[0-9a-f]{40}@[0-9a-f]{8} 0:249025:GNU_General_Public_License,_version_3.pdf
348 func (s *FederationSuite) TestGetRemoteCollection(c *check.C) {
349 defer s.localServiceReturns404(c).Close()
351 req := httptest.NewRequest("GET", "/arvados/v1/collections/"+arvadostest.UserAgreementCollection, nil)
352 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
353 resp := s.testRequest(req)
354 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
355 var col arvados.Collection
356 c.Check(json.NewDecoder(resp.Body).Decode(&col), check.IsNil)
357 c.Check(col.UUID, check.Equals, arvadostest.UserAgreementCollection)
358 c.Check(col.ManifestText, check.Matches,
359 `\. 6a4ff0499484c6c79c95cd8c566bd25f\+249025\+Rzzzzz-[0-9a-f]{40}@[0-9a-f]{8} 0:249025:GNU_General_Public_License,_version_3.pdf
363 func (s *FederationSuite) TestGetRemoteCollectionError(c *check.C) {
364 defer s.localServiceReturns404(c).Close()
366 req := httptest.NewRequest("GET", "/arvados/v1/collections/zzzzz-4zz18-fakefakefakefak", nil)
367 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
368 resp := s.testRequest(req)
369 c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)
372 func (s *FederationSuite) TestSignedLocatorPattern(c *check.C) {
373 // Confirm the regular expression identifies other groups of hints correctly
374 c.Check(keepclient.SignedLocatorRe.FindStringSubmatch(`6a4ff0499484c6c79c95cd8c566bd25f+249025+B1+C2+A05227438989d04712ea9ca1c91b556cef01d5cc7@5ba5405b+D3+E4`),
376 []string{"6a4ff0499484c6c79c95cd8c566bd25f+249025+B1+C2+A05227438989d04712ea9ca1c91b556cef01d5cc7@5ba5405b+D3+E4",
377 "6a4ff0499484c6c79c95cd8c566bd25f",
380 "+A05227438989d04712ea9ca1c91b556cef01d5cc7@5ba5405b",
381 "05227438989d04712ea9ca1c91b556cef01d5cc7", "5ba5405b",
385 func (s *FederationSuite) TestGetLocalCollectionByPDH(c *check.C) {
386 np := arvados.NodeProfile{
387 Controller: arvados.SystemServiceInstance{Listen: ":"},
388 RailsAPI: arvados.SystemServiceInstance{Listen: os.Getenv("ARVADOS_TEST_API_HOST"),
389 TLS: true, Insecure: true}}
390 s.testHandler.Cluster.NodeProfiles["*"] = np
391 s.testHandler.NodeProfile = &np
393 req := httptest.NewRequest("GET", "/arvados/v1/collections/"+arvadostest.UserAgreementPDH, nil)
394 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
395 resp := s.testRequest(req)
397 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
398 var col arvados.Collection
399 c.Check(json.NewDecoder(resp.Body).Decode(&col), check.IsNil)
400 c.Check(col.PortableDataHash, check.Equals, arvadostest.UserAgreementPDH)
401 c.Check(col.ManifestText, check.Matches,
402 `\. 6a4ff0499484c6c79c95cd8c566bd25f\+249025\+A[0-9a-f]{40}@[0-9a-f]{8} 0:249025:GNU_General_Public_License,_version_3.pdf
406 func (s *FederationSuite) TestGetRemoteCollectionByPDH(c *check.C) {
407 defer s.localServiceReturns404(c).Close()
409 req := httptest.NewRequest("GET", "/arvados/v1/collections/"+arvadostest.UserAgreementPDH, nil)
410 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
411 resp := s.testRequest(req)
413 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
415 var col arvados.Collection
416 c.Check(json.NewDecoder(resp.Body).Decode(&col), check.IsNil)
417 c.Check(col.PortableDataHash, check.Equals, arvadostest.UserAgreementPDH)
418 c.Check(col.ManifestText, check.Matches,
419 `\. 6a4ff0499484c6c79c95cd8c566bd25f\+249025\+Rzzzzz-[0-9a-f]{40}@[0-9a-f]{8} 0:249025:GNU_General_Public_License,_version_3.pdf
423 func (s *FederationSuite) TestGetCollectionByPDHError(c *check.C) {
424 defer s.localServiceReturns404(c).Close()
426 req := httptest.NewRequest("GET", "/arvados/v1/collections/99999999999999999999999999999999+99", nil)
427 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
429 resp := s.testRequest(req)
430 defer resp.Body.Close()
432 c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)
435 func (s *FederationSuite) TestGetCollectionByPDHErrorBadHash(c *check.C) {
436 defer s.localServiceReturns404(c).Close()
438 srv2 := &httpserver.Server{
440 Handler: http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
442 // Return a collection where the hash
443 // of the manifest text doesn't match
444 // PDH that was requested.
445 var col arvados.Collection
446 col.PortableDataHash = "99999999999999999999999999999999+99"
447 col.ManifestText = `. 6a4ff0499484c6c79c95cd8c566bd25f\+249025 0:249025:GNU_General_Public_License,_version_3.pdf
449 enc := json.NewEncoder(w)
455 c.Assert(srv2.Start(), check.IsNil)
458 // Direct zzzzz to service that returns a 200 result with a bogus manifest_text
459 s.testHandler.Cluster.RemoteClusters["zzzzz"] = arvados.RemoteCluster{
465 req := httptest.NewRequest("GET", "/arvados/v1/collections/99999999999999999999999999999999+99", nil)
466 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
468 resp := s.testRequest(req)
469 defer resp.Body.Close()
471 c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)
474 func (s *FederationSuite) TestSaltedTokenGetCollectionByPDH(c *check.C) {
475 np := arvados.NodeProfile{
476 Controller: arvados.SystemServiceInstance{Listen: ":"},
477 RailsAPI: arvados.SystemServiceInstance{Listen: os.Getenv("ARVADOS_TEST_API_HOST"),
478 TLS: true, Insecure: true}}
479 s.testHandler.Cluster.NodeProfiles["*"] = np
480 s.testHandler.NodeProfile = &np
482 req := httptest.NewRequest("GET", "/arvados/v1/collections/"+arvadostest.UserAgreementPDH, nil)
483 req.Header.Set("Authorization", "Bearer v2/zzzzz-gj3su-077z32aux8dg2s1/282d7d172b6cfdce364c5ed12ddf7417b2d00065")
484 resp := s.testRequest(req)
486 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
487 var col arvados.Collection
488 c.Check(json.NewDecoder(resp.Body).Decode(&col), check.IsNil)
489 c.Check(col.PortableDataHash, check.Equals, arvadostest.UserAgreementPDH)
490 c.Check(col.ManifestText, check.Matches,
491 `\. 6a4ff0499484c6c79c95cd8c566bd25f\+249025\+A[0-9a-f]{40}@[0-9a-f]{8} 0:249025:GNU_General_Public_License,_version_3.pdf
495 func (s *FederationSuite) TestSaltedTokenGetCollectionByPDHError(c *check.C) {
496 np := arvados.NodeProfile{
497 Controller: arvados.SystemServiceInstance{Listen: ":"},
498 RailsAPI: arvados.SystemServiceInstance{Listen: os.Getenv("ARVADOS_TEST_API_HOST"),
499 TLS: true, Insecure: true}}
500 s.testHandler.Cluster.NodeProfiles["*"] = np
501 s.testHandler.NodeProfile = &np
503 req := httptest.NewRequest("GET", "/arvados/v1/collections/99999999999999999999999999999999+99", nil)
504 req.Header.Set("Authorization", "Bearer v2/zzzzz-gj3su-077z32aux8dg2s1/282d7d172b6cfdce364c5ed12ddf7417b2d00065")
505 resp := s.testRequest(req)
507 c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)
510 func (s *FederationSuite) TestGetRemoteContainerRequest(c *check.C) {
511 defer s.localServiceReturns404(c).Close()
512 req := httptest.NewRequest("GET", "/arvados/v1/container_requests/"+arvadostest.QueuedContainerRequestUUID, nil)
513 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
514 resp := s.testRequest(req)
515 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
516 var cr arvados.ContainerRequest
517 c.Check(json.NewDecoder(resp.Body).Decode(&cr), check.IsNil)
518 c.Check(cr.UUID, check.Equals, arvadostest.QueuedContainerRequestUUID)
519 c.Check(cr.Priority, check.Equals, 1)
522 func (s *FederationSuite) TestUpdateRemoteContainerRequest(c *check.C) {
523 defer s.localServiceReturns404(c).Close()
524 req := httptest.NewRequest("PATCH", "/arvados/v1/container_requests/"+arvadostest.QueuedContainerRequestUUID,
525 strings.NewReader(`{"container_request": {"priority": 696}}`))
526 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
527 req.Header.Set("Content-type", "application/json")
528 resp := s.testRequest(req)
529 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
530 var cr arvados.ContainerRequest
531 c.Check(json.NewDecoder(resp.Body).Decode(&cr), check.IsNil)
532 c.Check(cr.UUID, check.Equals, arvadostest.QueuedContainerRequestUUID)
533 c.Check(cr.Priority, check.Equals, 696)
536 func (s *FederationSuite) TestCreateRemoteContainerRequest1(c *check.C) {
537 defer s.localServiceReturns404(c).Close()
538 req := httptest.NewRequest("POST", "/arvados/v1/container_requests",
540 "cluster_id": "zzzzz",
541 "container_request": {
542 "name": "hello world",
543 "state": "Uncommitted",
545 "container_image": "123",
550 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
551 req.Header.Set("Content-type", "application/json")
552 resp := s.testRequest(req)
553 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
554 var cr arvados.ContainerRequest
555 c.Check(json.NewDecoder(resp.Body).Decode(&cr), check.IsNil)
556 c.Check(cr.Name, check.Equals, "hello world")
559 func (s *FederationSuite) TestCreateRemoteContainerRequest2(c *check.C) {
560 defer s.localServiceReturns404(c).Close()
561 // pass cluster_id via query parameter, this allows arvados-controller
562 // to avoid parsing the body
563 req := httptest.NewRequest("POST", "/arvados/v1/container_requests?cluster_id=zzzzz",
565 "container_request": {
566 "name": "hello world",
567 "state": "Uncommitted",
569 "container_image": "123",
574 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
575 req.Header.Set("Content-type", "application/json")
576 resp := s.testRequest(req)
577 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
578 var cr arvados.ContainerRequest
579 c.Check(json.NewDecoder(resp.Body).Decode(&cr), check.IsNil)
580 c.Check(cr.Name, check.Equals, "hello world")
583 func (s *FederationSuite) TestGetRemoteContainer(c *check.C) {
584 defer s.localServiceReturns404(c).Close()
585 req := httptest.NewRequest("GET", "/arvados/v1/containers/"+arvadostest.QueuedContainerUUID, nil)
586 req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
587 resp := s.testRequest(req)
588 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
589 var cn arvados.Container
590 c.Check(json.NewDecoder(resp.Body).Decode(&cn), check.IsNil)
591 c.Check(cn.UUID, check.Equals, arvadostest.QueuedContainerUUID)