-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtest_diff_alerts.py
More file actions
79 lines (63 loc) · 2.82 KB
/
test_diff_alerts.py
File metadata and controls
79 lines (63 loc) · 2.82 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import pytest
from socketsecurity.core import Core
from socketsecurity.core.classes import Issue
class TestDiffAlerts:
"""Test alert collection for diff reports"""
def test_get_unchanged_alerts_filters_errors(self):
"""Test that get_unchanged_alerts only returns error/warn alerts"""
alerts_dict = {
'alert1': [
Issue(error=True, warn=False, purl='npm/pkg1', type='malicious'),
Issue(error=False, warn=False, purl='npm/pkg1', type='info', monitor=True)
],
'alert2': [
Issue(error=False, warn=True, purl='npm/pkg2', type='typosquat')
]
}
result = Core.get_unchanged_alerts(alerts_dict)
# Should only include error=True and warn=True alerts
assert len(result) == 2
assert any(alert.error for alert in result)
assert any(alert.warn for alert in result)
assert not any(alert.monitor and not (alert.error or alert.warn) for alert in result)
def test_get_unchanged_alerts_deduplicates(self):
"""Test that get_unchanged_alerts deduplicates by purl+type"""
alerts_dict = {
'alert1': [
Issue(error=True, warn=False, purl='npm/pkg1', type='malicious'),
Issue(error=True, warn=False, purl='npm/pkg1', type='malicious') # Duplicate
]
}
result = Core.get_unchanged_alerts(alerts_dict)
# Should deduplicate
assert len(result) == 1
def test_get_unchanged_alerts_empty(self):
"""Test that get_unchanged_alerts handles empty input"""
result = Core.get_unchanged_alerts({})
assert len(result) == 0
def test_get_removed_alerts_all_alerts(self):
"""Test that get_removed_alerts returns all alerts from removed packages"""
alerts_dict = {
'alert1': [
Issue(error=True, warn=False, purl='npm/pkg1', type='malicious'),
Issue(error=False, warn=True, purl='npm/pkg1', type='typosquat')
]
}
result = Core.get_removed_alerts(alerts_dict)
# Should include all alerts, not just error/warn
assert len(result) == 2
def test_get_removed_alerts_deduplicates(self):
"""Test that get_removed_alerts deduplicates by purl+type"""
alerts_dict = {
'alert1': [
Issue(error=True, warn=False, purl='npm/pkg1', type='malicious'),
Issue(error=True, warn=False, purl='npm/pkg1', type='malicious') # Duplicate
]
}
result = Core.get_removed_alerts(alerts_dict)
# Should deduplicate
assert len(result) == 1
def test_get_removed_alerts_empty(self):
"""Test that get_removed_alerts handles empty input"""
result = Core.get_removed_alerts({})
assert len(result) == 0