Skip to content

Commit

Permalink
Revert "adds logic to remove http query params from destination file …
Browse files Browse the repository at this point in the history
…name"
  • Loading branch information
pivotal-david-osullivan authored Oct 2, 2023
1 parent 0ffae26 commit 2bd4bfd
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 42 deletions.
12 changes: 2 additions & 10 deletions dependency_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ func (d *DependencyCache) Artifact(dependency BuildpackDependency, mods ...Reque
actual BuildpackDependency
artifact string
file string
hasher = sha256.New()
uri = dependency.URI
uriSha string
)

for d, u := range d.Mappings {
Expand All @@ -179,18 +177,12 @@ func (d *DependencyCache) Artifact(dependency BuildpackDependency, mods ...Reque
}
}

// downloaded artifact will have the uri sha as its filename
hasher.Write([]byte(uri))
uriSha = hex.EncodeToString(hasher.Sum(nil))

if dependency.SHA256 == "" {
d.Logger.Headerf("%s Dependency has no SHA256. Skipping cache.",
color.New(color.FgYellow, color.Bold).Sprint("Warning:"))

d.Logger.Bodyf("%s from %s", color.YellowString("Downloading"), uri)

artifact = filepath.Join(d.DownloadPath, uriSha)

artifact = filepath.Join(d.DownloadPath, filepath.Base(uri))
if err := d.download(uri, artifact, mods...); err != nil {
return nil, fmt.Errorf("unable to download %s\n%w", uri, err)
}
Expand Down Expand Up @@ -227,7 +219,7 @@ func (d *DependencyCache) Artifact(dependency BuildpackDependency, mods ...Reque
}

d.Logger.Bodyf("%s from %s", color.YellowString("Downloading"), uri)
artifact = filepath.Join(d.DownloadPath, dependency.SHA256, uriSha)
artifact = filepath.Join(d.DownloadPath, dependency.SHA256, filepath.Base(uri))
if err := d.download(uri, artifact, mods...); err != nil {
return nil, fmt.Errorf("unable to download %s\n%w", uri, err)
}
Expand Down
32 changes: 0 additions & 32 deletions dependency_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
package libpak_test

import (
"crypto/sha256"
"encoding/hex"
"fmt"
"hash"
"io"
"net/http"
"os"
Expand Down Expand Up @@ -158,7 +155,6 @@ func testDependencyCache(t *testing.T, context spec.G, it spec.S) {
downloadPath string
dependency libpak.BuildpackDependency
dependencyCache libpak.DependencyCache
hasher hash.Hash
server *ghttp.Server
)

Expand All @@ -168,8 +164,6 @@ func testDependencyCache(t *testing.T, context spec.G, it spec.S) {
cachePath = t.TempDir()
Expect(err).NotTo(HaveOccurred())

hasher = sha256.New()

downloadPath = t.TempDir()
Expect(err).NotTo(HaveOccurred())

Expand Down Expand Up @@ -323,32 +317,6 @@ func testDependencyCache(t *testing.T, context spec.G, it spec.S) {
Expect(io.ReadAll(a)).To(Equal([]byte("alternate-fixture")))
})

it("sets downloaded file name to uri's sha256", func() {
server.AppendHandlers(ghttp.RespondWith(http.StatusOK, "test-fixture"))

hasher.Write([]byte(dependency.URI))

a, err := dependencyCache.Artifact(dependency)
Expect(err).NotTo(HaveOccurred())

Expect(io.ReadAll(a)).To(Equal([]byte("test-fixture")))
Expect(filepath.Base(a.Name())).To(Equal(hex.EncodeToString(hasher.Sum(nil))))
})

it("sets downloaded file name to uri's sha256 with empty SHA256 and query parameters in the uri", func() {
dependency.SHA256 = ""
dependency.URI = fmt.Sprintf("%s/test-path?param1=value1&param2=value2", server.URL())
server.AppendHandlers(ghttp.RespondWith(http.StatusOK, "alternate-fixture"))

hasher.Write([]byte(dependency.URI))

a, err := dependencyCache.Artifact(dependency)
Expect(err).NotTo(HaveOccurred())

Expect(io.ReadAll(a)).To(Equal([]byte("alternate-fixture")))
Expect(filepath.Base(a.Name())).To(Equal(hex.EncodeToString(hasher.Sum(nil))))
})

it("sets User-Agent", func() {
server.AppendHandlers(ghttp.CombineHandlers(
ghttp.VerifyHeaderKV("User-Agent", "test-user-agent"),
Expand Down

0 comments on commit 2bd4bfd

Please sign in to comment.