diff --git a/layer.go b/layer.go index 68bac99..6eefa05 100644 --- a/layer.go +++ b/layer.go @@ -146,19 +146,30 @@ 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 depr_date, ok := input["deprecation_date"]; ok { + if err := l.replaceDeprecationDate(input, depr_date); 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 +} + // parseDeprecationDate accepts both string and time.Time as input, and returns // a truncated time.Time value. func (l *LayerContributor) parseDeprecationDate(v interface{}) (deprecationDate time.Time, err error) { diff --git a/layer_test.go b/layer_test.go index 15334f3..28c20b8 100644 --- a/layer_test.go +++ b/layer_test.go @@ -636,6 +636,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.BuildpackDependency{ + 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.BuildpackDependencyLicense{ + { + 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(artifact *os.File) (libcnb.Layer, error) { + defer artifact.Close() + + called = true + return layer, nil + }) + Expect(err).NotTo(HaveOccurred()) + + Expect(called).To(BeFalse()) + }) + it("does not call function with missing deprecation_date", func() { dependency = libpak.BuildpackDependency{ ID: "test-id",