Skip to content

Commit 4a8b41e

Browse files
Use saneyaml.dump for SSVC display in UI
1 parent 053c8fb commit 4a8b41e

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

vulnerabilities/templates/advisory_detail.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@
583583
<summary class="is-size-7 has-text-link" style="cursor: pointer;">
584584
View SSVC decision tree
585585
</summary>
586-
<pre>{{ ssvc.options|pprint }}</pre>
586+
<pre>{{ ssvc.options_yaml }}</pre>
587587
</details>
588588
</div>
589589
</div>

vulnerabilities/tests/test_view.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from vulnerabilities.utils import get_purl_version_class
2727
from vulnerabilities.views import PackageDetails
2828
from vulnerabilities.views import PackageSearch
29+
from vulnerabilities.views import render_as_yaml
2930

3031
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
3132
TEST_DIR = os.path.join(BASE_DIR, "test_data/package_sort")
@@ -330,3 +331,19 @@ def test_aggregate_fixed_and_affected_packages(self):
330331
end_time = time.time()
331332
assert end_time - start_time < 0.05
332333
self.assertEqual(response.status_code, 200)
334+
335+
class TestRenderAsYaml:
336+
def test_render_as_yaml_with_ssvc_options(self):
337+
options = [
338+
{"Exploitation": "active"},
339+
{"Automatable": "yes"},
340+
{"Technical Impact": "total"},
341+
]
342+
result = render_as_yaml(options)
343+
assert result == "- Exploitation: active\n- Automatable: yes\n- Technical Impact: total\n"
344+
345+
def test_render_as_yaml_with_none(self):
346+
assert render_as_yaml(None) is None
347+
348+
def test_render_as_yaml_with_empty_list(self):
349+
assert render_as_yaml([]) is None

vulnerabilities/views.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# See https://aboutcode.org for more information about nexB OSS projects.
88
#
99
import logging
10-
10+
import saneyaml
1111
from cvss.exceptions import CVSS2MalformedError
1212
from cvss.exceptions import CVSS3MalformedError
1313
from cvss.exceptions import CVSS4MalformedError
@@ -45,6 +45,9 @@
4545

4646
PAGE_SIZE = 20
4747

48+
def render_as_yaml(value):
49+
if value:
50+
return saneyaml.dump(value, indent=2)
4851

4952
class PackageSearch(ListView):
5053
model = models.Package
@@ -522,6 +525,7 @@ def add_ssvc(ssvc):
522525
"vector": ssvc.vector,
523526
"decision": ssvc.decision,
524527
"options": ssvc.options,
528+
"options_yaml": render_as_yaml(ssvc.options),
525529
"advisory_url": ssvc.source_advisory.url,
526530
"advisory": ssvc.source_advisory,
527531
}

0 commit comments

Comments
 (0)