Skip to content

Commit

Permalink
cli: fix url in vulnerability show
Browse files Browse the repository at this point in the history
Fix the vulnerability URL for the vulnerability show
command, as it was not redirecting to the correct
vulnerability page
  • Loading branch information
lucasmoura committed Oct 8, 2024
1 parent b004a4b commit 8c6fff5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
10 changes: 5 additions & 5 deletions features/cli/vulnerability_show.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Feature: CLI vulnerability show command
Then stdout matches regexp:
"""
CVE-2024-7542
Public URL: https://ubuntu.com/CVE-2024-7542
Public URL: https://ubuntu.com/security/CVE-2024-7542
Ubuntu vulnerability data published at: .*
APT package information updated at: .*
Expand All @@ -26,7 +26,7 @@ Feature: CLI vulnerability show command
Then stdout matches regexp:
"""
CVE-2022-2286
Public URL: https://ubuntu.com/CVE-2022-2286
Public URL: https://ubuntu.com/security/CVE-2022-2286
Published at: 2022-07-02 19:15:00
Ubuntu vulnerability data published at: .*
APT package information updated at: .*
Expand All @@ -53,7 +53,7 @@ Feature: CLI vulnerability show command
Then stdout matches regexp:
"""
CVE-2024-8088
Public URL: https://ubuntu.com/CVE-2024-8088
Public URL: https://ubuntu.com/security/CVE-2024-8088
Published at: 2024-08-22 19:15:00
Ubuntu vulnerability data published at: .*
APT package information updated at: .*
Expand Down Expand Up @@ -90,7 +90,7 @@ Feature: CLI vulnerability show command
Then stdout matches regexp:
"""
USN-4976-2
Public URL: https://ubuntu.com/USN-4976-2
Public URL: https://ubuntu.com/security/notices/USN-4976-2
Published at: 2022-09-07 15:22:39
Ubuntu vulnerability data published at: .*
APT package information updated at: .*
Expand Down Expand Up @@ -133,7 +133,7 @@ Feature: CLI vulnerability show command
\$ pro vulnerability show <vulnerability_issue> --update
.*USN-4976-2
Public URL: https://ubuntu.com/USN-4976-2
Public URL: https://ubuntu.com/security/notices/USN-4976-2
Published at: 2022-09-07 15:22:39
"""

Expand Down
40 changes: 32 additions & 8 deletions uaclient/cli/vulnerability/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@
from uaclient.cli.vulnerability import util as vuln_util


def _show_base_info_for_unaffected_issue(vulnerability_result, name: str):
def _show_base_info_for_unaffected_issue(
vulnerability_result, name: str, security_url: str
):
if not security_url.endswith("/"):
security_url += "/"

print(util.handle_unicode_characters("● {}".format(name)))
print(
messages.CLI_VULNERABILITY_SHOW_PUBLIC_URL.format(
urljoin(defaults.BASE_SECURITY_URL, name)
urljoin(security_url, name)
)
)
print(
Expand All @@ -41,13 +46,20 @@ def _show_base_info_for_unaffected_issue(vulnerability_result, name: str):
)


def _show_base_info(vulnerability_result, vulnerability_issue):
def _show_base_info(
vulnerability_result,
vulnerability_issue,
security_url,
):
if not security_url.endswith("/"):
security_url += "/"

print(
util.handle_unicode_characters("● {}".format(vulnerability_issue.name))
)
print(
messages.CLI_VULNERABILITY_SHOW_PUBLIC_URL.format(
urljoin(defaults.BASE_SECURITY_URL, vulnerability_issue.name)
urljoin(security_url, vulnerability_issue.name)
)
)
print(
Expand Down Expand Up @@ -197,15 +209,21 @@ def _show_cve_info(cfg: config.UAConfig, cve: str, data_file: Optional[str]):

if not cve_data:
_show_base_info_for_unaffected_issue(
cve_vulnerabilities_result, name=cve
cve_vulnerabilities_result,
name=cve,
security_url=defaults.BASE_SECURITY_URL,
)
print(
"\n"
+ messages.CLI_VULNERABILITY_SHOW_NOT_AFFECTED.format(issue=cve)
)
return

_show_base_info(cve_vulnerabilities_result, cve_data)
_show_base_info(
cve_vulnerabilities_result,
cve_data,
security_url=defaults.BASE_SECURITY_URL,
)
print(
messages.CLI_VULNERABILITY_SHOW_UBUNTU_PRIORITY.format(
cve_info.ubuntu_priority
Expand Down Expand Up @@ -250,15 +268,21 @@ def _show_usn_info(cfg: config.UAConfig, usn: str, data_file: Optional[str]):

if not usn_data:
_show_base_info_for_unaffected_issue(
usn_vulnerabilities_result, name=usn
usn_vulnerabilities_result,
name=usn,
security_url=defaults.BASE_SECURITY_URL + "/notices",
)
print(
"\n"
+ messages.CLI_VULNERABILITY_SHOW_NOT_AFFECTED.format(issue=usn)
)
return

_show_base_info(usn_vulnerabilities_result, usn_data)
_show_base_info(
usn_vulnerabilities_result,
usn_data,
security_url=defaults.BASE_SECURITY_URL + "/notices",
)
_show_description(usn_data)
_show_usn_affected_packages(usn_data)

Expand Down

0 comments on commit 8c6fff5

Please sign in to comment.