Skip to content

Commit

Permalink
test: remove SBOM test (#1465)
Browse files Browse the repository at this point in the history
The SBOM focused test is no longer needed because the SBOM is no longer
injected into the container image. This was removed in a separate PR in
the buildah task.

JIRA: ISV-5411

Signed-off-by: Ales Raszka <[email protected]>
  • Loading branch information
Allda authored Nov 27, 2024
1 parent a9824c8 commit 4e5e1cd
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 117 deletions.
75 changes: 0 additions & 75 deletions pkg/utils/build/sbom.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,6 @@
package build

import (
"encoding/json"
"fmt"
"os"
)

func GetParsedSbomFilesContentFromImage(image string) (*SbomPurl, *SbomCyclonedx, error) {
tmpDir, err := ExtractImage(image)
defer os.RemoveAll(tmpDir)
if err != nil {
return nil, nil, err
}

purl, err := getSbomPurlContent(tmpDir)
if err != nil {
return nil, nil, fmt.Errorf("failed to get sbom purl content: %+v", err)
}

cyclonedx, err := getSbomCyclonedxContent(tmpDir)
if err != nil {
return nil, nil, fmt.Errorf("failed to get sbom cyclonedx content: %+v", err)
}
return purl, cyclonedx, nil
}

type SbomPurl struct {
ImageContents struct {
Dependencies []struct {
Purl string `json:"purl"`
} `json:"dependencies"`
} `json:"image_contents"`
}

type SbomCyclonedx struct {
BomFormat string
Expand All @@ -44,47 +13,3 @@ type SbomCyclonedx struct {
Version string `json:"version"`
} `json:"components"`
}

func getSbomPurlContent(rootDir string) (*SbomPurl, error) {
sbomPurlFilePath := rootDir + "/root/buildinfo/content_manifests/sbom-purl.json"
file, err := os.Stat(sbomPurlFilePath)
if err != nil {
return nil, fmt.Errorf("sbom file not found in path %s", sbomPurlFilePath)
}
if file.Size() == 0 {
return nil, fmt.Errorf("sbom file %s is empty", sbomPurlFilePath)
}

b, err := os.ReadFile(sbomPurlFilePath)
if err != nil {
return nil, fmt.Errorf("error when reading sbom file %s: %v", sbomPurlFilePath, err)
}
sbom := &SbomPurl{}
if err := json.Unmarshal(b, sbom); err != nil {
return nil, fmt.Errorf("error when parsing sbom PURL json: %v", err)
}

return sbom, nil
}

func getSbomCyclonedxContent(rootDir string) (*SbomCyclonedx, error) {
sbomCyclonedxFilePath := rootDir + "/root/buildinfo/content_manifests/sbom-cyclonedx.json"
file, err := os.Stat(sbomCyclonedxFilePath)
if err != nil {
return nil, fmt.Errorf("sbom file not found in path %s", sbomCyclonedxFilePath)
}
if file.Size() == 0 {
return nil, fmt.Errorf("sbom file %s is empty", sbomCyclonedxFilePath)
}

b, err := os.ReadFile(sbomCyclonedxFilePath)
if err != nil {
return nil, fmt.Errorf("error when reading sbom file %s: %v", sbomCyclonedxFilePath, err)
}
sbom := &SbomCyclonedx{}
if err := json.Unmarshal(b, sbom); err != nil {
return nil, fmt.Errorf("error when parsing sbom CycloneDX json: %v", err)
}

return sbom, nil
}
29 changes: 0 additions & 29 deletions tests/build/build_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,35 +597,6 @@ var _ = framework.BuildSuiteDescribe("Build templates E2E test", Label("build",
ContainElements(tekton.MatchTaskRunResultWithJSONPathValue(constants.TektonTaskTestOutputName, "{$.result}", `["SUCCESS"]`)),
)
})
It("contains non-empty sbom files", Label(buildTemplatesTestLabel), func() {
purl, cyclonedx, err := build.GetParsedSbomFilesContentFromImage(imageWithDigest)
Expect(err).NotTo(HaveOccurred())

Expect(cyclonedx.BomFormat).To(Equal("CycloneDX"))
Expect(cyclonedx.SpecVersion).ToNot(BeEmpty())
Expect(cyclonedx.Version).ToNot(BeZero())
if !strings.Contains(scenario.GitURL, "from-scratch") {
Expect(cyclonedx.Components).ToNot(BeEmpty())

numberOfLibraryComponents := 0
for _, component := range cyclonedx.Components {
Expect(component.Name).ToNot(BeEmpty())
Expect(component.Type).ToNot(BeEmpty())

if component.Type == "library" || component.Type == "application" {
Expect(component.Purl).ToNot(BeEmpty())
numberOfLibraryComponents++
}
}

Expect(purl.ImageContents.Dependencies).ToNot(BeEmpty())
Expect(purl.ImageContents.Dependencies).To(HaveLen(numberOfLibraryComponents))

for _, dependency := range purl.ImageContents.Dependencies {
Expect(dependency.Purl).ToNot(BeEmpty())
}
}
})
})

Context("build-definitions ec pipelines", Label(buildTemplatesTestLabel), func() {
Expand Down
14 changes: 1 addition & 13 deletions tests/konflux-demo/konflux-demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,19 +265,7 @@ var _ = framework.KonfluxDemoSuiteDescribe(Label(devEnvTestLabel), func() {
})

When("Build PipelineRun completes successfully", func() {
It("should be possible to download the SBOM file", func() {
var outputImage string
for _, p := range pipelineRun.Spec.Params {
if p.Name == "output-image" {
outputImage = p.Value.StringVal
}
}
Expect(outputImage).ToNot(BeEmpty(), "output image of a component could not be found")

_, _, err = build.GetParsedSbomFilesContentFromImage(outputImage)
Expect(err).NotTo(HaveOccurred())
})


It("should validate Tekton TaskRun test results successfully", func() {
pipelineRun, err = fw.AsKubeAdmin.HasController.GetComponentPipelineRun(component.GetName(), appSpec.ApplicationName, fw.UserNamespace, headSHA)
Expect(err).ShouldNot(HaveOccurred())
Expand Down

0 comments on commit 4e5e1cd

Please sign in to comment.