Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: remove SBOM test #1465

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading