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

CycloneDX Validation #415

Merged
merged 9 commits into from
Aug 4, 2021
Merged

CycloneDX Validation #415

merged 9 commits into from
Aug 4, 2021

Conversation

jeffrey778zhan
Copy link
Contributor

@jeffrey778zhan jeffrey778zhan commented Jul 30, 2021

What Changed?
Added support to validate CycloneDX generated reports against json-schema.

How was it tested?
Unit tests

Usage of CycloneDX Schema
Usage of CycloneDX Json Schema approved

@@ -0,0 +1,1054 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The schema provided uses draft-07 compared to draft-04 which is the maximum version our json-schema gem supports. Potentially in another PR we'd like to support draft-04 and higher with this gem.

@jeffrey778zhan jeffrey778zhan changed the title CycloneDC Validation CycloneDX Validation Jul 31, 2021
@jeffrey778zhan jeffrey778zhan marked this pull request as ready for review August 4, 2021 16:15

# for each scanner report, run the appropriate converter
@scan_reports.each do |scan_report|
cyclonedx_report[:components] << converter(scan_report[0])
cyclonedx_report[:components] += converter(scan_report[0])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did convertor go from returning an item to returning an array?

Copy link
Contributor Author

@jeffrey778zhan jeffrey778zhan Aug 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, converter returns an array of components (i.e a list of components built from a gemfile) and the final CycloneDX report expects a list of components rather than a list of lists so had to make this change.

info = @scan_report.to_h.fetch(:info)
return [] unless info[:dependencies]
Copy link
Contributor

@ghbren ghbren Aug 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are no dependencies, would info[:dependencies] be nil or something like [] or {}?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep info[:dependencies] becomes nil which causes errors if the code execution proceeds to info[:dependencies].each leading to an exception

def initialize(scan_reports, config = {})
@scan_reports = scan_reports
@config = config
end

CYCLONEDX_SPEC_VERSION = "1.3".freeze
CYCLONEDX_VERSION = "1".freeze
CYCLONEDX_VERSION = 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was the freeze taken out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rubocop said it was redundant Style/RedundantFreeze: Do not freeze immutable objects, as freezing them has no effect.

@jeffrey778zhan jeffrey778zhan merged commit 0c0ce7c into master Aug 4, 2021
@jeffrey778zhan jeffrey778zhan deleted the jeffreyz/CycloneDX-Validator branch August 4, 2021 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants