socketdev 3.6.3__tar.gz → 3.6.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {socketdev-3.6.3 → socketdev-3.6.4}/CHANGELOG.md +19 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/PKG-INFO +1 -1
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/core/dedupe.py +45 -14
- socketdev-3.6.4/socketdev/version.py +1 -0
- socketdev-3.6.4/tests/unit/test_dedupe.py +368 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/tests/unit/test_full_scan_cached_polling_http.py +31 -0
- socketdev-3.6.3/socketdev/version.py +0 -1
- socketdev-3.6.3/tests/unit/test_dedupe.py +0 -192
- {socketdev-3.6.3 → socketdev-3.6.4}/.gitattributes +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/.github/CODEOWNERS +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/.github/PULL_REQUEST_TEMPLATE/bug-fix.md +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/.github/PULL_REQUEST_TEMPLATE/feature.md +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/.github/PULL_REQUEST_TEMPLATE/improvement.md +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/.github/actions/setup-hatch/action.yml +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/.github/actions/setup-sfw/action.yml +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/.github/dependabot.yml +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/.github/workflows/api-drift-check.yml +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/.github/workflows/dependency-review.yml +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/.github/workflows/package-check.yml +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/.github/workflows/pr-preview.yml +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/.github/workflows/release.yml +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/.github/workflows/version-check.yml +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/.gitignore +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/.hooks/sync_version.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/.python-version +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/CONTRIBUTING.md +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/LICENSE +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/README.rst +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/pyproject.toml +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/scripts/build.sh +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/scripts/check_api_enum_drift.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/scripts/deploy-test-pypi.sh +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/alertfullscansearch/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/alerts/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/alerttypes/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/analytics/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/apitokens/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/auditlog/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/basics/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/core/api.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/core/classes.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/core/enums.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/core/issues.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/core/retired_token.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/core/token_selection.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/dependencies/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/diffscans/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/exceptions.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/export/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/fixes/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/fullscans/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/historical/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/labels/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/licensemetadata/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/log.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/npm/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/openapi/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/org/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/purl/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/quota/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/report/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/repos/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/repositories/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/sbom/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/settings/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/supportedfiles/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/telemetry/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/threatfeed/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/tools/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/triage/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/uploadmanifests/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/utils/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/socketdev/webhooks/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/tests/README.md +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/tests/conftest.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/tests/integration/test_all_endpoints.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/tests/integration/test_comprehensive_integration.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/tests/integration/test_diffscans_integration.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/tests/integration/test_new_endpoints.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/tests/run_tests.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/tests/support/socket_api_fixture.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/tests/unit/__init__.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/tests/unit/test_all_endpoints_unit.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/tests/unit/test_enum_forward_compat.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/tests/unit/test_exceptions.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/tests/unit/test_issues_did_you_mean_props.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/tests/unit/test_retired_token.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/tests/unit/test_socket_alert_category.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/tests/unit/test_socket_purl_type.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/tests/unit/test_socket_sdk_unit.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/tests/unit/test_upload_manifests.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/tests/unit/test_working_endpoints_unit.py +0 -0
- {socketdev-3.6.3 → socketdev-3.6.4}/uv.lock +0 -0
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 3.6.4
|
|
4
|
+
|
|
5
|
+
### Fixed: every advisory on a package is kept
|
|
6
|
+
|
|
7
|
+
- `fullscans.stream()` and `purl.post()` no longer merge different
|
|
8
|
+
vulnerabilities of the same severity on a package into one alert. Alerts are
|
|
9
|
+
now told apart by their advisory ID (`props.ghsaId`, falling back to
|
|
10
|
+
`props.cveId`) as well as type, severity, category and file location. Before,
|
|
11
|
+
a package with six Critical advisories came back with one `criticalCVE`
|
|
12
|
+
alert.
|
|
13
|
+
- When the same alert does appear more than once (in one artifact, or across
|
|
14
|
+
the release files of a package in a `purl.post()` result), the merged alert
|
|
15
|
+
carries the most severe `action` (`error`, then `warn`, `monitor`, `ignore`)
|
|
16
|
+
instead of the first one seen. A blocking alert can no longer be hidden
|
|
17
|
+
behind a triaged or ignored one. The merged alert keeps the `key` of the
|
|
18
|
+
first sighting, so that `key` can come from a release whose own action was
|
|
19
|
+
less severe. `fullscans.stream()` does not merge across releases: each
|
|
20
|
+
release file is its own artifact there.
|
|
21
|
+
|
|
3
22
|
## 3.6.3
|
|
4
23
|
|
|
5
24
|
### Fixed: `settings.integration_events()` requested the wrong path
|
|
@@ -2,12 +2,45 @@ from collections import defaultdict
|
|
|
2
2
|
from typing import Dict, List, Any
|
|
3
3
|
from socketdev.log import log
|
|
4
4
|
|
|
5
|
+
# Props that name the advisory behind a vulnerability alert. Every advisory of
|
|
6
|
+
# one severity on a package shares an alert type (``criticalCVE``, ``cve`` and
|
|
7
|
+
# so on), so these are what tell two of them apart.
|
|
8
|
+
#
|
|
9
|
+
# Socket's CVE alerts carry ``ghsaId`` and ``cveId``. The other names are in no
|
|
10
|
+
# current alert schema; they mirror ``Issue.advisory_id()`` in socket-python-cli
|
|
11
|
+
# (socketsecurity/core/classes.py), which reads alerts from this SDK. Keep the
|
|
12
|
+
# two lists in step.
|
|
13
|
+
ADVISORY_ID_PROPS = ("ghsaId", "ghsa_id", "cveId", "cve_id", "cve")
|
|
14
|
+
|
|
15
|
+
# Policy actions from least to most severe. An unknown or missing action ranks
|
|
16
|
+
# below "ignore", so it never replaces a known action and the merged result
|
|
17
|
+
# doesn't depend on which release is listed first.
|
|
18
|
+
ACTION_RANK = {"ignore": 0, "monitor": 1, "warn": 2, "error": 3}
|
|
19
|
+
|
|
5
20
|
|
|
6
21
|
class Dedupe:
|
|
7
22
|
@staticmethod
|
|
8
23
|
def normalize_file_path(path: str) -> str:
|
|
9
24
|
return path.split("/", 1)[-1] if path and "/" in path else path or ""
|
|
10
25
|
|
|
26
|
+
@staticmethod
|
|
27
|
+
def advisory_id(alert: dict) -> str:
|
|
28
|
+
"""The alert's GHSA or CVE identifier, upper-cased, or "" if it has none."""
|
|
29
|
+
props = alert.get("props")
|
|
30
|
+
if not isinstance(props, dict):
|
|
31
|
+
return ""
|
|
32
|
+
for prop_name in ADVISORY_ID_PROPS:
|
|
33
|
+
value = props.get(prop_name)
|
|
34
|
+
if isinstance(value, (list, tuple)):
|
|
35
|
+
value = next((v for v in value if isinstance(v, str) and v.strip()), "")
|
|
36
|
+
if isinstance(value, str) and value.strip():
|
|
37
|
+
return value.strip().upper()
|
|
38
|
+
return ""
|
|
39
|
+
|
|
40
|
+
@staticmethod
|
|
41
|
+
def action_rank(action: Any) -> int:
|
|
42
|
+
return ACTION_RANK.get(action, -1) if isinstance(action, str) else -1
|
|
43
|
+
|
|
11
44
|
@staticmethod
|
|
12
45
|
def alert_key(alert: dict) -> tuple:
|
|
13
46
|
return (
|
|
@@ -16,21 +49,12 @@ class Dedupe:
|
|
|
16
49
|
alert.get("category"),
|
|
17
50
|
Dedupe.normalize_file_path(alert.get("file")),
|
|
18
51
|
alert.get("start"),
|
|
19
|
-
alert.get("end")
|
|
52
|
+
alert.get("end"),
|
|
53
|
+
Dedupe.advisory_id(alert),
|
|
20
54
|
)
|
|
21
55
|
|
|
22
56
|
@staticmethod
|
|
23
57
|
def consolidate_and_merge_alerts(package_group: List[Dict[str, Any]]) -> Dict[str, Any]:
|
|
24
|
-
def alert_identity(alert: dict) -> tuple:
|
|
25
|
-
return (
|
|
26
|
-
alert.get("type"),
|
|
27
|
-
alert.get("severity"),
|
|
28
|
-
alert.get("category"),
|
|
29
|
-
Dedupe.normalize_file_path(alert.get("file")),
|
|
30
|
-
alert.get("start"),
|
|
31
|
-
alert.get("end")
|
|
32
|
-
)
|
|
33
|
-
|
|
34
58
|
alert_map: Dict[tuple, dict] = {}
|
|
35
59
|
releases = set()
|
|
36
60
|
for pkg in package_group:
|
|
@@ -38,7 +62,7 @@ class Dedupe:
|
|
|
38
62
|
releases.add(release)
|
|
39
63
|
|
|
40
64
|
for alert in pkg.get("alerts", []):
|
|
41
|
-
identity =
|
|
65
|
+
identity = Dedupe.alert_key(alert)
|
|
42
66
|
|
|
43
67
|
if identity not in alert_map:
|
|
44
68
|
# Build alert dict with only fields that exist in the original alert.
|
|
@@ -66,8 +90,15 @@ class Dedupe:
|
|
|
66
90
|
|
|
67
91
|
alert_map[identity] = consolidated_alert
|
|
68
92
|
else:
|
|
69
|
-
|
|
70
|
-
|
|
93
|
+
merged = alert_map[identity]
|
|
94
|
+
if release not in merged["releases"]:
|
|
95
|
+
merged["releases"].append(release)
|
|
96
|
+
# Keep the most severe action seen, so a release that blocks
|
|
97
|
+
# is never hidden behind one that doesn't. Only the action
|
|
98
|
+
# moves: key and props stay with the first sighting, so the
|
|
99
|
+
# key can belong to a release with a less severe action.
|
|
100
|
+
if Dedupe.action_rank(alert.get("action")) > Dedupe.action_rank(merged.get("action")):
|
|
101
|
+
merged["action"] = alert.get("action")
|
|
71
102
|
|
|
72
103
|
base = package_group[0]
|
|
73
104
|
base["releases"] = sorted(releases)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "3.6.4"
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from socketdev.core.dedupe import Dedupe
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class TestDedupe(unittest.TestCase):
|
|
6
|
+
|
|
7
|
+
def test_consolidate_by_input_purl(self):
|
|
8
|
+
"""Test that packages are correctly grouped by inputPurl"""
|
|
9
|
+
# Sample data similar to what the user provided
|
|
10
|
+
packages = [
|
|
11
|
+
{
|
|
12
|
+
"id": "15591824355",
|
|
13
|
+
"name": "pyonepassword",
|
|
14
|
+
"version": "5.0.0",
|
|
15
|
+
"type": "pypi",
|
|
16
|
+
"release": "py3-none-any-whl",
|
|
17
|
+
"inputPurl": "pkg:pypi/pyonepassword@5.0.0",
|
|
18
|
+
"batchIndex": 0,
|
|
19
|
+
"alerts": []
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"id": "15594798924",
|
|
23
|
+
"name": "pyonepassword",
|
|
24
|
+
"version": "5.0.0",
|
|
25
|
+
"type": "pypi",
|
|
26
|
+
"release": "tar-gz",
|
|
27
|
+
"inputPurl": "pkg:pypi/pyonepassword@5.0.0",
|
|
28
|
+
"batchIndex": 0,
|
|
29
|
+
"alerts": []
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"id": "77600911089",
|
|
33
|
+
"name": "socketsecurity",
|
|
34
|
+
"version": "2.2.7",
|
|
35
|
+
"type": "pypi",
|
|
36
|
+
"release": "py3-none-any-whl",
|
|
37
|
+
"inputPurl": "pkg:pypi/socketsecurity",
|
|
38
|
+
"batchIndex": 0,
|
|
39
|
+
"alerts": []
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"id": "77600911090",
|
|
43
|
+
"name": "socketsecurity",
|
|
44
|
+
"version": "2.2.7",
|
|
45
|
+
"type": "pypi",
|
|
46
|
+
"release": "tar-gz",
|
|
47
|
+
"inputPurl": "pkg:pypi/socketsecurity",
|
|
48
|
+
"batchIndex": 0,
|
|
49
|
+
"alerts": []
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
# Group by inputPurl
|
|
54
|
+
grouped = Dedupe.consolidate_by_input_purl(packages)
|
|
55
|
+
|
|
56
|
+
# Should have 2 groups
|
|
57
|
+
self.assertEqual(len(grouped), 2)
|
|
58
|
+
|
|
59
|
+
# Check pyonepassword group
|
|
60
|
+
pyonepassword_group = grouped["pkg:pypi/pyonepassword@5.0.0"]
|
|
61
|
+
self.assertEqual(len(pyonepassword_group), 2)
|
|
62
|
+
self.assertEqual(pyonepassword_group[0]["name"], "pyonepassword")
|
|
63
|
+
self.assertEqual(pyonepassword_group[1]["name"], "pyonepassword")
|
|
64
|
+
|
|
65
|
+
# Check socketsecurity group
|
|
66
|
+
socketsecurity_group = grouped["pkg:pypi/socketsecurity"]
|
|
67
|
+
self.assertEqual(len(socketsecurity_group), 2)
|
|
68
|
+
self.assertEqual(socketsecurity_group[0]["name"], "socketsecurity")
|
|
69
|
+
self.assertEqual(socketsecurity_group[1]["name"], "socketsecurity")
|
|
70
|
+
|
|
71
|
+
def test_dedupe_with_input_purl_grouping(self):
|
|
72
|
+
"""Test that dedupe returns separate results when grouping by inputPurl"""
|
|
73
|
+
packages = [
|
|
74
|
+
{
|
|
75
|
+
"id": "15591824355",
|
|
76
|
+
"name": "pyonepassword",
|
|
77
|
+
"version": "5.0.0",
|
|
78
|
+
"type": "pypi",
|
|
79
|
+
"release": "py3-none-any-whl",
|
|
80
|
+
"inputPurl": "pkg:pypi/pyonepassword@5.0.0",
|
|
81
|
+
"batchIndex": 0,
|
|
82
|
+
"alerts": []
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"id": "15594798924",
|
|
86
|
+
"name": "pyonepassword",
|
|
87
|
+
"version": "5.0.0",
|
|
88
|
+
"type": "pypi",
|
|
89
|
+
"release": "tar-gz",
|
|
90
|
+
"inputPurl": "pkg:pypi/pyonepassword@5.0.0",
|
|
91
|
+
"batchIndex": 0,
|
|
92
|
+
"alerts": []
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"id": "77600911089",
|
|
96
|
+
"name": "socketsecurity",
|
|
97
|
+
"version": "2.2.7",
|
|
98
|
+
"type": "pypi",
|
|
99
|
+
"release": "py3-none-any-whl",
|
|
100
|
+
"inputPurl": "pkg:pypi/socketsecurity",
|
|
101
|
+
"batchIndex": 0,
|
|
102
|
+
"alerts": []
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"id": "77600911090",
|
|
106
|
+
"name": "socketsecurity",
|
|
107
|
+
"version": "2.2.7",
|
|
108
|
+
"type": "pypi",
|
|
109
|
+
"release": "tar-gz",
|
|
110
|
+
"inputPurl": "pkg:pypi/socketsecurity",
|
|
111
|
+
"batchIndex": 0,
|
|
112
|
+
"alerts": []
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
|
|
116
|
+
# Test with new inputPurl grouping (now the default and only method)
|
|
117
|
+
result = Dedupe.dedupe(packages)
|
|
118
|
+
|
|
119
|
+
# Should return 2 deduplicated packages
|
|
120
|
+
self.assertEqual(len(result), 2)
|
|
121
|
+
|
|
122
|
+
# Find each package in results
|
|
123
|
+
pyonepassword_result = None
|
|
124
|
+
socketsecurity_result = None
|
|
125
|
+
|
|
126
|
+
for pkg in result:
|
|
127
|
+
if pkg["name"] == "pyonepassword":
|
|
128
|
+
pyonepassword_result = pkg
|
|
129
|
+
elif pkg["name"] == "socketsecurity":
|
|
130
|
+
socketsecurity_result = pkg
|
|
131
|
+
|
|
132
|
+
# Both should be present
|
|
133
|
+
self.assertIsNotNone(pyonepassword_result)
|
|
134
|
+
self.assertIsNotNone(socketsecurity_result)
|
|
135
|
+
|
|
136
|
+
# Check that releases are consolidated
|
|
137
|
+
self.assertIn("releases", pyonepassword_result)
|
|
138
|
+
self.assertIn("releases", socketsecurity_result)
|
|
139
|
+
self.assertEqual(len(pyonepassword_result["releases"]), 2)
|
|
140
|
+
self.assertEqual(len(socketsecurity_result["releases"]), 2)
|
|
141
|
+
|
|
142
|
+
# Check that batchIndex is removed from results
|
|
143
|
+
self.assertNotIn("batchIndex", pyonepassword_result)
|
|
144
|
+
self.assertNotIn("batchIndex", socketsecurity_result)
|
|
145
|
+
|
|
146
|
+
def test_dedupe_batched_parameter_backward_compatibility(self):
|
|
147
|
+
"""Test that batched parameter is kept for backward compatibility but doesn't change behavior"""
|
|
148
|
+
packages = [
|
|
149
|
+
{
|
|
150
|
+
"id": "15591824355",
|
|
151
|
+
"name": "pyonepassword",
|
|
152
|
+
"version": "5.0.0",
|
|
153
|
+
"type": "pypi",
|
|
154
|
+
"release": "py3-none-any-whl",
|
|
155
|
+
"inputPurl": "pkg:pypi/pyonepassword@5.0.0",
|
|
156
|
+
"batchIndex": 0,
|
|
157
|
+
"alerts": []
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
"id": "77600911089",
|
|
161
|
+
"name": "socketsecurity",
|
|
162
|
+
"version": "2.2.7",
|
|
163
|
+
"type": "pypi",
|
|
164
|
+
"release": "py3-none-any-whl",
|
|
165
|
+
"inputPurl": "pkg:pypi/socketsecurity@2.2.7",
|
|
166
|
+
"batchIndex": 0,
|
|
167
|
+
"alerts": []
|
|
168
|
+
}
|
|
169
|
+
]
|
|
170
|
+
|
|
171
|
+
# Test with batched=True
|
|
172
|
+
result_batched_true = Dedupe.dedupe(packages, batched=True)
|
|
173
|
+
|
|
174
|
+
# Test with batched=False
|
|
175
|
+
result_batched_false = Dedupe.dedupe(packages, batched=False)
|
|
176
|
+
|
|
177
|
+
# Both should return 2 results (same behavior regardless of batched parameter)
|
|
178
|
+
self.assertEqual(len(result_batched_true), 2)
|
|
179
|
+
self.assertEqual(len(result_batched_false), 2)
|
|
180
|
+
|
|
181
|
+
# Results should be the same
|
|
182
|
+
names_true = sorted([pkg['name'] for pkg in result_batched_true])
|
|
183
|
+
names_false = sorted([pkg['name'] for pkg in result_batched_false])
|
|
184
|
+
self.assertEqual(names_true, names_false)
|
|
185
|
+
|
|
186
|
+
# Should not contain batchIndex
|
|
187
|
+
for pkg in result_batched_true + result_batched_false:
|
|
188
|
+
self.assertNotIn("batchIndex", pkg)
|
|
189
|
+
|
|
190
|
+
@staticmethod
|
|
191
|
+
def _cve(ghsa, action, cve="", severity="critical", alert_type="criticalCVE", key=None):
|
|
192
|
+
return {
|
|
193
|
+
"key": key or f"key-{ghsa}",
|
|
194
|
+
"type": alert_type,
|
|
195
|
+
"severity": severity,
|
|
196
|
+
"category": "vulnerability",
|
|
197
|
+
"action": action,
|
|
198
|
+
"props": {"ghsaId": ghsa, "cveId": cve},
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
def test_same_severity_advisories_on_one_package_stay_separate(self):
|
|
202
|
+
"""Each advisory keeps its own alert even when type and severity match"""
|
|
203
|
+
ghsa_ids = [
|
|
204
|
+
"GHSA-8r5x-fm3f-whwj", "GHSA-p8wg-vrv2-v86f", "GHSA-2w6w-674q-4c4q",
|
|
205
|
+
"GHSA-w457-6q6x-cgp9", "GHSA-765h-qjxv-5f44", "GHSA-f2jv-r9rf-7988",
|
|
206
|
+
]
|
|
207
|
+
packages = [{
|
|
208
|
+
"id": "artifact-1", "type": "npm", "name": "handlebars", "version": "4.0.11",
|
|
209
|
+
"alerts": [self._cve(ghsa, "error") for ghsa in ghsa_ids],
|
|
210
|
+
}]
|
|
211
|
+
|
|
212
|
+
result = Dedupe.dedupe(packages, batched=False)
|
|
213
|
+
|
|
214
|
+
alerts = result[0]["alerts"]
|
|
215
|
+
self.assertEqual(len(alerts), 6)
|
|
216
|
+
self.assertEqual(sorted(a["props"]["ghsaId"] for a in alerts), sorted(ghsa_ids))
|
|
217
|
+
self.assertTrue(all(a["action"] == "error" for a in alerts))
|
|
218
|
+
|
|
219
|
+
def test_blocking_advisory_is_kept_when_an_earlier_one_is_triaged(self):
|
|
220
|
+
"""A monitored or ignored advisory listed first must not hide a later Block one"""
|
|
221
|
+
for triaged_action in ("ignore", "monitor", "warn"):
|
|
222
|
+
with self.subTest(triaged_action=triaged_action):
|
|
223
|
+
packages = [{
|
|
224
|
+
"id": "artifact-1", "type": "npm", "name": "example", "version": "1.0.0",
|
|
225
|
+
"alerts": [
|
|
226
|
+
self._cve("GHSA-aaaa-aaaa-aaaa", triaged_action),
|
|
227
|
+
self._cve("GHSA-bbbb-bbbb-bbbb", "error"),
|
|
228
|
+
],
|
|
229
|
+
}]
|
|
230
|
+
|
|
231
|
+
alerts = Dedupe.dedupe(packages, batched=False)[0]["alerts"]
|
|
232
|
+
|
|
233
|
+
actions = {a["props"]["ghsaId"]: a["action"] for a in alerts}
|
|
234
|
+
self.assertEqual(actions, {
|
|
235
|
+
"GHSA-aaaa-aaaa-aaaa": triaged_action,
|
|
236
|
+
"GHSA-bbbb-bbbb-bbbb": "error",
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
def test_same_advisory_across_releases_merges_with_most_severe_action(self):
|
|
240
|
+
"""One advisory seen in several releases is one alert carrying the strictest action"""
|
|
241
|
+
orders = [
|
|
242
|
+
["ignore", "monitor", "error", "warn"],
|
|
243
|
+
["error", "ignore", "monitor", "warn"],
|
|
244
|
+
["monitor", "warn", "ignore", "error"],
|
|
245
|
+
]
|
|
246
|
+
for actions in orders:
|
|
247
|
+
with self.subTest(actions=actions):
|
|
248
|
+
packages = [
|
|
249
|
+
{
|
|
250
|
+
"id": f"artifact-{i}", "type": "pypi", "name": "example", "version": "1.0",
|
|
251
|
+
"release": release, "inputPurl": "pkg:pypi/example@1.0",
|
|
252
|
+
"alerts": [self._cve("GHSA-cccc-cccc-cccc", action, cve="CVE-2020-0001",
|
|
253
|
+
key=f"key-{release}")],
|
|
254
|
+
}
|
|
255
|
+
for i, (release, action) in enumerate(zip(["a", "b", "c", "d"], actions))
|
|
256
|
+
]
|
|
257
|
+
|
|
258
|
+
alerts = Dedupe.dedupe(packages)[0]["alerts"]
|
|
259
|
+
|
|
260
|
+
self.assertEqual(len(alerts), 1)
|
|
261
|
+
self.assertEqual(alerts[0]["action"], "error")
|
|
262
|
+
self.assertEqual(alerts[0]["releases"], ["a", "b", "c", "d"])
|
|
263
|
+
|
|
264
|
+
def test_merged_action_ranks_error_warn_monitor_ignore(self):
|
|
265
|
+
cases = [
|
|
266
|
+
(["ignore", "monitor"], "monitor"),
|
|
267
|
+
(["monitor", "warn"], "warn"),
|
|
268
|
+
(["warn", "ignore"], "warn"),
|
|
269
|
+
([None, "ignore"], "ignore"),
|
|
270
|
+
(["ignore", None], "ignore"),
|
|
271
|
+
(["unknown-action", "monitor"], "monitor"),
|
|
272
|
+
# An unknown action yields to any known one, "ignore" included,
|
|
273
|
+
# and never replaces a known "error", in either order.
|
|
274
|
+
(["unknown-action", "ignore"], "ignore"),
|
|
275
|
+
(["error", "unknown-action"], "error"),
|
|
276
|
+
(["unknown-action", "error"], "error"),
|
|
277
|
+
]
|
|
278
|
+
for actions, expected in cases:
|
|
279
|
+
with self.subTest(actions=actions):
|
|
280
|
+
packages = [
|
|
281
|
+
{
|
|
282
|
+
"id": f"artifact-{i}", "type": "pypi", "name": "example", "version": "1.0",
|
|
283
|
+
"release": f"r{i}", "inputPurl": "pkg:pypi/example@1.0",
|
|
284
|
+
"alerts": [self._cve("GHSA-dddd-dddd-dddd", action)],
|
|
285
|
+
}
|
|
286
|
+
for i, action in enumerate(actions)
|
|
287
|
+
]
|
|
288
|
+
alerts = Dedupe.dedupe(packages)[0]["alerts"]
|
|
289
|
+
self.assertEqual(len(alerts), 1)
|
|
290
|
+
self.assertEqual(alerts[0]["action"], expected)
|
|
291
|
+
|
|
292
|
+
def test_merged_alert_keeps_first_key_when_action_comes_from_a_later_release(self):
|
|
293
|
+
"""Only the action moves to the most severe sighting; key and props stay with the first"""
|
|
294
|
+
packages = [
|
|
295
|
+
{
|
|
296
|
+
"id": f"artifact-{release}", "type": "pypi", "name": "example", "version": "1.0",
|
|
297
|
+
"release": release, "inputPurl": "pkg:pypi/example@1.0",
|
|
298
|
+
"alerts": [self._cve("GHSA-eeee-eeee-eeee", action, key=f"key-{release}")],
|
|
299
|
+
}
|
|
300
|
+
for release, action in [("sdist", "monitor"), ("wheel", "error")]
|
|
301
|
+
]
|
|
302
|
+
|
|
303
|
+
alerts = Dedupe.dedupe(packages)[0]["alerts"]
|
|
304
|
+
|
|
305
|
+
self.assertEqual(len(alerts), 1)
|
|
306
|
+
self.assertEqual(alerts[0]["key"], "key-sdist")
|
|
307
|
+
self.assertEqual(alerts[0]["action"], "error")
|
|
308
|
+
|
|
309
|
+
def test_non_advisory_alert_on_a_package_with_cves_keeps_its_own_entry(self):
|
|
310
|
+
packages = [{
|
|
311
|
+
"id": "artifact-1", "type": "npm", "name": "example", "version": "1.0.0",
|
|
312
|
+
"alerts": [
|
|
313
|
+
self._cve("GHSA-ffff-ffff-ffff", "monitor"),
|
|
314
|
+
{"key": "key-malware", "type": "malware", "severity": "critical",
|
|
315
|
+
"category": "supplyChainRisk", "action": "error", "props": {}},
|
|
316
|
+
],
|
|
317
|
+
}]
|
|
318
|
+
|
|
319
|
+
alerts = Dedupe.dedupe(packages, batched=False)[0]["alerts"]
|
|
320
|
+
|
|
321
|
+
self.assertEqual({a["type"]: a["action"] for a in alerts}, {"criticalCVE": "monitor", "malware": "error"})
|
|
322
|
+
|
|
323
|
+
def test_dedupe_of_no_packages_is_empty(self):
|
|
324
|
+
self.assertEqual(Dedupe.dedupe([]), [])
|
|
325
|
+
|
|
326
|
+
def test_advisory_id_falls_back_to_cve_and_ignores_case(self):
|
|
327
|
+
self.assertEqual(Dedupe.advisory_id({"props": {"ghsaId": "", "cveId": "cve-2021-1"}}), "CVE-2021-1")
|
|
328
|
+
self.assertEqual(Dedupe.advisory_id({"props": {"ghsaId": " ghsa-x "}}), "GHSA-X")
|
|
329
|
+
self.assertEqual(Dedupe.advisory_id({"props": {"cve": ["", "CVE-2022-2"]}}), "CVE-2022-2")
|
|
330
|
+
self.assertEqual(Dedupe.advisory_id({"props": []}), "")
|
|
331
|
+
self.assertEqual(Dedupe.advisory_id({}), "")
|
|
332
|
+
|
|
333
|
+
packages = [{
|
|
334
|
+
"id": "artifact-1", "type": "npm", "name": "example", "version": "1.0.0",
|
|
335
|
+
"alerts": [
|
|
336
|
+
self._cve("", "error", cve="CVE-2021-0001"),
|
|
337
|
+
self._cve("", "error", cve="CVE-2021-0002"),
|
|
338
|
+
self._cve("", "monitor", cve="cve-2021-0001"),
|
|
339
|
+
],
|
|
340
|
+
}]
|
|
341
|
+
alerts = Dedupe.dedupe(packages, batched=False)[0]["alerts"]
|
|
342
|
+
self.assertEqual(sorted(a["props"]["cveId"] for a in alerts), ["CVE-2021-0001", "CVE-2021-0002"])
|
|
343
|
+
|
|
344
|
+
def test_alerts_without_advisory_still_merge_across_releases(self):
|
|
345
|
+
"""Alerts without an advisory ID merge on type, severity and location, with file paths normalized"""
|
|
346
|
+
def file_alert(path, action):
|
|
347
|
+
return {
|
|
348
|
+
"key": f"key-{path}", "type": "networkAccess", "severity": "middle",
|
|
349
|
+
"category": "supplyChainRisk", "file": path, "start": 10, "end": 20,
|
|
350
|
+
"action": action, "props": {"module": "http"},
|
|
351
|
+
}
|
|
352
|
+
packages = [
|
|
353
|
+
{"id": "1", "type": "pypi", "name": "example", "version": "1.0", "release": "wheel",
|
|
354
|
+
"inputPurl": "pkg:pypi/example@1.0", "alerts": [file_alert("wheel/example/net.py", "monitor")]},
|
|
355
|
+
{"id": "2", "type": "pypi", "name": "example", "version": "1.0", "release": "sdist",
|
|
356
|
+
"inputPurl": "pkg:pypi/example@1.0", "alerts": [file_alert("sdist/example/net.py", "warn")]},
|
|
357
|
+
]
|
|
358
|
+
|
|
359
|
+
alerts = Dedupe.dedupe(packages)[0]["alerts"]
|
|
360
|
+
|
|
361
|
+
self.assertEqual(len(alerts), 1)
|
|
362
|
+
self.assertEqual(alerts[0]["file"], "example/net.py")
|
|
363
|
+
self.assertEqual(alerts[0]["action"], "warn")
|
|
364
|
+
self.assertEqual(alerts[0]["releases"], ["wheel", "sdist"])
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
if __name__ == '__main__':
|
|
368
|
+
unittest.main()
|
|
@@ -118,6 +118,37 @@ def test_duplicate_artifacts_merge_alerts_and_preserve_score_event(api_fixture):
|
|
|
118
118
|
assert artifact["alerts"][0]["releases"] == ["wheel", "source"]
|
|
119
119
|
|
|
120
120
|
|
|
121
|
+
def test_stream_keeps_each_advisory_and_its_action(api_fixture):
|
|
122
|
+
"""Same-severity CVEs on one artifact reach the caller as separate alerts."""
|
|
123
|
+
path = "orgs/org/full-scans/scan"
|
|
124
|
+
|
|
125
|
+
def cve(ghsa, cve_id, action):
|
|
126
|
+
return {
|
|
127
|
+
"key": "key-" + ghsa, "type": "criticalCVE", "severity": "critical",
|
|
128
|
+
"category": "vulnerability", "action": action,
|
|
129
|
+
"props": {"ghsaId": ghsa, "cveId": cve_id},
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
artifact = {
|
|
133
|
+
"id": "artifact-1", "type": "npm", "name": "handlebars", "version": "4.0.11",
|
|
134
|
+
"alerts": [
|
|
135
|
+
cve("GHSA-w457-6q6x-cgp9", "CVE-2019-19919", "monitor"),
|
|
136
|
+
cve("GHSA-765h-qjxv-5f44", "CVE-2021-23383", "error"),
|
|
137
|
+
cve("GHSA-f2jv-r9rf-7988", "CVE-2021-23369", "ignore"),
|
|
138
|
+
],
|
|
139
|
+
}
|
|
140
|
+
api_fixture.route("GET", path, ndjson(artifact))
|
|
141
|
+
|
|
142
|
+
typed = sdk_for(api_fixture).fullscans.stream("org", "scan", use_types=True)
|
|
143
|
+
|
|
144
|
+
alerts = typed.artifacts["artifact-1"].alerts
|
|
145
|
+
assert [(alert.props["ghsaId"], alert.action) for alert in alerts] == [
|
|
146
|
+
("GHSA-w457-6q6x-cgp9", "monitor"),
|
|
147
|
+
("GHSA-765h-qjxv-5f44", "error"),
|
|
148
|
+
("GHSA-f2jv-r9rf-7988", "ignore"),
|
|
149
|
+
]
|
|
150
|
+
|
|
151
|
+
|
|
121
152
|
@pytest.mark.parametrize("status", [403, 404])
|
|
122
153
|
def test_deterministic_errors_stop_immediately(api_fixture, status):
|
|
123
154
|
api_fixture.route("GET", "orgs/org/full-scans/scan", SocketResponse(status, {"error": {"message": "denied"}}))
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "3.6.3"
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import unittest
|
|
2
|
-
from socketdev.core.dedupe import Dedupe
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class TestDedupe(unittest.TestCase):
|
|
6
|
-
|
|
7
|
-
def test_consolidate_by_input_purl(self):
|
|
8
|
-
"""Test that packages are correctly grouped by inputPurl"""
|
|
9
|
-
# Sample data similar to what the user provided
|
|
10
|
-
packages = [
|
|
11
|
-
{
|
|
12
|
-
"id": "15591824355",
|
|
13
|
-
"name": "pyonepassword",
|
|
14
|
-
"version": "5.0.0",
|
|
15
|
-
"type": "pypi",
|
|
16
|
-
"release": "py3-none-any-whl",
|
|
17
|
-
"inputPurl": "pkg:pypi/pyonepassword@5.0.0",
|
|
18
|
-
"batchIndex": 0,
|
|
19
|
-
"alerts": []
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
"id": "15594798924",
|
|
23
|
-
"name": "pyonepassword",
|
|
24
|
-
"version": "5.0.0",
|
|
25
|
-
"type": "pypi",
|
|
26
|
-
"release": "tar-gz",
|
|
27
|
-
"inputPurl": "pkg:pypi/pyonepassword@5.0.0",
|
|
28
|
-
"batchIndex": 0,
|
|
29
|
-
"alerts": []
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
"id": "77600911089",
|
|
33
|
-
"name": "socketsecurity",
|
|
34
|
-
"version": "2.2.7",
|
|
35
|
-
"type": "pypi",
|
|
36
|
-
"release": "py3-none-any-whl",
|
|
37
|
-
"inputPurl": "pkg:pypi/socketsecurity",
|
|
38
|
-
"batchIndex": 0,
|
|
39
|
-
"alerts": []
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
"id": "77600911090",
|
|
43
|
-
"name": "socketsecurity",
|
|
44
|
-
"version": "2.2.7",
|
|
45
|
-
"type": "pypi",
|
|
46
|
-
"release": "tar-gz",
|
|
47
|
-
"inputPurl": "pkg:pypi/socketsecurity",
|
|
48
|
-
"batchIndex": 0,
|
|
49
|
-
"alerts": []
|
|
50
|
-
}
|
|
51
|
-
]
|
|
52
|
-
|
|
53
|
-
# Group by inputPurl
|
|
54
|
-
grouped = Dedupe.consolidate_by_input_purl(packages)
|
|
55
|
-
|
|
56
|
-
# Should have 2 groups
|
|
57
|
-
self.assertEqual(len(grouped), 2)
|
|
58
|
-
|
|
59
|
-
# Check pyonepassword group
|
|
60
|
-
pyonepassword_group = grouped["pkg:pypi/pyonepassword@5.0.0"]
|
|
61
|
-
self.assertEqual(len(pyonepassword_group), 2)
|
|
62
|
-
self.assertEqual(pyonepassword_group[0]["name"], "pyonepassword")
|
|
63
|
-
self.assertEqual(pyonepassword_group[1]["name"], "pyonepassword")
|
|
64
|
-
|
|
65
|
-
# Check socketsecurity group
|
|
66
|
-
socketsecurity_group = grouped["pkg:pypi/socketsecurity"]
|
|
67
|
-
self.assertEqual(len(socketsecurity_group), 2)
|
|
68
|
-
self.assertEqual(socketsecurity_group[0]["name"], "socketsecurity")
|
|
69
|
-
self.assertEqual(socketsecurity_group[1]["name"], "socketsecurity")
|
|
70
|
-
|
|
71
|
-
def test_dedupe_with_input_purl_grouping(self):
|
|
72
|
-
"""Test that dedupe returns separate results when grouping by inputPurl"""
|
|
73
|
-
packages = [
|
|
74
|
-
{
|
|
75
|
-
"id": "15591824355",
|
|
76
|
-
"name": "pyonepassword",
|
|
77
|
-
"version": "5.0.0",
|
|
78
|
-
"type": "pypi",
|
|
79
|
-
"release": "py3-none-any-whl",
|
|
80
|
-
"inputPurl": "pkg:pypi/pyonepassword@5.0.0",
|
|
81
|
-
"batchIndex": 0,
|
|
82
|
-
"alerts": []
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
"id": "15594798924",
|
|
86
|
-
"name": "pyonepassword",
|
|
87
|
-
"version": "5.0.0",
|
|
88
|
-
"type": "pypi",
|
|
89
|
-
"release": "tar-gz",
|
|
90
|
-
"inputPurl": "pkg:pypi/pyonepassword@5.0.0",
|
|
91
|
-
"batchIndex": 0,
|
|
92
|
-
"alerts": []
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
"id": "77600911089",
|
|
96
|
-
"name": "socketsecurity",
|
|
97
|
-
"version": "2.2.7",
|
|
98
|
-
"type": "pypi",
|
|
99
|
-
"release": "py3-none-any-whl",
|
|
100
|
-
"inputPurl": "pkg:pypi/socketsecurity",
|
|
101
|
-
"batchIndex": 0,
|
|
102
|
-
"alerts": []
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
"id": "77600911090",
|
|
106
|
-
"name": "socketsecurity",
|
|
107
|
-
"version": "2.2.7",
|
|
108
|
-
"type": "pypi",
|
|
109
|
-
"release": "tar-gz",
|
|
110
|
-
"inputPurl": "pkg:pypi/socketsecurity",
|
|
111
|
-
"batchIndex": 0,
|
|
112
|
-
"alerts": []
|
|
113
|
-
}
|
|
114
|
-
]
|
|
115
|
-
|
|
116
|
-
# Test with new inputPurl grouping (now the default and only method)
|
|
117
|
-
result = Dedupe.dedupe(packages)
|
|
118
|
-
|
|
119
|
-
# Should return 2 deduplicated packages
|
|
120
|
-
self.assertEqual(len(result), 2)
|
|
121
|
-
|
|
122
|
-
# Find each package in results
|
|
123
|
-
pyonepassword_result = None
|
|
124
|
-
socketsecurity_result = None
|
|
125
|
-
|
|
126
|
-
for pkg in result:
|
|
127
|
-
if pkg["name"] == "pyonepassword":
|
|
128
|
-
pyonepassword_result = pkg
|
|
129
|
-
elif pkg["name"] == "socketsecurity":
|
|
130
|
-
socketsecurity_result = pkg
|
|
131
|
-
|
|
132
|
-
# Both should be present
|
|
133
|
-
self.assertIsNotNone(pyonepassword_result)
|
|
134
|
-
self.assertIsNotNone(socketsecurity_result)
|
|
135
|
-
|
|
136
|
-
# Check that releases are consolidated
|
|
137
|
-
self.assertIn("releases", pyonepassword_result)
|
|
138
|
-
self.assertIn("releases", socketsecurity_result)
|
|
139
|
-
self.assertEqual(len(pyonepassword_result["releases"]), 2)
|
|
140
|
-
self.assertEqual(len(socketsecurity_result["releases"]), 2)
|
|
141
|
-
|
|
142
|
-
# Check that batchIndex is removed from results
|
|
143
|
-
self.assertNotIn("batchIndex", pyonepassword_result)
|
|
144
|
-
self.assertNotIn("batchIndex", socketsecurity_result)
|
|
145
|
-
|
|
146
|
-
def test_dedupe_batched_parameter_backward_compatibility(self):
|
|
147
|
-
"""Test that batched parameter is kept for backward compatibility but doesn't change behavior"""
|
|
148
|
-
packages = [
|
|
149
|
-
{
|
|
150
|
-
"id": "15591824355",
|
|
151
|
-
"name": "pyonepassword",
|
|
152
|
-
"version": "5.0.0",
|
|
153
|
-
"type": "pypi",
|
|
154
|
-
"release": "py3-none-any-whl",
|
|
155
|
-
"inputPurl": "pkg:pypi/pyonepassword@5.0.0",
|
|
156
|
-
"batchIndex": 0,
|
|
157
|
-
"alerts": []
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
"id": "77600911089",
|
|
161
|
-
"name": "socketsecurity",
|
|
162
|
-
"version": "2.2.7",
|
|
163
|
-
"type": "pypi",
|
|
164
|
-
"release": "py3-none-any-whl",
|
|
165
|
-
"inputPurl": "pkg:pypi/socketsecurity@2.2.7",
|
|
166
|
-
"batchIndex": 0,
|
|
167
|
-
"alerts": []
|
|
168
|
-
}
|
|
169
|
-
]
|
|
170
|
-
|
|
171
|
-
# Test with batched=True
|
|
172
|
-
result_batched_true = Dedupe.dedupe(packages, batched=True)
|
|
173
|
-
|
|
174
|
-
# Test with batched=False
|
|
175
|
-
result_batched_false = Dedupe.dedupe(packages, batched=False)
|
|
176
|
-
|
|
177
|
-
# Both should return 2 results (same behavior regardless of batched parameter)
|
|
178
|
-
self.assertEqual(len(result_batched_true), 2)
|
|
179
|
-
self.assertEqual(len(result_batched_false), 2)
|
|
180
|
-
|
|
181
|
-
# Results should be the same
|
|
182
|
-
names_true = sorted([pkg['name'] for pkg in result_batched_true])
|
|
183
|
-
names_false = sorted([pkg['name'] for pkg in result_batched_false])
|
|
184
|
-
self.assertEqual(names_true, names_false)
|
|
185
|
-
|
|
186
|
-
# Should not contain batchIndex
|
|
187
|
-
for pkg in result_batched_true + result_batched_false:
|
|
188
|
-
self.assertNotIn("batchIndex", pkg)
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
if __name__ == '__main__':
|
|
192
|
-
unittest.main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|