forked from SocketDev/socket-python-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_output.py
More file actions
54 lines (47 loc) · 1.79 KB
/
test_output.py
File metadata and controls
54 lines (47 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import pytest
from socketsecurity.output import OutputHandler
from socketsecurity.core.classes import Diff, Issue
import json
class TestOutputHandler:
@pytest.fixture
def handler(self):
return OutputHandler(blocking_disabled=False)
def test_report_pass_with_blocking_issues(self, handler):
diff = Diff()
diff.new_alerts = [Issue(error=True)]
assert not handler.report_pass(diff)
def test_report_pass_with_blocking_disabled(self):
handler = OutputHandler(blocking_disabled=True)
diff = Diff()
diff.new_alerts = [Issue(error=True)]
assert handler.report_pass(diff)
def test_json_output_format(self, handler, capsys):
diff = Diff()
test_issue = Issue(
title="Test",
severity="high",
description="Test description",
error=True,
key="test-key",
type="test-type",
pkg_type="npm",
pkg_name="test-package",
pkg_version="1.0.0",
purl="pkg:npm/test-package@1.0.0"
)
diff.new_alerts = [test_issue]
handler.output_console_json(diff)
captured = capsys.readouterr()
# Parse the JSON output and verify structure
output = json.loads(captured.out)
assert output["issues"][0]["title"] == "Test"
assert output["issues"][0]["severity"] == "high"
assert output["issues"][0]["blocking"] is True
assert output["issues"][0]["description"] == "Test description"
def test_sbom_file_saving(self, handler, tmp_path):
# Test SBOM file is created correctly
diff = Diff()
diff.sbom = {"test": "data"}
sbom_path = tmp_path / "test.json"
handler.save_sbom_file(diff, str(sbom_path))
assert sbom_path.exists()