Skip to content

Commit

Permalink
redirect optional ostree files (RedHatInsights#2650)
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Holloway <[email protected]>
  • Loading branch information
loadtheaccumulator authored Jul 17, 2024
1 parent af96d9b commit 399ffdf
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
25 changes: 19 additions & 6 deletions pkg/routes/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"net/http"
url2 "net/url"
"path/filepath"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -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
Expand Down
20 changes: 19 additions & 1 deletion pkg/routes/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand All @@ -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)
Expand Down

0 comments on commit 399ffdf

Please sign in to comment.