Skip to content

Commit

Permalink
get things happy after rebase on master
Browse files Browse the repository at this point in the history
  • Loading branch information
bhamail committed Apr 20, 2020
1 parent 33af791 commit 91e232b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
7 changes: 3 additions & 4 deletions cyclonedx/cyclonedx.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"encoding/xml"

"github.com/package-url/packageurl-go"
"github.com/sonatype-nexus-community/nancy/customerrors"
. "github.com/sonatype-nexus-community/nancy/logger"
"github.com/sonatype-nexus-community/nancy/types"
)
Expand All @@ -33,7 +32,7 @@ const version = "1"

// ProcessPurlsIntoSBOM will take a slice of packageurl.PackageURL and convert them
// into a minimal 1.1 CycloneDX sbom
func ProcessPurlsIntoSBOM(results []types.Coordinate) (string, error) {
func ProcessPurlsIntoSBOM(results []types.Coordinate) string {
return processPurlsIntoSBOMSchema1_1(results)
}

Expand Down Expand Up @@ -92,7 +91,7 @@ func processPurlsIntoSBOMSchema1_1(results []types.Coordinate) string {
for _, v := range results {
purl, err := packageurl.FromString(v.Coordinates)
if err != nil {
return "", err
return ""
}

component := types.Component{
Expand Down Expand Up @@ -143,5 +142,5 @@ func processAndReturnSbom(sbom *types.Sbom) string {

output = []byte(xml.Header + string(output))

return string(output), err
return string(output)
}
17 changes: 6 additions & 11 deletions cyclonedx/cyclonedx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

func TestCreateSBOMFromPackageURLs(t *testing.T) {
results := []packageurl.PackageURL{}
var results []packageurl.PackageURL
uno, _ := packageurl.FromString("pkg:golang/github.com/test/test@1.0.0")
results = append(results, uno)

Expand Down Expand Up @@ -65,7 +65,7 @@ func TestCreateSBOMFromPackageURLs(t *testing.T) {
}

func TestCreateSBOMFromSHA1s(t *testing.T) {
results := []types.Sha1SBOM{}
var results []types.Sha1SBOM
uno := types.Sha1SBOM{Location: "/path/on/disk", Sha1: "c2843e01d9a2"}
results = append(results, uno)

Expand Down Expand Up @@ -128,8 +128,7 @@ func TestProcessPurlsIntoSBOM(t *testing.T) {
Reference: "https://ossindex.sonatype.org/component/pkg:golang/github.com/go-yaml/yaml@v2.2.2",
Vulnerabilities: []types.Vulnerability{},
})
result, err := ProcessPurlsIntoSBOM(results)
assert.Equal(t, nil, err)
result := ProcessPurlsIntoSBOM(results)

doc := etree.NewDocument()

Expand Down Expand Up @@ -216,8 +215,7 @@ func assertBaseXMLValid(doc *etree.Element, t *testing.T) {

func TestProcess1_1NoError(t *testing.T) {
var results []types.Coordinate
sbom, err := processPurlsIntoSBOMSchema1_1(results)
assert.Equal(t, nil, err)
sbom := processPurlsIntoSBOMSchema1_1(results)
assert.Equal(t, `<?xml version="1.0" encoding="UTF-8"?>
<bom xmlns="http://cyclonedx.org/schema/bom/1.1" xmlns:v="http://cyclonedx.org/schema/ext/vulnerability/1.0" version="1">
<components></components>
Expand All @@ -231,16 +229,13 @@ func TestProcess1_1WithCoordinate(t *testing.T) {
},
}

sbom, err := processPurlsIntoSBOMSchema1_1(results)
assert.NotEqual(t, nil, err)
assert.Equal(t, "scheme is missing", err.Error())
sbom := processPurlsIntoSBOMSchema1_1(results)
assert.Equal(t, "", sbom)
}

func TestProcessWithError(t *testing.T) {
var results []types.Coordinate
sbom, err := ProcessPurlsIntoSBOM(results)
assert.Equal(t, nil, err)
sbom := ProcessPurlsIntoSBOM(results)
assert.Equal(t, `<?xml version="1.0" encoding="UTF-8"?>
<bom xmlns="http://cyclonedx.org/schema/bom/1.1" xmlns:v="http://cyclonedx.org/schema/ext/vulnerability/1.0" version="1">
<components></components>
Expand Down
5 changes: 1 addition & 4 deletions iq/iq.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ func AuditPackages(purls []string, applicationID string, config configuration.Iq
return statusURLResp, customerrors.ErrorExit{ExitCode: 3, Err: err, Message: "There was an issue auditing packages using OSS Index"}
}

sbom, err := cyclonedx.ProcessPurlsIntoSBOM(resultsFromOssIndex)
if err != nil {
return types.StatusURLResult{}, err
}
sbom := cyclonedx.ProcessPurlsIntoSBOM(resultsFromOssIndex)
LogLady.WithField("sbom", sbom).Debug("Obtained cyclonedx SBOM")

LogLady.WithFields(logrus.Fields{
Expand Down

0 comments on commit 91e232b

Please sign in to comment.