Skip to content

Commit

Permalink
Merge pull request #108 from dmikusa-pivotal/gh_issue_107
Browse files Browse the repository at this point in the history
  • Loading branch information
samj1912 committed Jan 11, 2022
2 parents c9ad73f + 45c858b commit 896a63b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
8 changes: 5 additions & 3 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,11 @@ func Build(builder Builder, options ...Option) {
}
}

if err := validateSBOMFormats(ctx.Layers.Path, ctx.Buildpack.Info.SBOMFormats); err != nil {
config.exitHandler.Error(fmt.Errorf("unable to validate SBOM\n%w", err))
return
if API != "0.1" && API != "0.2" && API != "0.3" && API != "0.4" && API != "0.5" && API != "0.6" {
if err := validateSBOMFormats(ctx.Layers.Path, ctx.Buildpack.Info.SBOMFormats); err != nil {
config.exitHandler.Error(fmt.Errorf("unable to validate SBOM\n%w", err))
return
}
}

// Deprecated: as of Buildpack API 0.7, to be removed in a future version
Expand Down
24 changes: 24 additions & 0 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,30 @@ sbom-formats = []
Expect(exitHandler.Calls[0].Arguments.Get(0)).To(MatchError("unable to validate SBOM\nunable to find actual SBOM Type application/spdx+json in list of supported SBOM types []"))
})

it("skips if API is not 0.7", func() {
Expect(ioutil.WriteFile(filepath.Join(buildpackPath, "buildpack.toml"),
[]byte(`
api = "0.6"
[buildpack]
id = "test-id"
name = "test-name"
version = "1.1.1"
sbom-formats = []
`),
0600),
).To(Succeed())

Expect(ioutil.WriteFile(filepath.Join(layersPath, "launch.sbom.spdx.json"), []byte{}, 0600)).To(Succeed())

libcnb.Build(builder,
libcnb.WithArguments([]string{commandPath, layersPath, platformPath, buildpackPlanPath}),
libcnb.WithExitHandler(exitHandler),
)

Expect(exitHandler.Calls).To(BeEmpty())
})

it("has no matching formats", func() {
Expect(ioutil.WriteFile(filepath.Join(layersPath, "launch.sbom.spdx.json"), []byte{}, 0600)).To(Succeed())

Expand Down

0 comments on commit 896a63b

Please sign in to comment.