-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* SBOM convert command Signed-off-by: Charles Hu <[email protected]> * Fix tests Signed-off-by: Charles Hu <[email protected]> * SBOM update Signed-off-by: Charles Hu <[email protected]> * Example SPDX to CycloneDX added Signed-off-by: Charles Hu <[email protected]> * Testing changes; README blurb Signed-off-by: Charles Hu <[email protected]> * Blurb update Signed-off-by: Charles Hu <[email protected]> * Linting Signed-off-by: Charles Hu <[email protected]> * Input check update Signed-off-by: Charles Hu <[email protected]> --------- Signed-off-by: Charles Hu <[email protected]> Co-authored-by: Amndeep Singh Mann <[email protected]>
- Loading branch information
1 parent
a6f0a50
commit f406b49
Showing
25 changed files
with
471,126 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import {Command, Flags} from '@oclif/core' | ||
import fs from 'fs' | ||
import {CycloneDXSBOMResults as Mapper} from '@mitre/hdf-converters' | ||
import {checkInput, checkSuffix} from '../../utils/global' | ||
|
||
export default class CycloneDXSBOM2HDF extends Command { | ||
static usage = 'convert cyclonedx_sbom2hdf -i <cyclonedx_sbom-json> -o <hdf-scan-results-json> [-h] [-w]' | ||
|
||
static description = 'Translate a CycloneDX SBOM report into an HDF results set' | ||
|
||
static examples = ['saf convert cyclonedx_sbom2hdf -i cyclonedx_sbom.json -o output-hdf-name.json'] | ||
|
||
static flags = { | ||
help: Flags.help({char: 'h'}), | ||
input: Flags.string({char: 'i', required: true, description: 'Input CycloneDX SBOM file'}), | ||
output: Flags.string({char: 'o', required: true, description: 'Output HDF JSON file'}), | ||
'with-raw': Flags.boolean({char: 'w', required: false, description: 'Include raw input file in HDF JSON file'}), | ||
} | ||
|
||
async run() { | ||
const {flags} = await this.parse(CycloneDXSBOM2HDF) | ||
|
||
// Check for correct input type | ||
const data = fs.readFileSync(flags.input, 'utf8') | ||
checkInput({data, filename: flags.input}, 'cyclonedx_sbom', 'CycloneDX SBOM output file') | ||
|
||
const converter = new Mapper(data, flags['with-raw']) | ||
fs.writeFileSync(checkSuffix(flags.output), JSON.stringify(converter.toHdf(), null, 2)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import {expect, test} from '@oclif/test' | ||
import tmp from 'tmp' | ||
import path from 'path' | ||
import fs from 'fs' | ||
import {omitHDFChangingFields} from '../utils' | ||
|
||
describe('Test sbom', () => { | ||
const tmpobj = tmp.dirSync({unsafeCleanup: true}) | ||
|
||
test | ||
.stdout() | ||
.command(['convert cyclonedx_sbom2hdf', '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/dropwizard-no-vulns.json'), '-o', `${tmpobj.name}/cyclonedx_sbom.json`]) | ||
.it('hdf-converter output test - dropwizard no vulns', () => { | ||
const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) | ||
const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-dropwizard-no-vulns-hdf.json'), 'utf8')) | ||
expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) | ||
}) | ||
test | ||
.stdout() | ||
.command(['convert cyclonedx_sbom2hdf', '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/dropwizard-vex.json'), '-o', `${tmpobj.name}/cyclonedx_sbom.json`]) | ||
.it('hdf-converter output test - dropwizard vex', () => { | ||
const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) | ||
const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-dropwizard-vex-hdf.json'), 'utf8')) | ||
expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) | ||
}) | ||
test | ||
.stdout() | ||
.command(['convert cyclonedx_sbom2hdf', '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/dropwizard-vulns.json'), '-o', `${tmpobj.name}/cyclonedx_sbom.json`]) | ||
.it('hdf-converter output test - dropwizard w/ vulns', () => { | ||
const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) | ||
const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-dropwizard-vulns-hdf.json'), 'utf8')) | ||
expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) | ||
}) | ||
test | ||
.stdout() | ||
.command(['convert cyclonedx_sbom2hdf', '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/generated-saf-sbom.json'), '-o', `${tmpobj.name}/cyclonedx_sbom.json`]) | ||
.it('hdf-converter output test - saf', () => { | ||
const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) | ||
const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-saf-hdf.json'), 'utf8')) | ||
expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) | ||
}) | ||
test | ||
.stdout() | ||
.command(['convert cyclonedx_sbom2hdf', '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/vex.json'), '-o', `${tmpobj.name}/cyclonedx_sbom.json`]) | ||
.it('hdf-converter output test - vex', () => { | ||
const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) | ||
const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-vex-hdf.json'), 'utf8')) | ||
expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) | ||
}) | ||
test | ||
.stdout() | ||
.command(['convert cyclonedx_sbom2hdf', '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/spdx-to-cyclonedx.json'), '-o', `${tmpobj.name}/cyclonedx_sbom.json`]) | ||
.it('hdf-converter output test - spdx converted cyclonedx', () => { | ||
const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) | ||
const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-converted-spdx-hdf.json'), 'utf8')) | ||
expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) | ||
}) | ||
test | ||
.stdout() | ||
.command(['convert cyclonedx_sbom2hdf', '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/syft-scan-alpine-container.json'), '-o', `${tmpobj.name}/cyclonedx_sbom.json`]) | ||
.it('hdf-converter output test - syft-generated alpine container', () => { | ||
const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) | ||
const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-syft-alpine-container-hdf.json'), 'utf8')) | ||
expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) | ||
}) | ||
}) | ||
|
||
describe('Test sbom using withraw flag', () => { | ||
const tmpobj = tmp.dirSync({unsafeCleanup: true}) | ||
|
||
test | ||
.stdout() | ||
.command(['convert cyclonedx_sbom2hdf', '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/dropwizard-no-vulns.json'), '-o', `${tmpobj.name}/cyclonedx_sbom.json`, '-w']) | ||
.it('hdf-converter withraw output test - dropwizard no vulns', () => { | ||
const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) | ||
const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-dropwizard-no-vulns-hdf-withraw.json'), 'utf8')) | ||
expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) | ||
}) | ||
test | ||
.stdout() | ||
.command(['convert cyclonedx_sbom2hdf', '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/dropwizard-vex.json'), '-o', `${tmpobj.name}/cyclonedx_sbom.json`, '-w']) | ||
.it('hdf-converter withraw output test - dropwizard vex', () => { | ||
const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) | ||
const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-dropwizard-vex-hdf-withraw.json'), 'utf8')) | ||
expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) | ||
}) | ||
test | ||
.stdout() | ||
.command(['convert cyclonedx_sbom2hdf', '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/dropwizard-vulns.json'), '-o', `${tmpobj.name}/cyclonedx_sbom.json`, '-w']) | ||
.it('hdf-converter withraw output test - dropwizard w/ vulns', () => { | ||
const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) | ||
const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-dropwizard-vulns-hdf-withraw.json'), 'utf8')) | ||
expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) | ||
}) | ||
test | ||
.stdout() | ||
.command(['convert cyclonedx_sbom2hdf', '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/generated-saf-sbom.json'), '-o', `${tmpobj.name}/cyclonedx_sbom.json`, '-w']) | ||
.it('hdf-converter withraw output test - saf', () => { | ||
const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) | ||
const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-saf-hdf-withraw.json'), 'utf8')) | ||
expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) | ||
}) | ||
test | ||
.stdout() | ||
.command(['convert cyclonedx_sbom2hdf', '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/vex.json'), '-o', `${tmpobj.name}/cyclonedx_sbom.json`, '-w']) | ||
.it('hdf-converter withraw output test - vex', () => { | ||
const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) | ||
const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-vex-hdf-withraw.json'), 'utf8')) | ||
expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) | ||
}) | ||
test | ||
.stdout() | ||
.command(['convert cyclonedx_sbom2hdf', '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/spdx-to-cyclonedx.json'), '-o', `${tmpobj.name}/cyclonedx_sbom.json`, '-w']) | ||
.it('hdf-converter withraw output test - spdx converted cyclonedx', () => { | ||
const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) | ||
const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-converted-spdx-hdf-withraw.json'), 'utf8')) | ||
expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) | ||
}) | ||
test | ||
.stdout() | ||
.command(['convert cyclonedx_sbom2hdf', '-i', path.resolve('./test/sample_data/cyclonedx_sbom/sample_input_report/syft-scan-alpine-container.json'), '-o', `${tmpobj.name}/cyclonedx_sbom.json`, '-w']) | ||
.it('hdf-converter withraw output test - syft-generated alpine container', () => { | ||
const converted = JSON.parse(fs.readFileSync(`${tmpobj.name}/cyclonedx_sbom.json`, 'utf8')) | ||
const sample = JSON.parse(fs.readFileSync(path.resolve('./test/sample_data/cyclonedx_sbom/sbom-syft-alpine-container-hdf-withraw.json'), 'utf8')) | ||
expect(omitHDFChangingFields(converted)).to.eql(omitHDFChangingFields(sample)) | ||
}) | ||
}) |
Oops, something went wrong.