diff --git a/pkg/routes/storage.go b/pkg/routes/storage.go index b0e108e3e..ec1d73157 100644 --- a/pkg/routes/storage.go +++ b/pkg/routes/storage.go @@ -8,6 +8,7 @@ import ( "io" "net/http" url2 "net/url" + "path/filepath" "strconv" "strings" "time" @@ -420,12 +421,24 @@ func GetUpdateTransactionRepoFile(w http.ResponseWriter, r *http.Request) { return } - logger.WithFields(log.Fields{ - "orgID": updateRepo.OrgID, - "updateTransactionID": updateRepo.ID, - "path": requestPath, - }).Debug("return storage update transaction repo resource content") - serveStorageContent(w, r, requestPath) + // workaround to serve 303 instead of 404 for optional ostree files + baseFilename := filepath.Base(requestPath) + switch baseFilename { + case "summary", "summary.sig", ".commitmeta", "superblock": + logger.WithFields(log.Fields{ + "orgID": updateRepo.OrgID, + "updateTransactionID": updateRepo.ID, + "path": requestPath, + }).Debug("redirected possible missing optional ostree file") + redirectToStorageSignedURL(w, r, requestPath) + default: + logger.WithFields(log.Fields{ + "orgID": updateRepo.OrgID, + "updateTransactionID": updateRepo.ID, + "path": requestPath, + }).Debug("return storage update transaction repo resource content") + serveStorageContent(w, r, requestPath) + } } // storageImageCtx is a handler for storage image requests diff --git a/pkg/routes/storage_test.go b/pkg/routes/storage_test.go index 961208329..7891495a6 100644 --- a/pkg/routes/storage_test.go +++ b/pkg/routes/storage_test.go @@ -138,7 +138,7 @@ var _ = Describe("Storage Router", func() { Context("GetUpdateTransactionRepoFile", func() { It("Should return the requested resource content", func() { - targetRepoFile := "summary.sig" + targetRepoFile := "thing.filez" req, err := http.NewRequest("GET", fmt.Sprintf("/storage/update-repos/%d/%s", updateTransaction.ID, targetRepoFile), nil) Expect(err).ToNot(HaveOccurred()) @@ -161,6 +161,24 @@ var _ = Describe("Storage Router", func() { Expect(string(respBody)).To(Equal(fileContent)) }) + It("Should redirect to the requested resource content file", func() { + targetRepoFile := "summary.sig" + req, err := http.NewRequest("GET", fmt.Sprintf("/storage/update-repos/%d/content/%s", updateTransaction.ID, targetRepoFile), nil) + Expect(err).ToNot(HaveOccurred()) + + url, err := url2.Parse(updateTransaction.Repo.URL) + Expect(err).ToNot(HaveOccurred()) + targetPath := fmt.Sprintf("%s/%s", url.Path, targetRepoFile) + expectedURL := fmt.Sprintf("%s/%s?signature", url, targetRepoFile) + mockFilesService.EXPECT().GetSignedURL(targetPath).Return(expectedURL, nil) + + httpTestRecorder := httptest.NewRecorder() + router.ServeHTTP(httpTestRecorder, req) + + Expect(httpTestRecorder.Code).To(Equal(http.StatusSeeOther)) + Expect(httpTestRecorder.Header()["Location"][0]).To(Equal(expectedURL)) + }) + It("should return error when the update transaction does not exists", func() { req, err := http.NewRequest("GET", fmt.Sprintf("/storage/update-repos/%d/summary.sig", 9999), nil)