Skip to content

Commit

Permalink
cli: change header order for list command
Browse files Browse the repository at this point in the history
For the pro vulnerability list command, we are now
putting the headers at the end of the command, to allow
users to better identify the number and criticality of
the affected CVEs in the system without the need to
scroll up on the command output
  • Loading branch information
lucasmoura committed Sep 27, 2024
1 parent 2ed6aaa commit ead4570
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 37 deletions.
56 changes: 27 additions & 29 deletions features/cli/vulnerability_list.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ Feature: CLI vulnerability list command
And I remove colors from output
Then I will see the following on stdout:
"""
Vulnerabilities with applied fixes:
13 applied via Ubuntu Security (2 high, 6 medium, 5 low)
Vulnerabilities with fixes available:
10 vulnerabilities found (3 high, 4 medium, 2 low, 1 negligible)
Common vulnerabilities and exposures (CVE):
VULNERABILITY PRIORITY FIX AVAILABLE FROM AFFECTED INSTALLED PACKAGES
CVE-2021-44730 high esm-infra snapd
Expand All @@ -42,20 +36,17 @@ Feature: CLI vulnerability list command
CVE-2021-46848 low esm-infra libtasn1-6
CVE-2023-24626 low esm-infra screen
CVE-2018-1000654 negligible esm-infra libtasn1-6
"""
When I run `pro vulnerability list --all --data-file=/tmp/security_issues_xenial --manifest-file=/tmp/manifest` as non-root
And I remove colors from output
Then I will see the following on stdout:
"""
Vulnerabilities with applied fixes:
13 applied via Ubuntu Security (2 high, 6 medium, 5 low)
Vulnerabilities with fixes available:
10 vulnerabilities found (3 high, 4 medium, 2 low, 1 negligible)
Vulnerabilities with no fixes available:
10 unfixable vulnerabilities found (8 medium, 2 low)
"""
When I run `pro vulnerability list --all --data-file=/tmp/security_issues_xenial --manifest-file=/tmp/manifest` as non-root
And I remove colors from output
Then I will see the following on stdout:
"""
Common vulnerabilities and exposures (CVE):
VULNERABILITY PRIORITY FIX AVAILABLE FROM AFFECTED INSTALLED PACKAGES
CVE-2021-44730 high esm-infra snapd
Expand All @@ -69,7 +60,6 @@ Feature: CLI vulnerability list command
CVE-2021-4120 medium esm-infra snapd
CVE-2022-28948 medium no-fix snapd
CVE-2023-1523 medium esm-infra snapd
CVE-2023-48795 medium no-fix snapd
CVE-2024-1724 medium no-fix snapd
CVE-2024-29068 medium no-fix snapd
CVE-2024-29069 medium no-fix snapd
Expand All @@ -78,47 +68,55 @@ Feature: CLI vulnerability list command
CVE-2023-24626 low esm-infra screen
CVE-2024-5138 low no-fix snapd
CVE-2018-1000654 negligible esm-infra libtasn1-6
Vulnerabilities with applied fixes:
13 applied via Ubuntu Security (2 high, 6 medium, 5 low)
Vulnerabilities with fixes available:
10 vulnerabilities found (3 high, 4 medium, 2 low, 1 negligible)
Vulnerabilities with no fixes available:
9 unfixable vulnerabilities found (7 medium, 2 low)
"""
When I run `pro vulnerability list --unfixable --data-file=/tmp/security_issues_xenial --manifest-file=/tmp/manifest` as non-root
And I remove colors from output
Then I will see the following on stdout:
"""
Vulnerabilities with applied fixes:
13 applied via Ubuntu Security (2 high, 6 medium, 5 low)
Vulnerabilities with no fixes available:
10 unfixable vulnerabilities found (8 medium, 2 low)
Common vulnerabilities and exposures (CVE):
VULNERABILITY PRIORITY FIX AVAILABLE FROM AFFECTED INSTALLED PACKAGES
CVE-2019-11840 medium no-fix snapd
CVE-2021-24031 medium no-fix libzstd1
CVE-2021-24032 medium no-fix libzstd1
CVE-2022-28948 medium no-fix snapd
CVE-2023-48795 medium no-fix snapd
CVE-2024-1724 medium no-fix snapd
CVE-2024-29068 medium no-fix snapd
CVE-2024-29069 medium no-fix snapd
CVE-2017-3204 low no-fix snapd
CVE-2024-5138 low no-fix snapd
Vulnerabilities with applied fixes:
13 applied via Ubuntu Security (2 high, 6 medium, 5 low)
Vulnerabilities with no fixes available:
9 unfixable vulnerabilities found (7 medium, 2 low)
"""
When I run `pro vulnerability list --usns --data-file=/tmp/security_issues_xenial --manifest-file=/tmp/manifest` as non-root
And I remove colors from output
Then I will see the following on stdout:
"""
Vulnerabilities with applied fixes:
1 applied via Ubuntu Security
Vulnerabilities with fixes available:
5 vulnerabilities found
Ubuntu Security Notices (USN):
VULNERABILITY FIX AVAILABLE FROM AFFECTED INSTALLED PACKAGES
USN-5292-3 esm-infra snapd
USN-5352-1 esm-infra libtasn1-6
USN-5593-1 esm-infra libzstd1
USN-5707-1 esm-infra libtasn1-6
USN-5720-1 esm-infra libzstd1
Vulnerabilities with applied fixes:
1 applied via Ubuntu Security
Vulnerabilities with fixes available:
5 vulnerabilities found
"""
When I create the file `/tmp/manifest` with the following:
"""
Expand Down
20 changes: 12 additions & 8 deletions uaclient/cli/vulnerability/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,22 +327,24 @@ def _list_cves(
)

if cve_vulnerabilities_result.cves:
print(messages.CLI_VULNERABILITY_LIST_CVE_HEADER)
print(_create_cve_table(cve_vulnerabilities_result.cves))
print(
_create_list_header(
"\n"
+ _create_list_header(
vulnerabilities=cve_vulnerabilities_result.cves,
applied_fixes_count=applied_fixes_count,
show_usns=False,
show_all=show_all,
show_unfixable=show_unfixable,
)
)
print(messages.CLI_VULNERABILITY_LIST_CVE_HEADER)
print(_create_cve_table(cve_vulnerabilities_result.cves))
else:
print(_create_already_fixed_cves_count(applied_fixes_count))
print(
messages.CLI_VULNERABILITY_LIST_NOT_AFFECTED.format(issue="CVEs")
+ "\n"
)
print(_create_already_fixed_cves_count(applied_fixes_count))


def _list_usns(
Expand All @@ -365,22 +367,24 @@ def _list_usns(
)

if usn_vulnerabilities_result.usns:
print(messages.CLI_VULNERABILITY_LIST_USN_HEADER)
print(_create_usn_table(usn_vulnerabilities_result.usns))
print(
_create_list_header(
"\n"
+ _create_list_header(
vulnerabilities=usn_vulnerabilities_result.usns,
applied_fixes_count=applied_fixes_count,
show_usns=True,
show_all=show_all,
show_unfixable=show_unfixable,
)
)
print(messages.CLI_VULNERABILITY_LIST_USN_HEADER)
print(_create_usn_table(usn_vulnerabilities_result.usns))
else:
print(_create_already_fixed_usns_count(applied_fixes_count))
print(
messages.CLI_VULNERABILITY_LIST_NOT_AFFECTED.format(issue="USNs")
+ "\n"
)
print(_create_already_fixed_usns_count(applied_fixes_count))


@vuln_util.assert_data_cache_updated("pro vulnerability list")
Expand Down

0 comments on commit ead4570

Please sign in to comment.