-
-
Notifications
You must be signed in to change notification settings - Fork 281
Improve display of SSVC decision tree in UI using YAML format #2058 #2165
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
base: main
Are you sure you want to change the base?
Changes from all commits
e4c0a6b
18c5a55
a4f2a66
4065892
82913a6
3ae1108
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # | ||
| # Copyright (c) nexB Inc. and others. All rights reserved. | ||
| # VulnerableCode is a trademark of nexB Inc. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # See http://www.apache.org/licenses/LICENSE-2.0 for the license text. | ||
| # See https://github.com/aboutcode-org/vulnerablecode for support or download. | ||
| # See https://aboutcode.org for more information about nexB OSS projects. | ||
| # | ||
|
|
||
| import saneyaml | ||
| from django import template | ||
|
|
||
| register = template.Library() | ||
|
|
||
|
|
||
| @register.filter(name="to_yaml") | ||
| def to_yaml(value): | ||
| """ | ||
| Convert a Python object (typically SSVC options) to a | ||
| human-readable YAML string. | ||
| """ | ||
| if not value: | ||
| return "" | ||
| try: | ||
| return saneyaml.dump(value).strip() | ||
| except Exception: | ||
| return str(value) | ||
|
Member
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. Why not keeping the pprint behavior there? And why would there be a case that raises an exception? Is the exception really needed? |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # | ||
| # Copyright (c) nexB Inc. and others. All rights reserved. | ||
| # VulnerableCode is a trademark of nexB Inc. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # See http://www.apache.org/licenses/LICENSE-2.0 for the license text. | ||
| # See https://github.com/aboutcode-org/vulnerablecode for support or download. | ||
| # See https://aboutcode.org for more information about nexB OSS projects. | ||
| # | ||
|
|
||
| from vulnerabilities.templatetags.ssvc_filters import to_yaml | ||
|
|
||
|
|
||
| def test_to_yaml_with_ssvc_options(): | ||
|
Member
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. These tests are essentially testing the saneyaml library that is already tested. Can you test the tag instead? (I though I question using a filter is what we want here.) |
||
| options = [ | ||
| {"Exploitation": "active"}, | ||
| {"Automatable": "yes"}, | ||
| {"Technical Impact": "total"}, | ||
| {"Mission Prevalence": "essential"}, | ||
| {"Public Well-being Impact": "irreversible"}, | ||
| {"Mission & Well-being": "high"}, | ||
| ] | ||
| result = to_yaml(options) | ||
| assert "Exploitation: active" in result | ||
|
Member
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. I am not sure this series of asserts has a lot of value. Why not assert at once the whole "result" string? |
||
| assert "Technical Impact: total" in result | ||
| assert "Mission Prevalence: essential" in result | ||
| assert "Public Well-being Impact: irreversible" in result | ||
|
|
||
|
|
||
| def test_to_yaml_with_empty_value(): | ||
| assert to_yaml(None) == "" | ||
| assert to_yaml([]) == "" | ||
| assert to_yaml("") == "" | ||
|
|
||
|
|
||
| def test_to_yaml_with_non_serializable_value(): | ||
| result = to_yaml("plain string") | ||
| assert isinstance(result, str) | ||
|
|
||
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.
Is this generic? if yes, remove references to SSVC.
Also why not indent? And we have similar code in SCIO https://github.com/aboutcode-org/scancode.io/blob/d6b14acbb94ecfef52b3dbe34c1cd7f5f112e4bf/scanpipe/views.py#L206C5-L206C19 with a different approach. What about using that approach instead? @tdruez FYI