Skip to content

Commit

Permalink
docs(almalinux-importer): Add docstring to parse_advisory_data func…
Browse files Browse the repository at this point in the history
…tion

- Added a detailed docstring to the `parse_advisory_data` function in the `almalinux-importer` module.
- The docstring includes a clear description of the function's purpose, arguments, return value, and an example usage.
- Improved the readability and structure of the example output in the docstring to ensure clarity and consistency.

This documentation enhancement makes the `parse_advisory_data` function easier to understand and use, aiding future development and maintenance.

Signed-off-by: ambuj <kulshreshthaak.12@gmail.com>
  • Loading branch information
ambuj-1211 committed Aug 23, 2024
1 parent c679856 commit 088279c
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 59 deletions.
47 changes: 47 additions & 0 deletions vulnerabilities/importers/almalinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,53 @@ def advisory_data(self) -> Iterable[AdvisoryData]:


def parse_advisory_data(raw_data, advisory_url) -> Optional[AdvisoryData]:
"""
Parse Alma Linux advisory data and convert it into an AdvisoryData object.
Args:
raw_data (dict): A dictionary containing raw advisory information.
advisory_url (str): The URL to the advisory.
Returns:
AdvisoryData: An instance of AdvisoryData with processed information, or
None if the data cannot be parsed correctly.
Example:
>>> raw_data = {
... "id": "ALBA-2020:4512",
... "summary": "libteam bug fix and enhancement update",
... "details": "For detailed information on changes in this release, see the AlmaLinux Release Notes linked from the References section.",
... "published": "2020-11-03T12:11:24Z",
... "affected": [
... {
... "package": {
... "ecosystem": "AlmaLinux:8",
... "name": "libteam"
... },
... "ranges": [
... {
... "type": "ECOSYSTEM",
... "events": [
... {"introduced": "0"},
... {"fixed": "1.31-2.el8"}
... ]
... }
... ]
... }
... ],
... "references": [
... {
... "url": "https://errata.almalinux.org/8/ALBA-2020-4512.html",
... "type": "ADVISORY"
... }
... ]
... }
>>> advisory_url = "https://github.com/AlmaLinux/osv-database/blob/master/advisories/almalinux/example_advisory.json"
>>> advisory = parse_advisory_data(raw_data, advisory_url).to_dict()
>>> print(advisory)
{'aliases': ['ALBA-2020:4512'], 'summary': 'libteam bug fix and enhancement update\\nFor detailed information on changes in this release, see the AlmaLinux Release Notes linked from the References section.', 'affected_packages': [{'package': {'type': 'rpm', 'namespace': 'almalinux', 'name': 'libteam', 'version': '', 'qualifiers': '', 'subpath': ''}, 'affected_version_range': None, 'fixed_version': '1.31-2.el8'}], 'references': [{'reference_id': '', 'reference_type': '', 'url': 'https://errata.almalinux.org/8/ALBA-2020-4512.html', 'severities': []}], 'date_published': '2020-11-03T12:11:24+00:00', 'weaknesses': [], 'url': 'https://github.com/AlmaLinux/osv-database/blob/master/advisories/almalinux/example_advisory.json'}
"""

raw_id = raw_data.get("id") or ""
summary = raw_data.get("summary") or ""
details = raw_data.get("details") or ""
Expand Down
4 changes: 1 addition & 3 deletions vulnerabilities/tests/test_almalinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import os
from unittest import TestCase

from vulnerabilities.importers.almalinux import get_affected_purl
from vulnerabilities.importers.almalinux import get_fixed_versions
from vulnerabilities.importers.almalinux import parse_advisory_data
from vulnerabilities.tests import util_tests

Expand Down Expand Up @@ -44,7 +42,7 @@ def test_almalinux_importer2(self):
result = imported_data.to_dict()
util_tests.check_results_against_json(result, expected_file)

