socketdev 3.0.4__tar.gz → 3.0.5__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.0.4 → socketdev-3.0.5}/PKG-INFO +1 -1
- {socketdev-3.0.4 → socketdev-3.0.5}/pyproject.toml +1 -1
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/apitokens/__init__.py +40 -3
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/auditlog/__init__.py +4 -1
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/core/dedupe.py +28 -33
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/dependencies/__init__.py +16 -11
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/diffscans/__init__.py +3 -2
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/fullscans/__init__.py +13 -4
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/purl/__init__.py +1 -1
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/report/__init__.py +19 -4
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/utils/__init__.py +30 -8
- socketdev-3.0.5/socketdev/version.py +1 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/tests/integration/test_all_endpoints.py +2 -1
- {socketdev-3.0.4 → socketdev-3.0.5}/tests/unit/test_all_endpoints_unit.py +71 -62
- socketdev-3.0.5/tests/unit/test_dedupe.py +192 -0
- socketdev-3.0.4/socketdev/version.py +0 -1
- {socketdev-3.0.4 → socketdev-3.0.5}/.github/CODEOWNERS +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/.github/PULL_REQUEST_TEMPLATE/bug-fix.md +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/.github/PULL_REQUEST_TEMPLATE/feature.md +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/.github/PULL_REQUEST_TEMPLATE/improvement.md +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/.github/workflows/pr-preview.yml +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/.github/workflows/release.yml +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/.github/workflows/version-check.yml +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/.gitignore +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/.hooks/sync_version.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/.python-version +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/LICENSE +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/README.rst +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/scripts/build.sh +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/scripts/deploy-test-pypi.sh +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/__init__.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/alerttypes/__init__.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/analytics/__init__.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/core/api.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/core/classes.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/core/issues.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/exceptions.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/export/__init__.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/historical/__init__.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/labels/__init__.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/licensemetadata/__init__.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/log.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/npm/__init__.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/openapi/__init__.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/org/__init__.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/quota/__init__.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/repos/__init__.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/repositories/__init__.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/sbom/__init__.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/settings/__init__.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/threatfeed/__init__.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/tools/__init__.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/socketdev/triage/__init__.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/tests/README.md +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/tests/conftest.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/tests/integration/test_comprehensive_integration.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/tests/integration/test_diffscans_integration.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/tests/integration/test_new_endpoints.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/tests/run_tests.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/tests/unit/__init__.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/tests/unit/test_socket_sdk_unit.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/tests/unit/test_working_endpoints_unit.py +0 -0
- {socketdev-3.0.4 → socketdev-3.0.5}/uv.lock +0 -0
|
@@ -28,20 +28,57 @@ class ApiTokens:
|
|
|
28
28
|
log.error(response.text)
|
|
29
29
|
return {}
|
|
30
30
|
|
|
31
|
-
def
|
|
31
|
+
def list(self, org_slug: str, **kwargs) -> dict:
|
|
32
|
+
"""
|
|
33
|
+
List API tokens for an organization.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
org_slug: Organization slug
|
|
37
|
+
**kwargs: Query parameters
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
dict: API response containing list of tokens
|
|
41
|
+
"""
|
|
42
|
+
path = f"orgs/{org_slug}/api-tokens"
|
|
43
|
+
query_params = {}
|
|
44
|
+
if kwargs:
|
|
45
|
+
query_params.update(kwargs)
|
|
46
|
+
|
|
47
|
+
if query_params:
|
|
48
|
+
from urllib.parse import urlencode
|
|
49
|
+
path += "?" + urlencode(query_params)
|
|
50
|
+
response = self.api.do_request(path=path, method="GET")
|
|
51
|
+
if response.status_code == 200:
|
|
52
|
+
return response.json()
|
|
53
|
+
log.error(f"Error listing API tokens: {response.status_code}")
|
|
54
|
+
log.error(response.text)
|
|
55
|
+
return {}
|
|
56
|
+
|
|
57
|
+
def update(self, org_slug: str, token_id: str = None, **kwargs) -> dict:
|
|
32
58
|
"""
|
|
33
59
|
Update an API token.
|
|
34
60
|
|
|
35
61
|
Args:
|
|
36
62
|
org_slug: Organization slug
|
|
63
|
+
token_id: Token ID to update (optional, can be in kwargs)
|
|
37
64
|
**kwargs: Token update parameters
|
|
38
65
|
|
|
39
66
|
Returns:
|
|
40
67
|
dict: API response containing the updated token details
|
|
41
68
|
"""
|
|
42
|
-
|
|
69
|
+
# Extract token_id from kwargs if not provided as parameter
|
|
70
|
+
if token_id is None and 'token_id' in kwargs:
|
|
71
|
+
token_id = kwargs.pop('token_id')
|
|
72
|
+
|
|
73
|
+
if token_id:
|
|
74
|
+
path = f"orgs/{org_slug}/api-tokens/{token_id}"
|
|
75
|
+
method = "PUT"
|
|
76
|
+
else:
|
|
77
|
+
path = f"orgs/{org_slug}/api-tokens/update"
|
|
78
|
+
method = "POST"
|
|
79
|
+
|
|
43
80
|
payload = json.dumps(kwargs) if kwargs else "{}"
|
|
44
|
-
response = self.api.do_request(path=path, method=
|
|
81
|
+
response = self.api.do_request(path=path, method=method, payload=payload)
|
|
45
82
|
if response.status_code == 200:
|
|
46
83
|
return response.json()
|
|
47
84
|
log.error(f"Error updating API token: {response.status_code}")
|
|
@@ -19,7 +19,10 @@ class AuditLog:
|
|
|
19
19
|
dict: API response containing audit log entries
|
|
20
20
|
"""
|
|
21
21
|
path = f"orgs/{org_slug}/audit-log"
|
|
22
|
-
|
|
22
|
+
if kwargs:
|
|
23
|
+
from urllib.parse import urlencode
|
|
24
|
+
path += "?" + urlencode(kwargs)
|
|
25
|
+
response = self.api.do_request(path=path)
|
|
23
26
|
if response.status_code == 200:
|
|
24
27
|
return response.json()
|
|
25
28
|
log.error(f"Error getting audit log: {response.status_code}")
|
|
@@ -88,40 +88,35 @@ class Dedupe:
|
|
|
88
88
|
|
|
89
89
|
@staticmethod
|
|
90
90
|
def dedupe(packages: List[Dict[str, Any]], batched: bool = True) -> List[Dict[str, Any]]:
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
91
|
+
# Always group by inputPurl now, but keep the batched parameter for backward compatibility
|
|
92
|
+
grouped = Dedupe.consolidate_by_input_purl(packages)
|
|
93
|
+
results = []
|
|
94
|
+
for group in grouped.values():
|
|
95
|
+
result = Dedupe.consolidate_and_merge_alerts(group)
|
|
96
|
+
# Remove batchIndex from the result
|
|
97
|
+
if "batchIndex" in result:
|
|
98
|
+
del result["batchIndex"]
|
|
99
|
+
results.append(result)
|
|
100
|
+
return results
|
|
96
101
|
|
|
97
102
|
@staticmethod
|
|
98
|
-
def
|
|
99
|
-
|
|
103
|
+
def consolidate_by_input_purl(packages: List[Dict[str, Any]]) -> dict[str, list[dict[str, Any]]]:
|
|
104
|
+
"""Group packages by their inputPurl field"""
|
|
105
|
+
grouped: Dict[str, List[Dict[str, Any]]] = defaultdict(list)
|
|
106
|
+
|
|
107
|
+
# Handle both list of packages and nested structure
|
|
108
|
+
if packages and isinstance(packages[0], list):
|
|
109
|
+
# If we get a nested list, flatten it
|
|
110
|
+
flat_packages = []
|
|
111
|
+
for sublist in packages:
|
|
112
|
+
if isinstance(sublist, list):
|
|
113
|
+
flat_packages.extend(sublist)
|
|
114
|
+
else:
|
|
115
|
+
flat_packages.append(sublist)
|
|
116
|
+
packages = flat_packages
|
|
117
|
+
|
|
100
118
|
for pkg in packages:
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
@staticmethod
|
|
105
|
-
def consolidate_by_order(packages: List[Dict[str, Any]]) -> dict[int, list[dict[str, Any]]]:
|
|
106
|
-
grouped: Dict[int, List[Dict[str, Any]]] = defaultdict(list)
|
|
107
|
-
batch_index = 0
|
|
108
|
-
package_purl = None
|
|
109
|
-
try:
|
|
110
|
-
for pkg in packages:
|
|
111
|
-
name = pkg["name"]
|
|
112
|
-
version = pkg["version"]
|
|
113
|
-
namespace = pkg.get("namespace")
|
|
114
|
-
ecosystem = pkg.get("type")
|
|
115
|
-
new_purl = f"pkg:{ecosystem}/"
|
|
116
|
-
if namespace:
|
|
117
|
-
new_purl += f"{namespace}/"
|
|
118
|
-
new_purl += f"{name}@{version}"
|
|
119
|
-
if package_purl is None:
|
|
120
|
-
package_purl = new_purl
|
|
121
|
-
if package_purl != new_purl:
|
|
122
|
-
batch_index += 1
|
|
123
|
-
pkg["batchIndex"] = batch_index
|
|
124
|
-
grouped[pkg["batchIndex"]].append(pkg)
|
|
125
|
-
except Exception as error:
|
|
126
|
-
log.error(error)
|
|
119
|
+
# inputPurl should always exist now, fallback to purl if not found
|
|
120
|
+
group_key = pkg.get("inputPurl", pkg.get("purl", str(hash(str(pkg)))))
|
|
121
|
+
grouped[group_key].append(pkg)
|
|
127
122
|
return grouped
|
|
@@ -13,9 +13,9 @@ class Dependencies:
|
|
|
13
13
|
def __init__(self, api):
|
|
14
14
|
self.api = api
|
|
15
15
|
|
|
16
|
-
def post(self, files: list, params: dict, use_lazy_loading: bool =
|
|
16
|
+
def post(self, files: list, params: dict, use_lazy_loading: bool = True, workspace: str = None, base_path: str = None) -> dict:
|
|
17
17
|
if use_lazy_loading:
|
|
18
|
-
loaded_files = Utils.load_files_for_sending_lazy(files, workspace)
|
|
18
|
+
loaded_files = Utils.load_files_for_sending_lazy(files, workspace, base_path=base_path)
|
|
19
19
|
else:
|
|
20
20
|
loaded_files = []
|
|
21
21
|
loaded_files = load_files(files, loaded_files)
|
|
@@ -30,15 +30,20 @@ class Dependencies:
|
|
|
30
30
|
log.error(response.text)
|
|
31
31
|
return result
|
|
32
32
|
|
|
33
|
-
def get(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
33
|
+
def get(self, org_slug: str = None, ecosystem: str = None, package: str = None, version: str = None, **kwargs) -> dict:
|
|
34
|
+
# If all specific parameters are provided, use the specific dependency endpoint
|
|
35
|
+
if org_slug and ecosystem and package and version:
|
|
36
|
+
path = f"orgs/{org_slug}/dependencies/{ecosystem}/{package}/{version}"
|
|
37
|
+
response = self.api.do_request(path=path, method="GET")
|
|
38
|
+
else:
|
|
39
|
+
# Otherwise use the search endpoint
|
|
40
|
+
limit = kwargs.get('limit', 50)
|
|
41
|
+
offset = kwargs.get('offset', 0)
|
|
42
|
+
path = "dependencies/search"
|
|
43
|
+
payload = {"limit": limit, "offset": offset}
|
|
44
|
+
payload_str = json.dumps(payload)
|
|
45
|
+
response = self.api.do_request(path=path, method="POST", payload=payload_str)
|
|
46
|
+
|
|
42
47
|
if response.status_code == 200:
|
|
43
48
|
result = response.json()
|
|
44
49
|
else:
|
|
@@ -30,7 +30,7 @@ class DiffScans:
|
|
|
30
30
|
log.error(f"Error fetching diff scan: {response.status_code}, message: {response.text}")
|
|
31
31
|
return {}
|
|
32
32
|
|
|
33
|
-
def create_from_repo(self, org_slug: str, repo_slug: str, files: list, params: Optional[Dict[str, Any]] = None, use_lazy_loading: bool = False, workspace: str = None, max_open_files: int = 100) -> dict:
|
|
33
|
+
def create_from_repo(self, org_slug: str, repo_slug: str, files: list, params: Optional[Dict[str, Any]] = None, use_lazy_loading: bool = False, workspace: str = None, max_open_files: int = 100, base_path: str = None) -> dict:
|
|
34
34
|
"""
|
|
35
35
|
Create a diff scan from repo HEAD, uploading files as multipart form data.
|
|
36
36
|
|
|
@@ -45,6 +45,7 @@ class DiffScans:
|
|
|
45
45
|
workspace: Base directory path to make file paths relative to
|
|
46
46
|
max_open_files: Maximum number of files to keep open simultaneously when using
|
|
47
47
|
lazy loading. Useful for systems with low ulimit values (default: 100)
|
|
48
|
+
base_path: Optional base path to strip from key names for cleaner file organization
|
|
48
49
|
|
|
49
50
|
Returns:
|
|
50
51
|
dict: API response containing diff scan results
|
|
@@ -63,7 +64,7 @@ class DiffScans:
|
|
|
63
64
|
|
|
64
65
|
# Use lazy loading if requested
|
|
65
66
|
if use_lazy_loading:
|
|
66
|
-
prepared_files = Utils.load_files_for_sending_lazy(files, workspace, max_open_files)
|
|
67
|
+
prepared_files = Utils.load_files_for_sending_lazy(files, workspace, max_open_files, base_path)
|
|
67
68
|
else:
|
|
68
69
|
prepared_files = files
|
|
69
70
|
|
|
@@ -701,8 +701,16 @@ class FullScans:
|
|
|
701
701
|
|
|
702
702
|
|
|
703
703
|
def get(self, org_slug: str, params: dict, use_types: bool = False) -> Union[dict, GetFullScanMetadataResponse]:
|
|
704
|
-
|
|
705
|
-
|
|
704
|
+
# Check if this is a request for a specific scan by ID
|
|
705
|
+
if 'id' in params and len(params) == 1:
|
|
706
|
+
# Get specific scan by ID: /orgs/{org_slug}/full-scans/{full_scan_id}
|
|
707
|
+
scan_id = params['id']
|
|
708
|
+
path = f"orgs/{org_slug}/full-scans/{scan_id}"
|
|
709
|
+
else:
|
|
710
|
+
# List scans with query parameters: /orgs/{org_slug}/full-scans?params
|
|
711
|
+
params_arg = urllib.parse.urlencode(params)
|
|
712
|
+
path = "orgs/" + org_slug + "/full-scans?" + str(params_arg)
|
|
713
|
+
|
|
706
714
|
response = self.api.do_request(path=path)
|
|
707
715
|
|
|
708
716
|
if response.status_code == 200:
|
|
@@ -720,7 +728,7 @@ class FullScans:
|
|
|
720
728
|
)
|
|
721
729
|
return {}
|
|
722
730
|
|
|
723
|
-
def post(self, files: list, params: FullScanParams, use_types: bool = False, use_lazy_loading: bool = False, workspace: str = None, max_open_files: int = 100) -> Union[dict, CreateFullScanResponse]:
|
|
731
|
+
def post(self, files: list, params: FullScanParams, use_types: bool = False, use_lazy_loading: bool = False, workspace: str = None, max_open_files: int = 100, base_path: str = None) -> Union[dict, CreateFullScanResponse]:
|
|
724
732
|
"""
|
|
725
733
|
Create a new full scan by uploading manifest files.
|
|
726
734
|
|
|
@@ -734,6 +742,7 @@ class FullScans:
|
|
|
734
742
|
workspace: Base directory path to make file paths relative to
|
|
735
743
|
max_open_files: Maximum number of files to keep open simultaneously when using
|
|
736
744
|
lazy loading. Useful for systems with low ulimit values (default: 100)
|
|
745
|
+
base_path: Optional base path to strip from key names for cleaner file organization
|
|
737
746
|
|
|
738
747
|
Returns:
|
|
739
748
|
dict or CreateFullScanResponse: API response containing scan results
|
|
@@ -754,7 +763,7 @@ class FullScans:
|
|
|
754
763
|
|
|
755
764
|
# Use lazy loading if requested
|
|
756
765
|
if use_lazy_loading:
|
|
757
|
-
prepared_files = Utils.load_files_for_sending_lazy(files, workspace, max_open_files)
|
|
766
|
+
prepared_files = Utils.load_files_for_sending_lazy(files, workspace, max_open_files, base_path)
|
|
758
767
|
else:
|
|
759
768
|
prepared_files = files
|
|
760
769
|
|
|
@@ -33,7 +33,7 @@ class Purl:
|
|
|
33
33
|
purl.append(item)
|
|
34
34
|
except json.JSONDecodeError:
|
|
35
35
|
continue
|
|
36
|
-
purl_deduped = Dedupe.dedupe(purl)
|
|
36
|
+
purl_deduped = Dedupe.dedupe(purl, batched=True)
|
|
37
37
|
return purl_deduped
|
|
38
38
|
|
|
39
39
|
log.error(f"Error posting {components} to the Purl API: {response.status_code}")
|
|
@@ -58,14 +58,29 @@ class Report:
|
|
|
58
58
|
return {}
|
|
59
59
|
|
|
60
60
|
def create(self, files: list) -> dict:
|
|
61
|
+
# Handle both file path strings and file tuples
|
|
61
62
|
open_files = []
|
|
62
|
-
for
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
for file_entry in files:
|
|
64
|
+
if isinstance(file_entry, tuple) and len(file_entry) == 2:
|
|
65
|
+
name, file_data = file_entry
|
|
66
|
+
if isinstance(file_data, tuple) and len(file_data) == 2:
|
|
67
|
+
# Format: [("field_name", ("filename", file_obj))]
|
|
68
|
+
filename, file_obj = file_data
|
|
69
|
+
file_info = (name, (filename, file_obj, "text/plain"))
|
|
70
|
+
open_files.append(file_info)
|
|
71
|
+
else:
|
|
72
|
+
# Format: [("field_name", "file_path")]
|
|
73
|
+
file_info = (name, (name, open(file_data, "rb"), "text/plain"))
|
|
74
|
+
open_files.append(file_info)
|
|
75
|
+
else:
|
|
76
|
+
# Handle other formats if needed
|
|
77
|
+
log.error(f"Unexpected file format: {file_entry}")
|
|
78
|
+
return {}
|
|
79
|
+
|
|
65
80
|
path = "report/upload"
|
|
66
81
|
payload = {}
|
|
67
82
|
response = self.api.do_request(path=path, method="PUT", files=open_files, payload=payload)
|
|
68
|
-
if response.status_code
|
|
83
|
+
if response.status_code in (200, 201):
|
|
69
84
|
return response.json()
|
|
70
85
|
log.error(f"Error creating report: {response.status_code}")
|
|
71
86
|
log.error(response.text)
|
|
@@ -233,7 +233,7 @@ class Utils:
|
|
|
233
233
|
return integration_type # type: ignore
|
|
234
234
|
|
|
235
235
|
@staticmethod
|
|
236
|
-
def load_files_for_sending_lazy(files: List[str], workspace: str = None, max_open_files: int = 100) -> List[Tuple[str, Tuple[str, LazyFileLoader]]]:
|
|
236
|
+
def load_files_for_sending_lazy(files: List[str], workspace: str = None, max_open_files: int = 100, base_path: str = None) -> List[Tuple[str, Tuple[str, LazyFileLoader]]]:
|
|
237
237
|
"""
|
|
238
238
|
Prepares files for sending to the Socket API using lazy loading.
|
|
239
239
|
|
|
@@ -246,6 +246,7 @@ class Utils:
|
|
|
246
246
|
files: List of file paths from find_files()
|
|
247
247
|
workspace: Base directory path to make paths relative to
|
|
248
248
|
max_open_files: Maximum number of files to keep open simultaneously (default: 100)
|
|
249
|
+
base_path: Optional base path to strip from key names for cleaner file organization
|
|
249
250
|
|
|
250
251
|
Returns:
|
|
251
252
|
List of tuples formatted for requests multipart upload:
|
|
@@ -257,6 +258,8 @@ class Utils:
|
|
|
257
258
|
send_files = []
|
|
258
259
|
if workspace and "\\" in workspace:
|
|
259
260
|
workspace = workspace.replace("\\", "/")
|
|
261
|
+
if base_path and "\\" in base_path:
|
|
262
|
+
base_path = base_path.replace("\\", "/")
|
|
260
263
|
|
|
261
264
|
for file_path in files:
|
|
262
265
|
# Normalize file path
|
|
@@ -265,14 +268,33 @@ class Utils:
|
|
|
265
268
|
|
|
266
269
|
_, name = file_path.rsplit("/", 1)
|
|
267
270
|
|
|
268
|
-
# Calculate the key
|
|
269
|
-
|
|
271
|
+
# Calculate the key name for the form data
|
|
272
|
+
key = file_path
|
|
273
|
+
|
|
274
|
+
# If base_path is provided, strip it from the file path to create the key
|
|
275
|
+
if base_path:
|
|
276
|
+
# Normalize base_path to ensure consistent handling of trailing slashes
|
|
277
|
+
normalized_base_path = base_path.rstrip("/") + "/" if not base_path.endswith("/") else base_path
|
|
278
|
+
if key.startswith(normalized_base_path):
|
|
279
|
+
key = key[len(normalized_base_path):]
|
|
280
|
+
elif key.startswith(base_path.rstrip("/")):
|
|
281
|
+
# Handle case where base_path matches exactly without trailing slash
|
|
282
|
+
stripped_base = base_path.rstrip("/")
|
|
283
|
+
if key.startswith(stripped_base + "/") or key == stripped_base:
|
|
284
|
+
key = key[len(stripped_base):]
|
|
285
|
+
key = key.lstrip("/")
|
|
286
|
+
|
|
287
|
+
# If workspace is provided and base_path wasn't used, fall back to workspace logic
|
|
288
|
+
elif workspace and file_path.startswith(workspace):
|
|
270
289
|
key = file_path[len(workspace):]
|
|
271
|
-
|
|
272
|
-
key =
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
key
|
|
290
|
+
key = key.lstrip("/")
|
|
291
|
+
key = key.lstrip("./")
|
|
292
|
+
|
|
293
|
+
# If neither base_path nor workspace matched, clean up the key
|
|
294
|
+
if key == file_path:
|
|
295
|
+
# No base_path or workspace stripping occurred, clean up leading parts
|
|
296
|
+
key = key.lstrip("/")
|
|
297
|
+
key = key.lstrip("./")
|
|
276
298
|
|
|
277
299
|
# Create lazy file loader instead of opening file immediately
|
|
278
300
|
# Use the relative path (key) as filename instead of truncated basename
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "3.0.5"
|
|
@@ -59,7 +59,8 @@ class TestAllEndpointsMocked(unittest.TestCase):
|
|
|
59
59
|
json.dump({"name": "test", "version": "1.0.0"}, f)
|
|
60
60
|
f.flush()
|
|
61
61
|
try:
|
|
62
|
-
|
|
62
|
+
# Pass the file path as a string, not a file object
|
|
63
|
+
result = self.sdk.dependencies.post([f.name], {})
|
|
63
64
|
self.assertIn("packages", result)
|
|
64
65
|
finally:
|
|
65
66
|
os.unlink(f.name)
|
|
@@ -52,9 +52,9 @@ class TestAllEndpointsUnit(unittest.TestCase):
|
|
|
52
52
|
f.flush()
|
|
53
53
|
|
|
54
54
|
try:
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
# Pass the file path as a string, not a file object
|
|
56
|
+
files = [f.name]
|
|
57
|
+
result = self.sdk.dependencies.post(files, {})
|
|
58
58
|
|
|
59
59
|
self.assertEqual(result, expected_data)
|
|
60
60
|
self.mock_requests.request.assert_called_once()
|
|
@@ -148,7 +148,7 @@ class TestAllEndpointsUnit(unittest.TestCase):
|
|
|
148
148
|
self.assertEqual(result, expected_data)
|
|
149
149
|
call_args = self.mock_requests.request.call_args
|
|
150
150
|
self.assertEqual(call_args[0][0], "POST")
|
|
151
|
-
self.assertIn("/orgs/test-org/
|
|
151
|
+
self.assertIn("/orgs/test-org/diff-scans/from-repo/test-repo", call_args[0][1])
|
|
152
152
|
|
|
153
153
|
finally:
|
|
154
154
|
os.unlink(f.name)
|
|
@@ -167,7 +167,7 @@ class TestAllEndpointsUnit(unittest.TestCase):
|
|
|
167
167
|
|
|
168
168
|
def test_diffscans_delete_unit(self):
|
|
169
169
|
"""Test diffscans deletion."""
|
|
170
|
-
self._mock_response({"status": "
|
|
170
|
+
self._mock_response({"status": "ok"}, 200)
|
|
171
171
|
|
|
172
172
|
result = self.sdk.diffscans.delete("test-org", "diff-123")
|
|
173
173
|
|
|
@@ -191,7 +191,7 @@ class TestAllEndpointsUnit(unittest.TestCase):
|
|
|
191
191
|
self.assertEqual(result, expected_data)
|
|
192
192
|
call_args = self.mock_requests.request.call_args
|
|
193
193
|
self.assertEqual(call_args[0][0], "GET")
|
|
194
|
-
self.assertIn("/orgs/test-org/export/scan-123
|
|
194
|
+
self.assertIn("/orgs/test-org/export/cdx/scan-123", call_args[0][1])
|
|
195
195
|
|
|
196
196
|
def test_export_spdx_bom_unit(self):
|
|
197
197
|
"""Test SPDX BOM export."""
|
|
@@ -207,19 +207,7 @@ class TestAllEndpointsUnit(unittest.TestCase):
|
|
|
207
207
|
self.assertEqual(result, expected_data)
|
|
208
208
|
call_args = self.mock_requests.request.call_args
|
|
209
209
|
self.assertEqual(call_args[0][0], "GET")
|
|
210
|
-
self.assertIn("/orgs/test-org/export/scan-123
|
|
211
|
-
|
|
212
|
-
def test_export_get_unit(self):
|
|
213
|
-
"""Test export list."""
|
|
214
|
-
expected_data = {"exports": [{"id": "exp-1", "type": "cdx", "status": "ready"}]}
|
|
215
|
-
self._mock_response(expected_data)
|
|
216
|
-
|
|
217
|
-
result = self.sdk.export.get("test-org")
|
|
218
|
-
|
|
219
|
-
self.assertEqual(result, expected_data)
|
|
220
|
-
call_args = self.mock_requests.request.call_args
|
|
221
|
-
self.assertEqual(call_args[0][0], "GET")
|
|
222
|
-
self.assertIn("/orgs/test-org/export", call_args[0][1])
|
|
210
|
+
self.assertIn("/orgs/test-org/export/spdx/scan-123", call_args[0][1])
|
|
223
211
|
|
|
224
212
|
# FullScans endpoints
|
|
225
213
|
def test_fullscans_get_unit(self):
|
|
@@ -227,7 +215,7 @@ class TestAllEndpointsUnit(unittest.TestCase):
|
|
|
227
215
|
expected_data = {"id": "scan-123", "status": "completed", "results": []}
|
|
228
216
|
self._mock_response(expected_data)
|
|
229
217
|
|
|
230
|
-
# Test with
|
|
218
|
+
# Test with commit parameter
|
|
231
219
|
result = self.sdk.fullscans.get("test-org", {"id": "scan-123"})
|
|
232
220
|
|
|
233
221
|
self.assertEqual(result, expected_data)
|
|
@@ -309,7 +297,7 @@ class TestAllEndpointsUnit(unittest.TestCase):
|
|
|
309
297
|
self.assertEqual(result, expected_data)
|
|
310
298
|
call_args = self.mock_requests.request.call_args
|
|
311
299
|
self.assertEqual(call_args[0][0], "GET")
|
|
312
|
-
self.assertIn("/orgs/test-org/historical/trend", call_args[0][1])
|
|
300
|
+
self.assertIn("/orgs/test-org/historical/alerts/trend", call_args[0][1])
|
|
313
301
|
|
|
314
302
|
# NPM endpoints
|
|
315
303
|
def test_npm_issues_unit(self):
|
|
@@ -352,7 +340,7 @@ class TestAllEndpointsUnit(unittest.TestCase):
|
|
|
352
340
|
# Org endpoints
|
|
353
341
|
def test_org_get_unit(self):
|
|
354
342
|
"""Test organization retrieval."""
|
|
355
|
-
expected_data = {"name": "test-org", "id": "org-123", "plan": "pro"}
|
|
343
|
+
expected_data = {"organizations": {"test-org": {"name": "test-org", "id": "org-123", "plan": "pro"}}}
|
|
356
344
|
self._mock_response(expected_data)
|
|
357
345
|
|
|
358
346
|
result = self.sdk.org.get("test-org")
|
|
@@ -360,13 +348,33 @@ class TestAllEndpointsUnit(unittest.TestCase):
|
|
|
360
348
|
self.assertEqual(result, expected_data)
|
|
361
349
|
call_args = self.mock_requests.request.call_args
|
|
362
350
|
self.assertEqual(call_args[0][0], "GET")
|
|
363
|
-
self.assertIn("/
|
|
351
|
+
self.assertIn("/organizations", call_args[0][1])
|
|
364
352
|
|
|
365
353
|
# PURL endpoints
|
|
366
354
|
def test_purl_post_unit(self):
|
|
367
355
|
"""Test PURL validation endpoint."""
|
|
368
|
-
|
|
369
|
-
|
|
356
|
+
# Expected final result after deduplication - should match what the dedupe function produces
|
|
357
|
+
expected_data = [{
|
|
358
|
+
"inputPurl": "pkg:npm/lodash@4.17.21",
|
|
359
|
+
"purl": "pkg:npm/lodash@4.17.21",
|
|
360
|
+
"type": "npm",
|
|
361
|
+
"name": "lodash",
|
|
362
|
+
"version": "4.17.21",
|
|
363
|
+
"valid": True,
|
|
364
|
+
"alerts": [],
|
|
365
|
+
"releases": ["npm"]
|
|
366
|
+
}]
|
|
367
|
+
|
|
368
|
+
# Mock the NDJSON response that would come from the actual API
|
|
369
|
+
# This simulates what the API returns: newline-delimited JSON with SocketArtifact objects
|
|
370
|
+
mock_ndjson_response = '{"inputPurl": "pkg:npm/lodash@4.17.21", "purl": "pkg:npm/lodash@4.17.21", "type": "npm", "name": "lodash", "version": "4.17.21", "valid": true, "alerts": []}'
|
|
371
|
+
|
|
372
|
+
# Mock the response with NDJSON format
|
|
373
|
+
mock_response = Mock()
|
|
374
|
+
mock_response.status_code = 200
|
|
375
|
+
mock_response.headers = {'content-type': 'application/x-ndjson'}
|
|
376
|
+
mock_response.text = mock_ndjson_response
|
|
377
|
+
self.mock_requests.request.return_value = mock_response
|
|
370
378
|
|
|
371
379
|
components = [{"purl": "pkg:npm/lodash@4.17.21"}]
|
|
372
380
|
result = self.sdk.purl.post("false", components)
|
|
@@ -400,12 +408,12 @@ class TestAllEndpointsUnit(unittest.TestCase):
|
|
|
400
408
|
self.assertEqual(result, expected_data)
|
|
401
409
|
call_args = self.mock_requests.request.call_args
|
|
402
410
|
self.assertEqual(call_args[0][0], "GET")
|
|
403
|
-
self.assertIn("/
|
|
411
|
+
self.assertIn("/report/list", call_args[0][1])
|
|
404
412
|
|
|
405
413
|
def test_report_create_unit(self):
|
|
406
414
|
"""Test report creation."""
|
|
407
|
-
expected_data = {"id": "report-123", "
|
|
408
|
-
self._mock_response(expected_data, 201
|
|
415
|
+
expected_data = {"id": "report-123", "url": "https://socket.dev/report/report-123"}
|
|
416
|
+
self._mock_response(expected_data, 200) # API returns 200, not 201
|
|
409
417
|
|
|
410
418
|
with tempfile.NamedTemporaryFile(mode='w', suffix='.json', delete=False) as f:
|
|
411
419
|
json.dump({"name": "test", "version": "1.0.0"}, f)
|
|
@@ -418,8 +426,8 @@ class TestAllEndpointsUnit(unittest.TestCase):
|
|
|
418
426
|
|
|
419
427
|
self.assertEqual(result, expected_data)
|
|
420
428
|
call_args = self.mock_requests.request.call_args
|
|
421
|
-
self.assertEqual(call_args[0][0], "
|
|
422
|
-
self.assertIn("/
|
|
429
|
+
self.assertEqual(call_args[0][0], "PUT") # API uses PUT, not POST
|
|
430
|
+
self.assertIn("/report/upload", call_args[0][1]) # Correct path per OpenAPI
|
|
423
431
|
|
|
424
432
|
finally:
|
|
425
433
|
os.unlink(f.name)
|
|
@@ -434,7 +442,7 @@ class TestAllEndpointsUnit(unittest.TestCase):
|
|
|
434
442
|
self.assertEqual(result, expected_data)
|
|
435
443
|
call_args = self.mock_requests.request.call_args
|
|
436
444
|
self.assertEqual(call_args[0][0], "GET")
|
|
437
|
-
self.assertIn("/
|
|
445
|
+
self.assertIn("/report/view/report-123", call_args[0][1])
|
|
438
446
|
|
|
439
447
|
def test_report_delete_unit(self):
|
|
440
448
|
"""Test report deletion."""
|
|
@@ -445,7 +453,7 @@ class TestAllEndpointsUnit(unittest.TestCase):
|
|
|
445
453
|
self.assertTrue(result)
|
|
446
454
|
call_args = self.mock_requests.request.call_args
|
|
447
455
|
self.assertEqual(call_args[0][0], "DELETE")
|
|
448
|
-
self.assertIn("/
|
|
456
|
+
self.assertIn("/report/delete/report-123", call_args[0][1])
|
|
449
457
|
|
|
450
458
|
def test_report_supported_unit(self):
|
|
451
459
|
"""Test supported file types."""
|
|
@@ -457,7 +465,7 @@ class TestAllEndpointsUnit(unittest.TestCase):
|
|
|
457
465
|
self.assertEqual(result, expected_data)
|
|
458
466
|
call_args = self.mock_requests.request.call_args
|
|
459
467
|
self.assertEqual(call_args[0][0], "GET")
|
|
460
|
-
self.assertIn("/
|
|
468
|
+
self.assertIn("/report/supported", call_args[0][1])
|
|
461
469
|
|
|
462
470
|
# Settings endpoints
|
|
463
471
|
def test_settings_get_unit(self):
|
|
@@ -487,15 +495,15 @@ class TestAllEndpointsUnit(unittest.TestCase):
|
|
|
487
495
|
|
|
488
496
|
def test_triage_update_alert_triage_unit(self):
|
|
489
497
|
"""Test alert triage updating."""
|
|
490
|
-
expected_data = {"
|
|
498
|
+
expected_data = {"result": "Updated"}
|
|
491
499
|
self._mock_response(expected_data)
|
|
492
500
|
|
|
493
|
-
data = {"
|
|
501
|
+
data = {"alertTriage": [{"alertKey": "alert-123", "state": "ignore", "note": "Not applicable"}]}
|
|
494
502
|
result = self.sdk.triage.update_alert_triage("test-org", data)
|
|
495
503
|
|
|
496
504
|
self.assertEqual(result, expected_data)
|
|
497
505
|
call_args = self.mock_requests.request.call_args
|
|
498
|
-
self.assertEqual(call_args[0][0], "
|
|
506
|
+
self.assertEqual(call_args[0][0], "POST")
|
|
499
507
|
self.assertIn("/orgs/test-org/triage/alerts", call_args[0][1])
|
|
500
508
|
|
|
501
509
|
# New endpoints
|
|
@@ -509,7 +517,7 @@ class TestAllEndpointsUnit(unittest.TestCase):
|
|
|
509
517
|
self.assertEqual(result, expected_data)
|
|
510
518
|
call_args = self.mock_requests.request.call_args
|
|
511
519
|
self.assertEqual(call_args[0][0], "GET")
|
|
512
|
-
self.assertIn("/
|
|
520
|
+
self.assertIn("/orgs/test-org/threat-feed", call_args[0][1])
|
|
513
521
|
|
|
514
522
|
def test_analytics_get_org_unit(self):
|
|
515
523
|
"""Test analytics organization endpoint."""
|
|
@@ -564,12 +572,12 @@ class TestAllEndpointsUnit(unittest.TestCase):
|
|
|
564
572
|
expected_data = {"tokens": [{"id": "token-1", "name": "prod-token"}]}
|
|
565
573
|
self._mock_response(expected_data)
|
|
566
574
|
|
|
567
|
-
result = self.sdk.apitokens.list()
|
|
575
|
+
result = self.sdk.apitokens.list("test-org")
|
|
568
576
|
|
|
569
577
|
self.assertEqual(result, expected_data)
|
|
570
578
|
call_args = self.mock_requests.request.call_args
|
|
571
579
|
self.assertEqual(call_args[0][0], "GET")
|
|
572
|
-
self.assertIn("/api-tokens", call_args[0][1])
|
|
580
|
+
self.assertIn("/orgs/test-org/api-tokens", call_args[0][1])
|
|
573
581
|
|
|
574
582
|
def test_auditlog_get_unit(self):
|
|
575
583
|
"""Test audit log retrieval."""
|
|
@@ -592,57 +600,58 @@ class TestAllEndpointsUnit(unittest.TestCase):
|
|
|
592
600
|
|
|
593
601
|
self.assertEqual(result, expected_data)
|
|
594
602
|
call_args = self.mock_requests.request.call_args
|
|
595
|
-
self.assertEqual(call_args[0][0], "
|
|
603
|
+
self.assertEqual(call_args[0][0], "POST")
|
|
596
604
|
self.assertIn("/alert-types", call_args[0][1])
|
|
597
605
|
|
|
598
606
|
def test_labels_get_unit(self):
|
|
599
607
|
"""Test labels get endpoint."""
|
|
600
|
-
expected_data = {"
|
|
608
|
+
expected_data = {"id": "1", "name": "environment", "created_at": "2025-01-01"}
|
|
601
609
|
self._mock_response(expected_data)
|
|
602
610
|
|
|
603
|
-
result = self.sdk.labels.get("test-org", 1
|
|
611
|
+
result = self.sdk.labels.get("test-org", "1")
|
|
604
612
|
|
|
605
613
|
self.assertEqual(result, expected_data)
|
|
606
614
|
call_args = self.mock_requests.request.call_args
|
|
607
615
|
self.assertEqual(call_args[0][0], "GET")
|
|
608
|
-
self.assertIn("/orgs/test-org/
|
|
616
|
+
self.assertIn("/orgs/test-org/repos/labels/1", call_args[0][1])
|
|
609
617
|
|
|
610
|
-
def
|
|
611
|
-
"""Test labels put endpoint."""
|
|
618
|
+
def test_labels_setting_put_unit(self):
|
|
619
|
+
"""Test labels setting put endpoint."""
|
|
612
620
|
expected_data = {"updated": True}
|
|
613
|
-
self._mock_response(expected_data)
|
|
621
|
+
self._mock_response(expected_data, 201) # Label settings return 201
|
|
614
622
|
|
|
615
623
|
label_data = {"environment": {"production": {"critical": "true"}}}
|
|
616
|
-
result = self.sdk.labels.put("test-org", 1, label_data)
|
|
624
|
+
result = self.sdk.labels.setting.put("test-org", 1, label_data)
|
|
617
625
|
|
|
618
626
|
self.assertEqual(result, expected_data)
|
|
619
627
|
call_args = self.mock_requests.request.call_args
|
|
620
628
|
self.assertEqual(call_args[0][0], "PUT")
|
|
621
|
-
self.assertIn("/orgs/test-org/
|
|
629
|
+
self.assertIn("/orgs/test-org/repos/labels/1/label-setting", call_args[0][1])
|
|
622
630
|
|
|
623
631
|
def test_labels_delete_unit(self):
|
|
624
632
|
"""Test labels delete endpoint."""
|
|
625
633
|
expected_data = {"deleted": True}
|
|
626
634
|
self._mock_response(expected_data)
|
|
627
635
|
|
|
628
|
-
result = self.sdk.labels.delete("test-org", 1
|
|
636
|
+
result = self.sdk.labels.delete("test-org", "1")
|
|
629
637
|
|
|
630
638
|
self.assertEqual(result, expected_data)
|
|
631
639
|
call_args = self.mock_requests.request.call_args
|
|
632
640
|
self.assertEqual(call_args[0][0], "DELETE")
|
|
633
|
-
self.assertIn("/orgs/test-org/
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
641
|
+
self.assertIn("/orgs/test-org/repos/labels/1", call_args[0][1])
|
|
642
|
+
|
|
643
|
+
# License metadata only supports POST method per OpenAPI spec, no GET method available
|
|
644
|
+
# def test_licensemetadata_get_unit(self):
|
|
645
|
+
# """Test license metadata retrieval."""
|
|
646
|
+
# expected_data = {"licenses": [{"id": "MIT", "name": "MIT License"}]}
|
|
647
|
+
# self._mock_response(expected_data)
|
|
648
|
+
#
|
|
649
|
+
# result = self.sdk.licensemetadata.get()
|
|
650
|
+
#
|
|
651
|
+
# self.assertEqual(result, expected_data)
|
|
652
|
+
# call_args = self.mock_requests.request.call_args
|
|
653
|
+
# self.assertEqual(call_args[0][0], "GET")
|
|
654
|
+
# self.assertIn("/license-metadata", call_args[0][1])
|
|
646
655
|
|
|
647
656
|
|
|
648
657
|
if __name__ == "__main__":
|
|
@@ -0,0 +1,192 @@
|
|
|
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()
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "3.0.4"
|
|
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
|