diff --git a/layer.go b/layer.go index b7d9fe1..5210ff7 100644 --- a/layer.go +++ b/layer.go @@ -185,15 +185,26 @@ func (l *LayerContributor) normalizeDependencyDeprecationDate(input map[string]i if dep, ok := input["dependency"].(map[string]interface{}); ok { for k, v := range dep { if k == "deprecation_date" { - deprecationDate, err := l.parseDeprecationDate(v) - if err != nil { + if err := l.replaceDeprecationDate(dep, v); err != nil { return err } - dep["deprecation_date"] = deprecationDate break } } + } else if deprDate, ok := input["deprecation_date"]; ok { + if err := l.replaceDeprecationDate(input, deprDate); err != nil { + return err + } + } + return nil +} + +func (l *LayerContributor) replaceDeprecationDate(metadata map[string]interface{}, value interface{}) error { + deprecationDate, err := l.parseDeprecationDate(value) + if err != nil { + return err } + metadata["deprecation_date"] = deprecationDate return nil } diff --git a/layer_test.go b/layer_test.go index bedb599..5389cb0 100644 --- a/layer_test.go +++ b/layer_test.go @@ -541,6 +541,56 @@ func testLayer(t *testing.T, context spec.G, it spec.S) { Expect(called).To(BeFalse()) }) + it("does not contribute when deprecation_date is found on metadata map root", func() { + dependency = libpak.BuildModuleDependency{ + ID: "test-id", + Name: "test-name", + Version: "1.1.1", + URI: fmt.Sprintf("%s/test-path", server.URL()), + SHA256: "576dd8416de5619ea001d9662291d62444d1292a38e96956bc4651c01f14bca1", + Stacks: []string{"test-stack"}, + Licenses: []libpak.BuildModuleDependencyLicense{ + { + Type: "test-type", + URI: "test-uri", + }, + }, + CPEs: []string{"cpe:2.3:a:some:jre:11.0.2:*:*:*:*:*:*:*"}, + PURL: "pkg:generic/some-java11@11.0.2?arch=amd64", + } + dlc.ExpectedMetadata = dependency + + layer.Metadata = map[string]interface{}{ + "id": dependency.ID, + "name": dependency.Name, + "version": dependency.Version, + "uri": dependency.URI, + "sha256": dependency.SHA256, + "stacks": []interface{}{dependency.Stacks[0]}, + "licenses": []map[string]interface{}{ + { + "type": dependency.Licenses[0].Type, + "uri": dependency.Licenses[0].URI, + }, + }, + "cpes": []interface{}{"cpe:2.3:a:some:jre:11.0.2:*:*:*:*:*:*:*"}, + "purl": "pkg:generic/some-java11@11.0.2?arch=amd64", + "deprecation_date": "0001-01-01T00:00:00Z", + } + + var called bool + + err := dlc.Contribute(layer, func(layer *libcnb.Layer, artifact *os.File) error { + defer artifact.Close() + + called = true + return nil + }) + Expect(err).NotTo(HaveOccurred()) + + Expect(called).To(BeFalse()) + }) + it("does not call function with missing deprecation_date", func() { dependency = libpak.BuildModuleDependency{ ID: "test-id",