Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "adds logic to remove http query params from destination file name" #290

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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