Skip to content
Open
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
3 changes: 2 additions & 1 deletion vulnerabilities/templates/advisory_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{% load static %}
{% load show_cvss %}
{% load url_filters %}
{% load ssvc_filters %}

{% block title %}
VulnerableCode Advisory Details - {{ advisory.advisory_id }}
Expand Down Expand Up @@ -583,7 +584,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|to_yaml }}</pre>
</details>
</div>
</div>
Expand Down
28 changes: 28 additions & 0 deletions vulnerabilities/templatetags/ssvc_filters.py
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)

38 changes: 38 additions & 0 deletions vulnerabilities/tests/test_ssvc_filters.py
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():
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
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)