Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion plugins/semgrep_scanner/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@
"system_packages": []
},
"docker_image": "returntocorp/semgrep:latest",
"checksum": "8e59254f5ad937c0a5a2af47367cddf07e07b8a528d13ff303360d6e478a51d8"
"checksum": "2639e4aa47d346d9ab7caa64d6fe447203f8a6be5a0a354055eebebe9e674ae6"
}
3 changes: 2 additions & 1 deletion plugins/semgrep_scanner/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def parse(output: str) -> Dict[str, Any]:
}
)
except Exception:
pass
# If parsing fails, return empty findings
return {"findings": [], "count": 0}

return {"findings": findings, "count": len(findings)}
43 changes: 43 additions & 0 deletions testing/test_semgrep_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import pytest
import json
import sys
import os

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))

from plugins.semgrep_scanner.parser import parse

# Test 1: Valid JSON input
def test_valid_json():
valid_input = json.dumps({
"results": [
{
"check_id": "python.security.test-rule",
"path": "app.py",
"extra": {
"message": "Test security issue",
"severity": "WARNING",
"lines": "eval(user_input)"
},
"start": {"line": 10}
}
]
})
result = parse(valid_input)
assert result["count"] == 1
assert result["findings"][0]["severity"] == "medium"
assert result["findings"][0]["category"] == "Code Security"

# Test 2: Invalid JSON input
def test_invalid_json():
invalid_input = "this is not json {{{broken"
result = parse(invalid_input)
assert result["count"] == 0
assert result["findings"] == []

# Test 3: Mixed stdout (JSON mixed with other text)
def test_mixed_stdout():
mixed_input = "Some random text\n{invalid json here}\nmore text"
result = parse(mixed_input)
assert result["count"] == 0
assert result["findings"] == []
Loading