Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion vulnerabilities/templates/advisory_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@
<summary class="is-size-7 has-text-link" style="cursor: pointer;">
View SSVC decision tree
</summary>
<pre>{{ ssvc.options|pprint }}</pre>
<pre>{{ ssvc.options_yaml }}</pre>
</details>
</div>
</div>
Expand Down
17 changes: 17 additions & 0 deletions vulnerabilities/tests/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from vulnerabilities.utils import get_purl_version_class
from vulnerabilities.views import PackageDetails
from vulnerabilities.views import PackageSearch
from vulnerabilities.views import render_as_yaml

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
TEST_DIR = os.path.join(BASE_DIR, "test_data/package_sort")
Expand Down Expand Up @@ -330,3 +331,19 @@ def test_aggregate_fixed_and_affected_packages(self):
end_time = time.time()
assert end_time - start_time < 0.05
self.assertEqual(response.status_code, 200)

class TestRenderAsYaml:
def test_render_as_yaml_with_ssvc_options(self):
options = [
{"Exploitation": "active"},
{"Automatable": "yes"},
{"Technical Impact": "total"},
]
result = render_as_yaml(options)
assert result == "- Exploitation: active\n- Automatable: yes\n- Technical Impact: total\n"

def test_render_as_yaml_with_none(self):
assert render_as_yaml(None) is None

def test_render_as_yaml_with_empty_list(self):
assert render_as_yaml([]) is None
6 changes: 5 additions & 1 deletion vulnerabilities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# See https://aboutcode.org for more information about nexB OSS projects.
#
import logging

import saneyaml
from cvss.exceptions import CVSS2MalformedError
from cvss.exceptions import CVSS3MalformedError
from cvss.exceptions import CVSS4MalformedError
Expand Down Expand Up @@ -48,6 +48,9 @@

PAGE_SIZE = 20

def render_as_yaml(value):
if value:
return saneyaml.dump(value, indent=2)

class PackageSearch(ListView):
model = models.Package
Expand Down Expand Up @@ -559,6 +562,7 @@ def add_ssvc(ssvc):
"vector": ssvc.vector,
"decision": ssvc.decision,
"options": ssvc.options,
"options_yaml": render_as_yaml(ssvc.options),
"advisory_url": ssvc.source_advisory.url,
"advisory": ssvc.source_advisory,
}
Expand Down