-
Notifications
You must be signed in to change notification settings - Fork 532
Add basic json output #418
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e43f284
Refactor code to prepare for other output formats
mariuszskon 72564e2
Add naive json formatting
mariuszskon f140ee7
Structure json more nicely
mariuszskon 2f96f8b
Add test for formatted_modules in OutputEngine
mariuszskon 8f3fc23
Add test for output_json in OutputEngine
mariuszskon de74d85
Refactor OutputEngine tests to reduce code repetition
mariuszskon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,44 @@ | ||
""" | ||
CVE-bin-tool OutputEngine tests | ||
""" | ||
import unittest | ||
import io | ||
import json | ||
|
||
from cve_bin_tool.OutputEngine import OutputEngine | ||
|
||
|
||
class TestOutputEngine(unittest.TestCase): | ||
""" Test the OutputEngine class functions """ | ||
|
||
MOCK_MODULES = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hurrah for mock tests! |
||
"modulename0": { | ||
"1.0": {"CVE-1234-1234": "MEDIUM", "CVE-1234-9876": "LOW",}, | ||
"2.8.6": {"CVE-1234-1111": "LOW",}, | ||
}, | ||
"modulename1": {"3.2.1.0": {"CVE-1234-5678": "HIGH",}}, | ||
} | ||
FORMATTED_MODULES = { | ||
"modulename0": { | ||
"1.0": [ | ||
{"cve": "CVE-1234-1234", "severity": "MEDIUM"}, | ||
{"cve": "CVE-1234-9876", "severity": "LOW"}, | ||
], | ||
"2.8.6": [{"cve": "CVE-1234-1111", "severity": "LOW"},], | ||
}, | ||
"modulename1": {"3.2.1.0": [{"cve": "CVE-1234-5678", "severity": "HIGH"},]}, | ||
} | ||
|
||
def setUp(self): | ||
self.output_engine = OutputEngine(modules=self.MOCK_MODULES) | ||
self.mock_file = io.StringIO() | ||
|
||
def test_formatted_modules(self): | ||
""" Test reformatting modules """ | ||
self.assertEqual(self.output_engine.formatted_modules(), self.FORMATTED_MODULES) | ||
|
||
def test_output_json(self): | ||
""" Test formatting output as JSON """ | ||
self.output_engine.output_json(self.mock_file) | ||
self.mock_file.seek(0) # reset file position | ||
self.assertEqual(json.load(self.mock_file), self.FORMATTED_MODULES) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't decide if this should be
cve_number
(rather thancve
) for consistency, since we use cve_number just about anywhere we refer to a single number (as opposed to a list of cves). I think rather than hold up a review for this I'm going to just merge, but we might have to revisit when we see what the dffml team decides they actually want out of the json output and whether the difference matters to them. @pdxjohnny if you have an opinion now, maybe we could open an issue to discuss what "ideal" json output will look like?