Skip to content

Commit

Permalink
Trigger build
Browse files Browse the repository at this point in the history
  • Loading branch information
imsahil007 committed Sep 25, 2020
1 parent c12954a commit c178505
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 40 deletions.
4 changes: 3 additions & 1 deletion cve_bin_tool/async_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ def run_coroutine(coro):

async def aio_run_command(args):
process = await asyncio.create_subprocess_exec(
*args, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE,
*args,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
stdout, stderr = await process.communicate()
return stdout, stderr # binary encoded
Expand Down
11 changes: 9 additions & 2 deletions cve_bin_tool/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ def main(argv=None):
)

input_group.add_argument(
"-i", "--input-file", action="store", default="", help="provide input filename",
"-i",
"--input-file",
action="store",
default="",
help="provide input filename",
)
input_group.add_argument(
"-C", "--config", action="store", default="", help="provide config file"
Expand Down Expand Up @@ -144,7 +148,10 @@ def main(argv=None):
help="update schedule for NVD database (default: daily)",
)
parser.add_argument(
"-x", "--extract", action="store_true", help="autoextract compressed files",
"-x",
"--extract",
action="store_true",
help="autoextract compressed files",
)
parser.add_argument(
"--disable-version-check",
Expand Down
2 changes: 1 addition & 1 deletion cve_bin_tool/cve_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(
self.all_cve_data = defaultdict(CVEData)

def get_cves(self, product_info: ProductInfo, triage_data: TriageData):
""" Get CVEs against a specific version of a product.
"""Get CVEs against a specific version of a product.
Example:
nvd.get_cves('haxx', 'curl', '7.34.0')
Expand Down
7 changes: 5 additions & 2 deletions cve_bin_tool/cvedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CVEDB:
LOGGER = LOGGER.getChild("CVEDB")
NVDCVE_FILENAME_TEMPLATE = "nvdcve-1.1-{}.json.gz"
CURL_CVE_FILENAME_TEMPLATE = "curlcve-{}.json"
META_LINK = 'https://nvd.nist.gov'
META_LINK = "https://nvd.nist.gov"
META_REGEX = re.compile(r"\/feeds\/json\/.*-[0-9]*\.[0-9]*-[0-9]*\.meta")
RANGE_UNSET = ""

Expand Down Expand Up @@ -92,7 +92,10 @@ async def nist_scrape(self, session):
json_meta_links = self.META_REGEX.findall(page)
return dict(
await asyncio.gather(
*[self.getmeta(session, self.META_LINK+meta_url) for meta_url in json_meta_links]
*[
self.getmeta(session, self.META_LINK + meta_url)
for meta_url in json_meta_links
]
)
)

Expand Down
3 changes: 2 additions & 1 deletion cve_bin_tool/egg_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def update_egg():
)
for filename in os.listdir(
os.path.join(
os.path.abspath(os.path.dirname(__file__)), "checkers",
os.path.abspath(os.path.dirname(__file__)),
"checkers",
)
)
if filename.endswith(".py") and "__init__" not in filename
Expand Down
42 changes: 33 additions & 9 deletions cve_bin_tool/output_engine/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,17 @@ def output_html(

# Chart configuration for product_pie
product_pie.update_layout(
autosize=True, legend_orientation="h",
autosize=True,
legend_orientation="h",
)
product_pie.update_traces(
hoverinfo="label+percent",
textinfo="value",
textfont_size=14,
marker=dict(colors=["#d80032", "#1a936f"], line=dict(color="white", width=2),),
marker=dict(
colors=["#d80032", "#1a936f"],
line=dict(color="white", width=2),
),
)

# dash graph2: Product CVE's Graph
Expand All @@ -117,7 +121,9 @@ def output_html(
)

# Chart configuration for cve_bar
cve_bar.update_layout(yaxis_title="Number of CVE's",)
cve_bar.update_layout(
yaxis_title="Number of CVE's",
)

all_paths = defaultdict(list)

Expand All @@ -134,19 +140,34 @@ def output_html(
hid = f"{product_info.vendor}{product_info.product}{''.join(product_info.version.split('.'))}"

new_cves = render_cves(
hid, cve_row, "NEW", cve_by_remark[Remarks.NewFound],
hid,
cve_row,
"NEW",
cve_by_remark[Remarks.NewFound],
)
mitigated_cves = render_cves(
hid, cve_row, "MITIGATED", cve_by_remark[Remarks.Mitigated],
hid,
cve_row,
"MITIGATED",
cve_by_remark[Remarks.Mitigated],
)
confirmed_cves = render_cves(
hid, cve_row, "CONFIRMED", cve_by_remark[Remarks.Confirmed],
hid,
cve_row,
"CONFIRMED",
cve_by_remark[Remarks.Confirmed],
)
unexplored_cves = render_cves(
hid, cve_row, "UNEXPLORED", cve_by_remark[Remarks.Unexplored],
hid,
cve_row,
"UNEXPLORED",
cve_by_remark[Remarks.Unexplored],
)
ignored_cves = render_cves(
hid, cve_row, "IGNORED", cve_by_remark[Remarks.Ignored],
hid,
cve_row,
"IGNORED",
cve_by_remark[Remarks.Ignored],
)

analysis_data = Counter(cve.severity for cve in cve_data["cves"])
Expand All @@ -173,7 +194,10 @@ def output_html(
hoverinfo="label+percent",
textinfo="value",
textfont_size=14,
marker=dict(colors=colors, line=dict(color="white", width=2),),
marker=dict(
colors=colors,
line=dict(color="white", width=2),
),
)
analysis_pie.update_layout(
autosize=True,
Expand Down
38 changes: 16 additions & 22 deletions test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,34 +187,28 @@ def test_update(self, caplog):
with caplog.at_level(logging.INFO):
main(["cve-bin-tool", "-u", "daily", test_path])
assert (
(
"cve_bin_tool.CVEDB",
logging.INFO,
"Using cached CVE data (<24h old). Use -u now to update immediately.",
)
in caplog.record_tuples
or (
"cve_bin_tool.CVEDB",
logging.INFO,
"Updating CVE data. This will take a few minutes.",
)
in caplog.record_tuples
)
"cve_bin_tool.CVEDB",
logging.INFO,
"Using cached CVE data (<24h old). Use -u now to update immediately.",
) in caplog.record_tuples or (
"cve_bin_tool.CVEDB",
logging.INFO,
"Updating CVE data. This will take a few minutes.",
) in caplog.record_tuples
caplog.clear()

with caplog.at_level(logging.INFO):
main(["cve-bin-tool", "-u", "now", test_path])
db_path = DISK_LOCATION_DEFAULT
assert (
("cve_bin_tool.CVEDB", logging.WARNING, f"Deleting cachedir {db_path}",)
in caplog.record_tuples
and (
"cve_bin_tool.CVEDB",
logging.INFO,
"Updating CVE data. This will take a few minutes.",
)
in caplog.record_tuples
)
"cve_bin_tool.CVEDB",
logging.WARNING,
f"Deleting cachedir {db_path}",
) in caplog.record_tuples and (
"cve_bin_tool.CVEDB",
logging.INFO,
"Updating CVE data. This will take a few minutes.",
) in caplog.record_tuples
caplog.clear()

with caplog.at_level(logging.INFO):
Expand Down
6 changes: 5 additions & 1 deletion test/test_data/icecast.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
mapping_test_data = [
{"product": "icecast", "version": "2.3.0", "version_strings": ["Icecast 2.3.0"],}
{
"product": "icecast",
"version": "2.3.0",
"version_strings": ["Icecast 2.3.0"],
}
]
package_test_data = [
{
Expand Down
3 changes: 2 additions & 1 deletion test/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def test_json_validation(self, year):
""" Validate latest nvd json file against their published schema """
# Open the latest nvd file on disk
with gzip.open(
os.path.join(DISK_LOCATION_DEFAULT, f"nvdcve-1.1-{year}.json.gz"), "rb",
os.path.join(DISK_LOCATION_DEFAULT, f"nvdcve-1.1-{year}.json.gz"),
"rb",
) as json_file:
nvd_json = json.loads(json_file.read())
LOGGER.info(f"Loaded json for year {year}: nvdcve-1.1-{year}.json.gz")
Expand Down

0 comments on commit c178505

Please sign in to comment.