Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResultSet or behavior needs update for storing tools #944

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/codemodder/codeql.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ def from_sarif(cls, sarif_file: str | Path, truncate_rule_id: bool = False) -> S
sarif_result, sarif_run, truncate_rule_id
)
result_set.add_result(codeql_result)
result_set.store_tool_data(sarif_run["tool"])
return result_set
3 changes: 3 additions & 0 deletions src/codemodder/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ def __or__(self, other):
result.results_for_rule = list_dict_or(
self.results_for_rule, other.results_for_rule
)
for tool in self.tools or other.tools:
result.store_tool_data(tool)

return result

def __ior__(self, other):
Expand Down
2 changes: 1 addition & 1 deletion src/codemodder/semgrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def from_sarif(cls, sarif_file: str | Path, truncate_rule_id: bool = False) -> S
result, sarif_run, truncate_rule_id
)
result_set.add_result(sarif_result)

result_set.store_tool_data(sarif_run["tool"])
return result_set


Expand Down
2 changes: 2 additions & 0 deletions tests/test_codeql.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def test_from_file(codeql_result_set: Path):
result_set = process_codeql_findings(tuple([str(codeql_result_set)]))
assert len(result_set["py/path-injection"][Path("Path Traversal/py_ctf.py")]) == 1
assert len(result_set["py/path-injection"]) == 2
assert result_set.tools
assert result_set.tools[0]["driver"]


def test_from_duplicate_files(codeql_result_set: Path):
Expand Down
7 changes: 7 additions & 0 deletions tests/test_sarif_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest

from codemodder.codemods.semgrep import process_semgrep_findings
from codemodder.sarifs import detect_sarif_tools
from codemodder.semgrep import SemgrepResult, SemgrepResultSet

Expand Down Expand Up @@ -149,3 +150,9 @@ def test_two_sarifs_different_tools(self):
assert "semgrep" in results
assert len(results["codeql"]) == 1
assert len(results["semgrep"]) == 1

def test_stores_tools(self):
sarif_file = Path("tests") / "samples" / "semgrep.sarif"
result_set = process_semgrep_findings(tuple([str(sarif_file)]))
assert result_set.tools
assert result_set.tools[0]["driver"]["rules"]
Loading