Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Syslifters/reptor
Browse files Browse the repository at this point in the history
  • Loading branch information
aronmolnar committed Jul 31, 2024
2 parents b6344ac + 6c94040 commit cf703ac
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
5 changes: 3 additions & 2 deletions reptor/plugins/projects/ExportFindings/ExportFindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def _findings_summary(self, format="csv", filename=None, upload=False):
except (cvss.exceptions.CVSS2MalformedError, IndexError):
cvss_metrics = None
if cvss_metrics:
finding_summary[f"{field}__score"] = (
finding_summary[f"{field}__score"] = str(
cvss_metrics.environmental_score
)
finding_summary[f"{field}__vector"] = vector
Expand All @@ -119,7 +119,8 @@ def _findings_summary(self, format="csv", filename=None, upload=False):
if format == "json":
output = json.dumps(findings, indent=2)
elif format == "toml":
output = tomli_w.dumps(findings) # type: ignore
# TOML does not support top-level lists. Wrap in a dictionary.
output = tomli_w.dumps({'findings': findings})
elif format == "yaml":
output = yaml.dump(findings)
elif format == "csv":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,43 @@
import subprocess

import pytest
import tomli
import yaml

from reptor.plugins.core.Conf.tests.conftest import projects_api, get_note
from reptor.plugins.core.Conf.tests.conftest import get_note, projects_api


@pytest.mark.integration
class TestIntegrationExportFinding(object):
def test_render_project(self, projects_api):
def test_export_findings(self, projects_api):
p = subprocess.Popen(
["reptor", "exportfindings", "--format", "json"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
out, _ = p.communicate()
assert p.returncode == 0
json.loads(out)
json_export = json.loads(out)

p = subprocess.Popen(
["reptor", "exportfindings", "--format", "toml"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
out, _ = p.communicate()
assert p.returncode == 0
toml_export = tomli.loads(out.decode()).get("findings") # TOML wraps in a dict

p = subprocess.Popen(
["reptor", "exportfindings", "--format", "yaml"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
out, _ = p.communicate()
assert p.returncode == 0
yaml_export = yaml.safe_load(out.decode())

assert json_export == toml_export == yaml_export

p = subprocess.Popen(
["reptor", "exportfindings", "--format", "json", "--upload"],
Expand Down

0 comments on commit cf703ac

Please sign in to comment.