mirror of
https://github.com/Rarebuffalo/securelens-backend.git
synced 2026-06-19 07:00:30 +00:00
add unit tests for local pdf exporter
This commit is contained in:
48
tests/test_cli_pdf.py
Normal file
48
tests/test_cli_pdf.py
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import pytest
|
||||||
|
from pathlib import Path
|
||||||
|
from securelens.scanners import LocalScanResult, VulnerabilityFinding
|
||||||
|
from securelens.output.exporters import save_pdf
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def setup_db():
|
||||||
|
# Override the database autouse fixture because these tests do not touch the DB.
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_export_code_pdf_compiles(tmp_path):
|
||||||
|
# Setup mock result
|
||||||
|
findings = [
|
||||||
|
VulnerabilityFinding(
|
||||||
|
file_path="app.py",
|
||||||
|
severity="Critical",
|
||||||
|
issue="Hardcoded Secret Key",
|
||||||
|
explanation="Exposing secret key inside app.py.",
|
||||||
|
suggested_fix="Load key from environment",
|
||||||
|
line_number=5
|
||||||
|
),
|
||||||
|
VulnerabilityFinding(
|
||||||
|
file_path="db.py",
|
||||||
|
severity="High",
|
||||||
|
issue="Raw SQL Statement",
|
||||||
|
explanation="SQL injection inside db.py.",
|
||||||
|
suggested_fix="Use parameterized queries",
|
||||||
|
line_number=20
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
result = LocalScanResult(
|
||||||
|
target="/home/user/project",
|
||||||
|
total_files_found=10,
|
||||||
|
files_triaged=["app.py", "db.py"],
|
||||||
|
vulnerabilities=findings,
|
||||||
|
ai_summary="This is a dummy AI report summary describing security posture."
|
||||||
|
)
|
||||||
|
result.compute_score()
|
||||||
|
|
||||||
|
# Save to temp PDF file
|
||||||
|
out_file = tmp_path / "report.pdf"
|
||||||
|
|
||||||
|
from securelens.output.pdf import export_code_pdf
|
||||||
|
export_code_pdf(result, str(out_file))
|
||||||
|
|
||||||
|
assert out_file.exists()
|
||||||
|
assert out_file.stat().st_size > 1000 # should be non-empty PDF file
|
||||||
Reference in New Issue
Block a user