Skip to content

Commit

Permalink
Reserved but not owned CVE IDs do not display updatedDate
Browse files Browse the repository at this point in the history
  • Loading branch information
mprpic committed Jun 6, 2023
1 parent b06265f commit e9eb7a6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cvelib/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ def print_cve_id(cve: dict) -> None:
else:
click.echo(f"└─ Reserved on:\t{human_ts(cve['reserved'])}")
else:
click.echo(f"├─ Owning CNA:\t{cve['owning_cna']}")
click.echo(f"└─ Updated on:\t{human_ts(cve['dateUpdated'])}")
if "dateUpdated" in cve:
click.echo(f"├─ Owning CNA:\t{cve['owning_cna']}")
click.echo(f"└─ Updated on:\t{human_ts(cve['dateUpdated'])}")
else:
click.echo(f"└─ Owning CNA:\t{cve['owning_cna']}")


def print_cve_record(cve: dict) -> None:
Expand Down
40 changes: 40 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,46 @@ def test_cve_id_show(show_cve_record, show_cve_id):
assert not show_cve_record.called


@mock.patch("cvelib.cli.CveApi.show_cve_id")
@mock.patch("cvelib.cli.CveApi.show_cve_record")
def test_reserved_not_owned_cve_id(show_cve_record, show_cve_id):
show_cve_id.return_value = {
"cve_id": "CVE-2099-0000",
"cve_year": "2099",
"owning_cna": "[REDACTED]",
"state": "RESERVED",
}

runner = CliRunner()
result = runner.invoke(cli, DEFAULT_OPTS + ["show", "CVE-2099-0000"])
assert result.exit_code == 0, result.output
assert result.output == "CVE-2099-0000\n├─ State:\tRESERVED\n└─ Owning CNA:\t[REDACTED]\n"
assert not show_cve_record.called


@mock.patch("cvelib.cli.CveApi.show_cve_id")
@mock.patch("cvelib.cli.CveApi.show_cve_record")
def test_published_not_owned_cve_id(show_cve_record, show_cve_id):
show_cve_id.return_value = {
"cve_id": "CVE-2099-0000",
"cve_year": "2099",
"owning_cna": "acme",
"dateUpdated": "2000-02-08T17:22:07.669Z",
"state": "PUBLISHED",
}

runner = CliRunner()
result = runner.invoke(cli, DEFAULT_OPTS + ["show", "CVE-2099-0000"])
assert result.exit_code == 0, result.output
assert result.output == (
"CVE-2099-0000\n"
"├─ State:\tPUBLISHED\n"
"├─ Owning CNA:\tacme\n"
"└─ Updated on:\tTue Feb 8 17:22:07 2000 +0000\n"
)
assert not show_cve_record.called


@mock.patch("cvelib.cli.CveApi.show_cve_id")
@mock.patch("cvelib.cli.CveApi.show_cve_record")
def test_cve_show_full(show_cve_record, show_cve_id):
Expand Down

0 comments on commit e9eb7a6

Please sign in to comment.