Skip to content

Commit

Permalink
Merge branch 'feature/dashboard-links'
Browse files Browse the repository at this point in the history
  • Loading branch information
dmuhs committed Oct 30, 2019
2 parents 4db189a + 2193c47 commit 2b3a981
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
9 changes: 4 additions & 5 deletions mythx_cli/formatter/simple_stdout.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
)

from .base import BaseFormatter
from .util import get_source_location_by_offset
from .util import get_source_location_by_offset, generate_dashboard_link


class SimpleFormatter(BaseFormatter):
Expand Down Expand Up @@ -50,12 +50,11 @@ def format_detected_issues(
# TODO: Sort by file
for report in resp.issue_reports:
for issue in report.issues:
res.append("UUID: {}".format(ctx.obj["uuid"]))
res.append(generate_dashboard_link(ctx.obj["uuid"]))
res.append(
"Title: {} ({})".format(issue.swc_title or "-", issue.severity)
)
res.append("Description: {}".format(issue.description_long))
res.append("")
res.append("Description: {}".format(issue.description_long.strip()))

for loc in issue.locations:
comp = loc.source_map.components[0]
Expand All @@ -72,7 +71,7 @@ def format_detected_issues(
)
snippet = inp.sources[filename]["source"].split("\n")[line - 1]
res.append("{}:{}".format(filename, line))
res.append(snippet)
res.append("\t" + snippet.strip())

res.append("")

Expand Down
10 changes: 6 additions & 4 deletions mythx_cli/formatter/tabular.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""This module contains a tabular data formatter class printing a subset of the response data."""

from collections import defaultdict

import click
from mythx_models.response import (
AnalysisInputResponse,
AnalysisListResponse,
Expand All @@ -12,7 +12,7 @@
from tabulate import tabulate

from .base import BaseFormatter
from .util import get_source_location_by_offset
from .util import get_source_location_by_offset, generate_dashboard_link


class TabularFormatter(BaseFormatter):
Expand Down Expand Up @@ -68,15 +68,17 @@ def format_detected_issues(
)
)

ctx = click.get_current_context()
for filename, data in file_to_issue.items():
res.append("Report for {}".format(filename))
res.append(
res.extend((
generate_dashboard_link(ctx.obj["uuid"]),
tabulate(
data,
tablefmt="fancy_grid",
headers=("Line", "SWC Title", "Severity", "Short Description"),
)
)
))

return "\n".join(res)

Expand Down
7 changes: 7 additions & 0 deletions mythx_cli/formatter/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ def get_source_location_by_offset(source, offset):
"""

return source.encode("utf-8")[0:offset].count("\n".encode("utf-8")) + 1


def generate_dashboard_link(uuid: str, staging=False):
return "https://dashboard.{}mythx.io/#/console/analyses/{}".format(
"staging." if staging else "",
uuid
)
9 changes: 4 additions & 5 deletions tests/testdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3085,23 +3085,22 @@
"analysisMode": "quick",
}
)
ISSUES_RESPONSE_SIMPLE = """UUID: ab9092f7-54d0-480f-9b63-1bb1508280e2
ISSUES_RESPONSE_SIMPLE = """https://dashboard.mythx.io/#/console/analyses/ab9092f7-54d0-480f-9b63-1bb1508280e2
Title: Assert Violation (Low)
Description: It is possible to trigger an exception (opcode 0xfe). Exceptions can be caused by type errors, division by zero, out-of-bounds array access, or assert violations. Note that explicit `assert()` should only be used to check invariants. Use `require()` for regular input checking.
/home/spoons/diligence/mythx-qa/land/contracts/estate/EstateStorage.sol:24
mapping(uint256 => uint256[]) public estateLandIds;
\tmapping(uint256 => uint256[]) public estateLandIds;
UUID: ab9092f7-54d0-480f-9b63-1bb1508280e2
https://dashboard.mythx.io/#/console/analyses/ab9092f7-54d0-480f-9b63-1bb1508280e2
Title: - (Low)
Description: Warning: Free mode only detects certain types of smart contract vulnerabilities. Your contract may still be unsafe. Upgrade to MythX Pro to unlock the ability to test for even more vulnerabilities, perform deeper security analysis, and more. https://mythx.io/plans
"""

ISSUES_RESPONSE_TABLE = """Warning: Free mode only detects certain types of smart contract vulnerabilities. Your contract may still be unsafe. Upgrade to MythX Pro to unlock the ability to test for even more vulnerabilities, perform deeper security analysis, and more. https://mythx.io/plans
Report for /home/spoons/diligence/mythx-qa/land/contracts/estate/EstateStorage.sol
https://dashboard.mythx.io/#/console/analyses/ab9092f7-54d0-480f-9b63-1bb1508280e2
╒════════╤══════════════════╤════════════╤══════════════════════════════════════════╕
│ Line │ SWC Title │ Severity │ Short Description │
╞════════╪══════════════════╪════════════╪══════════════════════════════════════════╡
Expand Down

0 comments on commit 2b3a981

Please sign in to comment.