14242: Add a test for manifest_text PDH checking
authorPeter Amstutz <pamstutz@veritasgenetics.com>
Thu, 20 Sep 2018 14:46:11 +0000 (10:46 -0400)
committerPeter Amstutz <pamstutz@veritasgenetics.com>
Thu, 20 Sep 2018 14:46:11 +0000 (10:46 -0400)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz@veritasgenetics.com>

lib/controller/federation.go
lib/controller/federation_test.go

index 3715edae9aecf658149642ae8853decc32f0d774..4cbbe465d489cad14e156c64366ccaf0be6c6bbb 100644 (file)
@@ -159,15 +159,19 @@ func (rw rewriteSignaturesClusterId) rewriteSignatures(resp *http.Response, requ
                sz += n
        }
 
-       // Certify that the computed hash of the manifest matches our expectation
+       // Check that expected hash is consistent with
+       // portable_data_hash field of the returned record
        if rw.expectHash == "" {
                rw.expectHash = col.PortableDataHash
+       } else if rw.expectHash != col.PortableDataHash {
+               return nil, fmt.Errorf("portable_data_hash %q on returned record did not match expected hash %q ", rw.expectHash, col.PortableDataHash)
        }
 
+       // Certify that the computed hash of the manifest_text matches our expectation
        sum := hasher.Sum(nil)
        computedHash := fmt.Sprintf("%x+%v", sum, sz)
        if computedHash != rw.expectHash {
-               return nil, fmt.Errorf("Computed hash %q did not match expected hash %q", computedHash, rw.expectHash)
+               return nil, fmt.Errorf("Computed manifest_text hash %q did not match expected hash %q", computedHash, rw.expectHash)
        }
 
        col.ManifestText = updatedManifest.String()
index 1d113065eeae934de06e861f3a0cd82e212bf074..52906ead326fd4dad2cd9eda3bf1f7e80a2e7c95 100644 (file)
@@ -439,6 +439,62 @@ func (s *FederationSuite) TestGetCollectionByPDHError(c *check.C) {
        c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)
 }
 
+func (s *FederationSuite) TestGetCollectionByPDHErrorBadHash(c *check.C) {
+       srv := &httpserver.Server{
+               Server: http.Server{
+                       Handler: http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
+                               w.WriteHeader(404)
+                       }),
+               },
+       }
+
+       c.Assert(srv.Start(), check.IsNil)
+       defer srv.Close()
+
+       // Make the "local" cluster to a service that always returns 404
+       np := arvados.NodeProfile{
+               Controller: arvados.SystemServiceInstance{Listen: ":"},
+               RailsAPI: arvados.SystemServiceInstance{Listen: srv.Addr,
+                       TLS: false, Insecure: true}}
+       s.testHandler.Cluster.NodeProfiles["*"] = np
+       s.testHandler.NodeProfile = &np
+
+       srv2 := &httpserver.Server{
+               Server: http.Server{
+                       Handler: http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
+                               w.WriteHeader(200)
+                               // Return a collection where the hash
+                               // of the manifest text doesn't match
+                               // PDH that was requested.
+                               var col arvados.Collection
+                               col.PortableDataHash = "99999999999999999999999999999999+99"
+                               col.ManifestText = `. 6a4ff0499484c6c79c95cd8c566bd25f\+249025 0:249025:GNU_General_Public_License,_version_3.pdf
+`
+                               enc := json.NewEncoder(w)
+                               enc.Encode(col)
+                       }),
+               },
+       }
+
+       c.Assert(srv2.Start(), check.IsNil)
+       defer srv2.Close()
+
+       // Direct zzzzz to service that returns a 200 result with a bogus manifest_text
+       s.testHandler.Cluster.RemoteClusters["zzzzz"] = arvados.RemoteCluster{
+               Host:   srv2.Addr,
+               Proxy:  true,
+               Scheme: "http",
+       }
+
+       req := httptest.NewRequest("GET", "/arvados/v1/collections/99999999999999999999999999999999+99", nil)
+       req.Header.Set("Authorization", "Bearer "+arvadostest.ActiveToken)
+
+       resp := s.testRequest(req)
+       defer resp.Body.Close()
+
+       c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)
+}
+
 func (s *FederationSuite) TestSaltedTokenGetCollectionByPDH(c *check.C) {
        np := arvados.NodeProfile{
                Controller: arvados.SystemServiceInstance{Listen: ":"},