Skip to content

Commit

Permalink
Enable Alternative Checksum format of algorithm_hash (#526)
Browse files Browse the repository at this point in the history
* Enable Alternative Checksum format of algorithm-hash

* Adjust alternate delimeter from - to _.

* Update comment with algorithm_hash

Co-authored-by: Sophie Wigmore <sophiemwigmore@gmail.com>

---------

Co-authored-by: Sophie Wigmore <swigmore@vmware.com>
Co-authored-by: Sophie Wigmore <sophiemwigmore@gmail.com>
  • Loading branch information
3 people authored Oct 23, 2023
1 parent 14ebfa0 commit fb332c0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions postal/internal/dependency_mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ func (d DependencyMappingResolver) FindDependencyMapping(checksum, platformDir s
return "", err
}
return strings.TrimSpace(content), nil
// binding provided in the form `algorithm_hash`
} else if uri, ok := binding.Entries[strings.Replace(checksum, ":", "_", 1)]; ok {
content, err := uri.ReadString()
if err != nil {
return "", err
}
return strings.TrimSpace(content), nil
}
}

Expand Down
19 changes: 19 additions & 0 deletions postal/internal/dependency_mappings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ func testDependencyMappings(t *testing.T, context spec.G, it spec.S) {
"sha512:other-sha": servicebindings.NewEntry(filepath.Join(tmpDir, "entry-data")),
},
},
{
Name: "other-binding-with-hyphen",
Path: "hypen-another-",
Type: "dependency-mapping",
Entries: map[string]*servicebindings.Entry{
"sha-512_other-sha-underscore": servicebindings.NewEntry(filepath.Join(tmpDir, "entry-data")),
},
},
{
Name: "another-binding",
Path: "another-path",
Expand Down Expand Up @@ -85,6 +93,17 @@ func testDependencyMappings(t *testing.T, context spec.G, it spec.S) {
})
})

context("the binding is of format <algorithm>_<hash>", func() {
it("finds a matching dependency mappings in the platform bindings if there is one", func() {
boundDependency, err := resolver.FindDependencyMapping("sha-512:other-sha-underscore", "some-platform-dir")
Expect(err).ToNot(HaveOccurred())
Expect(bindingResolver.ResolveCall.Receives.Typ).To(Equal("dependency-mapping"))
Expect(bindingResolver.ResolveCall.Receives.Provider).To(BeEmpty())
Expect(bindingResolver.ResolveCall.Receives.PlatformDir).To(Equal("some-platform-dir"))
Expect(boundDependency).To(Equal("dependency-mapping-entry.tgz"))
})
})

context("the binding does not contain an algorithm", func() {
it("does not find matching dependency mapping when input isn't of sha256 algorithm", func() {
boundDependency, err := resolver.FindDependencyMapping("sha512:some-sha", "some-platform-dir")
Expand Down

0 comments on commit fb332c0

Please sign in to comment.