Skip to content

Commit

Permalink
Add sonarqube formatter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dmuhs committed Jan 13, 2020
1 parent b576d7c commit 9024bec
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
ISSUES_RESPONSE = get_test_case("testdata/detected-issues-response.json", DetectedIssuesResponse)
ISSUES_SIMPLE = get_test_case("testdata/detected-issues-simple.txt", raw=True)
ISSUES_TABLE = get_test_case("testdata/detected-issues-table.txt", raw=True)
ISSUES_SONAR = get_test_case("testdata/detected-issues-sonar.json")


def test_report_tabular():
Expand Down Expand Up @@ -43,6 +44,31 @@ def test_report_tabular_filter():
assert "/home/spoons/diligence/mythx-qa/land/contracts/estate/EstateStorage.sol" not in result.output


def test_report_sonar():
runner = CliRunner()
with mock_context():
result = runner.invoke(cli, ["--format", "sonar", "analysis", "report", "ab9092f7-54d0-480f-9b63-1bb1508280e2"])
assert result.exit_code == 0
assert json.loads(result.output) == ISSUES_SONAR


def test_report_sonar_blacklist():
runner = CliRunner()
with mock_context():
result = runner.invoke(cli, ["--format", "sonar", "analysis", "report", "--swc-blacklist",
"SWC-110", "ab9092f7-54d0-480f-9b63-1bb1508280e2"])
assert result.exit_code == 0
assert all(x["forRule"] != "SWC-110" for x in json.loads(result.output))


def test_report_sonar_filter():
runner = CliRunner()
with mock_context():
result = runner.invoke(cli, ["--format", "sonar", "analysis", "report", "--min-severity", "high", "ab9092f7-54d0-480f-9b63-1bb1508280e2"])
assert result.exit_code == 0
assert all(x["forRule"] != "SWC-110" for x in json.loads(result.output))


def test_report_json():
runner = CliRunner()
with mock_context():
Expand Down
18 changes: 18 additions & 0 deletions tests/testdata/detected-issues-sonar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"linterName": "mythx",
"forRule": "SWC-110",
"ruleType": "LOW",
"remediationEffortMinutes": 0,
"severity": "LOW",
"message": "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."
},
{
"linterName": "mythx",
"forRule": "",
"ruleType": "LOW",
"remediationEffortMinutes": 0,
"severity": "LOW",
"message": "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"
}
]

0 comments on commit 9024bec

Please sign in to comment.