def test_github_osv_importer3(self):
def test_almalinux_importer3(self):
with open(os.path.join(TEST_DATA, "almalinux_test_3.json")) as f:
mock_response = json.load(f)
expected_file = os.path.join(TEST_DATA, "almalinux_expected_3.json")
Expand Down
38 changes: 24 additions & 14 deletions vulnerabilities/tests/test_data/almalinux/almalinux_expected_1.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
{
"aliases": ["ALBA-2019:3336"],
"summary": "nss-altfiles bug fix and enhancement update\nFor detailed information on changes in this release, see the AlmaLinux Release Notes linked from the References section.",
"aliases": [
"ALBA-2019:3336"
],
"summary": "nss-altfiles bug fix and enhancement update\nFor detailed information on changes in this release, see the AlmaLinux Release Notes linked from the References section.",
"affected_packages": [
{
"package": {"type": "rpm", "namespace": "almalinux", "name": "nss-altfiles", "version": "", "qualifiers": "", "subpath": ""},
"affected_version_range": null,
"fixed_version": "2.18.1-12.el8"
}
],
"package": {
"type": "rpm",
"namespace": "almalinux",
"name": "nss-altfiles",
"version": "",
"qualifiers": "",
"subpath": ""
},
"affected_version_range": null,
"fixed_version": "2.18.1-12.el8"
}
],
"references": [
{
"reference_id": "",
"url": "https://errata.almalinux.org/8/ALBA-2019-3336.html",
"severities": []
}
],
"date_published": "2019-11-05T17:32:18+00:00",
"weaknesses": [],
"reference_id": "",
"reference_type": "",
"url": "https://errata.almalinux.org/8/ALBA-2019-3336.html",
"severities": []
}
],
"date_published": "2019-11-05T17:32:18+00:00",
"weaknesses": [],
"url": "https://github.com/AlmaLinux/osv-database/blob/master/advisories/almalinux8/almalinux_test_1.json"
}
27 changes: 17 additions & 10 deletions vulnerabilities/tests/test_data/almalinux/almalinux_expected_2.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
{
"aliases": ["ALEA-2019:3314"],
"summary": "python3-azure-sdk bug fix and enhancement update\nFor detailed information on changes in this release, see the AlmaLinux Release Notes linked from the References section.",
"aliases": [
"ALEA-2019:3314"
],
"summary": "python3-azure-sdk bug fix and enhancement update\nFor detailed information on changes in this release, see the AlmaLinux Release Notes linked from the References section.",
"affected_packages": [
{
"package": {
"type": "rpm", "namespace": "almalinux", "name": "python3-azure-sdk", "version": "", "qualifiers": "", "subpath": ""
},
"affected_version_range": null,
"fixed_version": "4.0.0-9.el8"
"type": "rpm",
"namespace": "almalinux",
"name": "python3-azure-sdk",
"version": "",
"qualifiers": "",
"subpath": ""
},
"affected_version_range": null,
"fixed_version": "4.0.0-9.el8"
}
],
"references": [],
"date_published": "2019-11-05T17:29:24+00:00",
"weaknesses": [],
],
"references": [],
"date_published": "2019-11-05T17:29:24+00:00",
"weaknesses": [],
"url": "https://github.com/AlmaLinux/osv-database/blob/master/advisories/almalinux8/almalinux_test_2.json"
}
159 changes: 127 additions & 32 deletions vulnerabilities/tests/test_data/almalinux/almalinux_expected_3.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,145 @@
{
"aliases": ["ALSA-2022:8221"],
"summary": "Moderate: xorg-x11-server security and bug fix update\nX.Org is an open-source implementation of the X Window System. It provides the basic low-level functionality that full-fledged graphical user interfaces are designed upon.\n\nSecurity Fix(es)n\n* xorg-x11-server: X.Org Server ProcXkbSetGeometry out-of-bounds access (CVE-2022-2319)\n* xorg-x11-server: out-of-bounds access in ProcXkbSetDeviceInfo request handler of the Xkb extension VE-2022-2320)\n\nFor more details about the security issue(s), including the impact, a CVSS score, acknowledgments, and other related information, refer to the CVE page(s) listed in the References section.\nAdditional Changes:\n\nFor detailed information on changes in this release, see the AlmaLinux Release Notes linked from the References section.",
"aliases": [
"ALSA-2022:8221"
],
"summary": "Moderate: xorg-x11-server security and bug fix update\nX.Org is an open-source implementation of the X Window System. It provides the basic low-level functionality that full-fledged graphical user interfaces are designed upon.\n\nSecurity Fix(es)n\n* xorg-x11-server: X.Org Server ProcXkbSetGeometry out-of-bounds access (CVE-2022-2319)\n* xorg-x11-server: out-of-bounds access in ProcXkbSetDeviceInfo request handler of the Xkb extension VE-2022-2320)\n\nFor more details about the security issue(s), including the impact, a CVSS score, acknowledgments, and other related information, refer to the CVE page(s) listed in the References section.\nAdditional Changes:\n\nFor detailed information on changes in this release, see the AlmaLinux Release Notes linked from the References section.",
"affected_packages": [
{"package": {"type": "rpm", "namespace": "almalinux", "name": "xorg-x11-server-Xdmx", "version": "", "qualifiers": "", "subpath": ""}, "affected_version_range": null, "fixed_version": "1.20.11-11.el9"},
{"package": {"type": "rpm", "namespace": "almalinux", "name": "xorg-x11-server-Xephyr", "version": "", "qualifiers": "", "subpath": ""}, "affected_version_range": null, "fixed_version": "1.20.11-11.el9"},
{"package": {"type": "rpm", "namespace": "almalinux", "name": "xorg-x11-server-Xnest", "version": "", "qualifiers": "", "subpath": ""}, "affected_version_range": null, "fixed_version": "1.20.11-11.el9"},
{"package": {"type": "rpm", "namespace": "almalinux", "name": "xorg-x11-server-Xorg", "version": "", "qualifiers": "", "subpath": ""}, "affected_version_range": null, "fixed_version": "1.20.11-11.el9"},
{"package": {"type": "rpm", "namespace": "almalinux", "name": "xorg-x11-server-Xvfb", "version": "", "qualifiers": "", "subpath": ""}, "affected_version_range": null, "fixed_version": "1.20.11-11.el9"},
{"package": {"type": "rpm", "namespace": "almalinux", "name": "xorg-x11-server-common", "version": "", "qualifiers": "", "subpath": ""}, "affected_version_range": null, "fixed_version": "1.20.11-11.el9"},
{"package": {"type": "rpm", "namespace": "almalinux", "name": "xorg-x11-server-devel", "version": "", "qualifiers": "", "subpath": ""}, "affected_version_range": null, "fixed_version": "1.20.11-11.el9"},
{"package": {"type": "rpm", "namespace": "almalinux", "name": "xorg-x11-server-source", "version": "", "qualifiers": "", "subpath": ""}, "affected_version_range": null, "fixed_version": "1.20.11-11.el9"}

],
{
"package": {
"type": "rpm",
"namespace": "almalinux",
"name": "xorg-x11-server-Xdmx",
"version": "",
"qualifiers": "",
"subpath": ""
},
"affected_version_range": null,
"fixed_version": "1.20.11-11.el9"
},
{
"package": {
"type": "rpm",
"namespace": "almalinux",
"name": "xorg-x11-server-Xephyr",
"version": "",
"qualifiers": "",
"subpath": ""
},
"affected_version_range": null,
"fixed_version": "1.20.11-11.el9"
},
{
"package": {
"type": "rpm",
"namespace": "almalinux",
"name": "xorg-x11-server-Xnest",
"version": "",
"qualifiers": "",
"subpath": ""
},
"affected_version_range": null,
"fixed_version": "1.20.11-11.el9"
},
{
"package": {
"type": "rpm",
"namespace": "almalinux",
"name": "xorg-x11-server-Xorg",
"version": "",
"qualifiers": "",
"subpath": ""
},
"affected_version_range": null,
"fixed_version": "1.20.11-11.el9"
},
{
"package": {
"type": "rpm",
"namespace": "almalinux",
"name": "xorg-x11-server-Xvfb",
"version": "",
"qualifiers": "",
"subpath": ""
},
"affected_version_range": null,
"fixed_version": "1.20.11-11.el9"
},
{
"package": {
"type": "rpm",
"namespace": "almalinux",
"name": "xorg-x11-server-common",
"version": "",
"qualifiers": "",
"subpath": ""
},
"affected_version_range": null,
"fixed_version": "1.20.11-11.el9"
},
{
"package": {
"type": "rpm",
"namespace": "almalinux",
"name": "xorg-x11-server-devel",
"version": "",
"qualifiers": "",
"subpath": ""
},
"affected_version_range": null,
"fixed_version": "1.20.11-11.el9"
},
{
"package": {
"type": "rpm",
"namespace": "almalinux",
"name": "xorg-x11-server-source",
"version": "",
"qualifiers": "",
"subpath": ""
},
"affected_version_range": null,
"fixed_version": "1.20.11-11.el9"
}
],
"references": [
{
"reference_id": "",
"url": "https://access.redhat.com/errata/RHSA-2022:8221",
"reference_id": "",
"reference_type": "",
"url": "https://access.redhat.com/errata/RHSA-2022:8221",
"severities": []
},
},
{
"reference_id": "",
"url": "https://access.redhat.com/security/cve/CVE-2022-2319",
"reference_id": "",
"reference_type": "",
"url": "https://access.redhat.com/security/cve/CVE-2022-2319",
"severities": []
},
},
{
"reference_id": "",
"url": "https://access.redhat.com/security/cve/CVE-2022-2320",
"reference_id": "",
"reference_type": "",
"url": "https://access.redhat.com/security/cve/CVE-2022-2320",
"severities": []
},
},
{
"reference_id": "",
"url": "https://bugzilla.redhat.com/2106671",
"reference_id": "",
"reference_type": "",
"url": "https://bugzilla.redhat.com/2106671",
"severities": []
},
},
{
"reference_id": "",
"url": "https://bugzilla.redhat.com/2106683",
"reference_id": "",
"reference_type": "",
"url": "https://bugzilla.redhat.com/2106683",
"severities": []
},
},
{
"reference_id": "",
"url": "https://errata.almalinux.org/9/ALSA-2022-8221.html",
"reference_id": "",
"reference_type": "",
"url": "https://errata.almalinux.org/9/ALSA-2022-8221.html",
"severities": []
}
],
"date_published": "2022-11-15T00:00:00+00:00",
"weaknesses": [],
],
"date_published": "2022-11-15T00:00:00+00:00",
"weaknesses": [],
"url": "https://github.com/AlmaLinux/osv-database/blob/master/advisories/almalinux8/almalinux_test_3.json"
}

0 comments on commit 088279c

Please sign in to comment.