socketdev 3.0.4__tar.gz → 3.0.6__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.
Files changed (64) hide show
  1. {socketdev-3.0.4 → socketdev-3.0.6}/PKG-INFO +1 -1
  2. {socketdev-3.0.4 → socketdev-3.0.6}/pyproject.toml +1 -1
  3. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/apitokens/__init__.py +40 -3
  4. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/auditlog/__init__.py +4 -1
  5. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/core/dedupe.py +28 -33
  6. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/dependencies/__init__.py +16 -11
  7. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/diffscans/__init__.py +5 -3
  8. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/fullscans/__init__.py +14 -4
  9. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/purl/__init__.py +1 -1
  10. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/report/__init__.py +19 -4
  11. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/utils/__init__.py +55 -8
  12. socketdev-3.0.6/socketdev/version.py +1 -0
  13. {socketdev-3.0.4 → socketdev-3.0.6}/tests/integration/test_all_endpoints.py +2 -1
  14. {socketdev-3.0.4 → socketdev-3.0.6}/tests/integration/test_comprehensive_integration.py +1 -1
  15. {socketdev-3.0.4 → socketdev-3.0.6}/tests/unit/test_all_endpoints_unit.py +71 -62
  16. socketdev-3.0.6/tests/unit/test_dedupe.py +192 -0
  17. {socketdev-3.0.4 → socketdev-3.0.6}/tests/unit/test_working_endpoints_unit.py +5 -5
  18. socketdev-3.0.4/socketdev/version.py +0 -1
  19. {socketdev-3.0.4 → socketdev-3.0.6}/.github/CODEOWNERS +0 -0
  20. {socketdev-3.0.4 → socketdev-3.0.6}/.github/PULL_REQUEST_TEMPLATE/bug-fix.md +0 -0
  21. {socketdev-3.0.4 → socketdev-3.0.6}/.github/PULL_REQUEST_TEMPLATE/feature.md +0 -0
  22. {socketdev-3.0.4 → socketdev-3.0.6}/.github/PULL_REQUEST_TEMPLATE/improvement.md +0 -0
  23. {socketdev-3.0.4 → socketdev-3.0.6}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
  24. {socketdev-3.0.4 → socketdev-3.0.6}/.github/workflows/pr-preview.yml +0 -0
  25. {socketdev-3.0.4 → socketdev-3.0.6}/.github/workflows/release.yml +0 -0
  26. {socketdev-3.0.4 → socketdev-3.0.6}/.github/workflows/version-check.yml +0 -0
  27. {socketdev-3.0.4 → socketdev-3.0.6}/.gitignore +0 -0
  28. {socketdev-3.0.4 → socketdev-3.0.6}/.hooks/sync_version.py +0 -0
  29. {socketdev-3.0.4 → socketdev-3.0.6}/.python-version +0 -0
  30. {socketdev-3.0.4 → socketdev-3.0.6}/LICENSE +0 -0
  31. {socketdev-3.0.4 → socketdev-3.0.6}/README.rst +0 -0
  32. {socketdev-3.0.4 → socketdev-3.0.6}/scripts/build.sh +0 -0
  33. {socketdev-3.0.4 → socketdev-3.0.6}/scripts/deploy-test-pypi.sh +0 -0
  34. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/__init__.py +0 -0
  35. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/alerttypes/__init__.py +0 -0
  36. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/analytics/__init__.py +0 -0
  37. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/core/api.py +0 -0
  38. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/core/classes.py +0 -0
  39. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/core/issues.py +0 -0
  40. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/exceptions.py +0 -0
  41. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/export/__init__.py +0 -0
  42. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/historical/__init__.py +0 -0
  43. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/labels/__init__.py +0 -0
  44. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/licensemetadata/__init__.py +0 -0
  45. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/log.py +0 -0
  46. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/npm/__init__.py +0 -0
  47. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/openapi/__init__.py +0 -0
  48. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/org/__init__.py +0 -0
  49. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/quota/__init__.py +0 -0
  50. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/repos/__init__.py +0 -0
  51. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/repositories/__init__.py +0 -0
  52. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/sbom/__init__.py +0 -0
  53. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/settings/__init__.py +0 -0
  54. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/threatfeed/__init__.py +0 -0
  55. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/tools/__init__.py +0 -0
  56. {socketdev-3.0.4 → socketdev-3.0.6}/socketdev/triage/__init__.py +0 -0
  57. {socketdev-3.0.4 → socketdev-3.0.6}/tests/README.md +0 -0
  58. {socketdev-3.0.4 → socketdev-3.0.6}/tests/conftest.py +0 -0
  59. {socketdev-3.0.4 → socketdev-3.0.6}/tests/integration/test_diffscans_integration.py +0 -0
  60. {socketdev-3.0.4 → socketdev-3.0.6}/tests/integration/test_new_endpoints.py +0 -0
  61. {socketdev-3.0.4 → socketdev-3.0.6}/tests/run_tests.py +0 -0
  62. {socketdev-3.0.4 → socketdev-3.0.6}/tests/unit/__init__.py +0 -0
  63. {socketdev-3.0.4 → socketdev-3.0.6}/tests/unit/test_socket_sdk_unit.py +0 -0
  64. {socketdev-3.0.4 → socketdev-3.0.6}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: socketdev
3
- Version: 3.0.4
3
+ Version: 3.0.6
4
4
  Summary: Socket Security Python SDK
5
5
  Project-URL: Homepage, https://github.com/socketdev/socketdev
6
6
  Author-email: Douglas Coburn <douglas@socket.dev>
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "socketdev"
7
- version = "3.0.4"
7
+ version = "3.0.6"
8
8
  requires-python = ">= 3.9"
9
9
  dependencies = [
10
10
  'requests',
@@ -28,20 +28,57 @@ class ApiTokens:
28
28
  log.error(response.text)
29
29
  return {}
30
30
 
31
- def update(self, org_slug: str, **kwargs) -> dict:
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
- path = f"orgs/{org_slug}/api-tokens/update"
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="POST", payload=payload)
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
- response = self.api.do_request(path=path, params=kwargs)
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
- if batched:
92
- grouped = Dedupe.consolidate_by_batch_index(packages)
93
- else:
94
- grouped = Dedupe.consolidate_by_order(packages)
95
- return [Dedupe.consolidate_and_merge_alerts(group) for group in grouped.values()]
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 consolidate_by_batch_index(packages: List[Dict[str, Any]]) -> dict[int, list[dict[str, Any]]]:
99
- grouped: Dict[int, List[Dict[str, Any]]] = defaultdict(list)
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
- grouped[pkg["batchIndex"]].append(pkg)
102
- return grouped
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 = False, workspace: str = None) -> dict:
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
- self,
35
- limit: int = 50,
36
- offset: int = 0,
37
- ) -> dict:
38
- path = "dependencies/search"
39
- payload = {"limit": limit, "offset": offset}
40
- payload_str = json.dumps(payload)
41
- response = self.api.do_request(path=path, method="POST", payload=payload_str)
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:
@@ -1,6 +1,6 @@
1
1
  import json
2
2
  import logging
3
- from typing import Any, Dict, Optional, Union
3
+ from typing import Any, Dict, List, Optional, Union
4
4
  from ..utils import Utils
5
5
 
6
6
  log = logging.getLogger("socketdev")
@@ -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, base_paths: list = None) -> dict:
34
34
  """
35
35
  Create a diff scan from repo HEAD, uploading files as multipart form data.
36
36
 
@@ -45,6 +45,8 @@ 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
49
+ base_paths: Optional list of base paths to strip from key names (takes precedence over base_path)
48
50
 
49
51
  Returns:
50
52
  dict: API response containing diff scan results
@@ -63,7 +65,7 @@ class DiffScans:
63
65
 
64
66
  # Use lazy loading if requested
65
67
  if use_lazy_loading:
66
- prepared_files = Utils.load_files_for_sending_lazy(files, workspace, max_open_files)
68
+ prepared_files = Utils.load_files_for_sending_lazy(files, workspace, max_open_files, base_path, base_paths)
67
69
  else:
68
70
  prepared_files = files
69
71
 
@@ -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
- params_arg = urllib.parse.urlencode(params)
705
- path = "orgs/" + org_slug + "/full-scans?" + str(params_arg)
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, base_paths: List[str] = None) -> Union[dict, CreateFullScanResponse]:
724
732
  """
725
733
  Create a new full scan by uploading manifest files.
726
734
 
@@ -734,6 +742,8 @@ 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
746
+ base_paths: Optional list of base paths to strip from key names (takes precedence over base_path)
737
747
 
738
748
  Returns:
739
749
  dict or CreateFullScanResponse: API response containing scan results
@@ -754,7 +764,7 @@ class FullScans:
754
764
 
755
765
  # Use lazy loading if requested
756
766
  if use_lazy_loading:
757
- prepared_files = Utils.load_files_for_sending_lazy(files, workspace, max_open_files)
767
+ prepared_files = Utils.load_files_for_sending_lazy(files, workspace, max_open_files, base_path, base_paths)
758
768
  else:
759
769
  prepared_files = files
760
770
 
@@ -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 name, path in files:
63
- file_info = (name, (name, open(path, "rb"), "text/plain"))
64
- open_files.append(file_info)
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 == 200:
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, base_paths: List[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,8 @@ 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
250
+ base_paths: Optional list of base paths to strip from key names (takes precedence over base_path)
249
251
 
250
252
  Returns:
251
253
  List of tuples formatted for requests multipart upload:
@@ -257,6 +259,10 @@ class Utils:
257
259
  send_files = []
258
260
  if workspace and "\\" in workspace:
259
261
  workspace = workspace.replace("\\", "/")
262
+ if base_path and "\\" in base_path:
263
+ base_path = base_path.replace("\\", "/")
264
+ if base_paths:
265
+ base_paths = [bp.replace("\\", "/") if "\\" in bp else bp for bp in base_paths]
260
266
 
261
267
  for file_path in files:
262
268
  # Normalize file path
@@ -265,14 +271,55 @@ class Utils:
265
271
 
266
272
  _, name = file_path.rsplit("/", 1)
267
273
 
268
- # Calculate the key (relative path from workspace)
269
- if workspace and file_path.startswith(workspace):
274
+ # Calculate the key name for the form data
275
+ key = file_path
276
+ path_stripped = False
277
+
278
+ # If base_paths is provided, try to strip one of the paths from the file path
279
+ if base_paths:
280
+ for bp in base_paths:
281
+ # Normalize base_path to ensure consistent handling of trailing slashes
282
+ normalized_base_path = bp.rstrip("/") + "/" if not bp.endswith("/") else bp
283
+ if key.startswith(normalized_base_path):
284
+ key = key[len(normalized_base_path):]
285
+ path_stripped = True
286
+ break
287
+ elif key.startswith(bp.rstrip("/")):
288
+ # Handle case where base_path matches exactly without trailing slash
289
+ stripped_base = bp.rstrip("/")
290
+ if key.startswith(stripped_base + "/") or key == stripped_base:
291
+ key = key[len(stripped_base):]
292
+ key = key.lstrip("/")
293
+ path_stripped = True
294
+ break
295
+
296
+ # If base_path is provided and no base_paths matched, use single base_path
297
+ elif base_path:
298
+ # Normalize base_path to ensure consistent handling of trailing slashes
299
+ normalized_base_path = base_path.rstrip("/") + "/" if not base_path.endswith("/") else base_path
300
+ if key.startswith(normalized_base_path):
301
+ key = key[len(normalized_base_path):]
302
+ path_stripped = True
303
+ elif key.startswith(base_path.rstrip("/")):
304
+ # Handle case where base_path matches exactly without trailing slash
305
+ stripped_base = base_path.rstrip("/")
306
+ if key.startswith(stripped_base + "/") or key == stripped_base:
307
+ key = key[len(stripped_base):]
308
+ key = key.lstrip("/")
309
+ path_stripped = True
310
+
311
+ # If workspace is provided and no base paths matched, fall back to workspace logic
312
+ if not path_stripped and workspace and file_path.startswith(workspace):
270
313
  key = file_path[len(workspace):]
271
- else:
272
- key = file_path
273
-
274
- key = key.lstrip("/")
275
- key = key.lstrip("./")
314
+ key = key.lstrip("/")
315
+ key = key.lstrip("./")
316
+ path_stripped = True
317
+
318
+ # If no path stripping occurred, clean up the key
319
+ if not path_stripped:
320
+ # No base_path, base_paths, or workspace stripping occurred, clean up leading parts
321
+ key = key.lstrip("/")
322
+ key = key.lstrip("./")
276
323
 
277
324
  # Create lazy file loader instead of opening file immediately
278
325
  # Use the relative path (key) as filename instead of truncated basename
@@ -0,0 +1 @@
1
+ __version__ = "3.0.6"
@@ -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
- result = self.sdk.dependencies.post([("file", ("package.json", open(f.name, "rb")))], {})
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)
@@ -152,7 +152,7 @@ class TestSocketSDKIntegration(unittest.TestCase):
152
152
  self.created_scan_ids.append(scan_id)
153
153
 
154
154
  # Get the scan
155
- scan_info = self.sdk.fullscans.get(self.org_slug, scan_id)
155
+ scan_info = self.sdk.fullscans.get(self.org_slug, {"id": scan_id})
156
156
  self.assertIsInstance(scan_info, dict)
157
157
 
158
158
  # List scans
@@ -52,9 +52,9 @@ class TestAllEndpointsUnit(unittest.TestCase):
52
52
  f.flush()
53
53
 
54
54
  try:
55
- with open(f.name, "rb") as file_obj:
56
- files = [("file", ("package.json", file_obj))]
57
- result = self.sdk.dependencies.post(files, {})
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/repos/test-repo/diff-scans", call_args[0][1])
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": "deleted"}, 200)
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/cdx", call_args[0][1])
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/spdx", call_args[0][1])
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 ID parameter
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("/orgs/test-org", call_args[0][1])
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
- expected_data = [{"purl": "pkg:npm/lodash@4.17.21", "valid": True}]
369
- self._mock_response(expected_data)
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("/reports", call_args[0][1])
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", "status": "queued"}
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], "POST")
422
- self.assertIn("/reports", call_args[0][1])
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("/reports/report-123", call_args[0][1])
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("/reports/report-123", call_args[0][1])
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("/reports/supported", call_args[0][1])
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 = {"updated": True, "alert_id": "alert-123"}
498
+ expected_data = {"result": "Updated"}
491
499
  self._mock_response(expected_data)
492
500
 
493
- data = {"alert_id": "alert-123", "status": "resolved"}
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], "PUT")
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("/threatfeed", call_args[0][1])
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], "GET")
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 = {"label": "production", "value": "true"}
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, "environment")
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/full-scans/1/labels/environment", call_args[0][1])
616
+ self.assertIn("/orgs/test-org/repos/labels/1", call_args[0][1])
609
617
 
610
- def test_labels_put_unit(self):
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/full-scans/1/labels", call_args[0][1])
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, "environment")
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/full-scans/1/labels/environment", call_args[0][1])
634
-
635
- def test_licensemetadata_get_unit(self):
636
- """Test license metadata retrieval."""
637
- expected_data = {"licenses": [{"id": "MIT", "name": "MIT License"}]}
638
- self._mock_response(expected_data)
639
-
640
- result = self.sdk.licensemetadata.get()
641
-
642
- self.assertEqual(result, expected_data)
643
- call_args = self.mock_requests.request.call_args
644
- self.assertEqual(call_args[0][0], "GET")
645
- self.assertIn("/license-metadata", call_args[0][1])
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()
@@ -346,15 +346,15 @@ class TestWorkingEndpointsUnit(unittest.TestCase):
346
346
  """Test fullscans get - CORRECTED PARAMETER HANDLING."""
347
347
  expected_data = {"id": "scan-123", "status": "completed"}
348
348
  self._mock_response(expected_data)
349
-
350
- # The actual API uses query parameters, not path parameters
349
+
350
+ # When getting a specific scan by ID, it uses path parameters
351
351
  result = self.sdk.fullscans.get("test-org", {"id": "scan-123"})
352
-
352
+
353
353
  self.assertEqual(result, expected_data)
354
354
  call_args = self.mock_requests.request.call_args
355
355
  self.assertEqual(call_args[0][0], "GET")
356
- # Path includes query params, not path segments
357
- self.assertIn("/orgs/test-org/full-scans?id=scan-123", call_args[0][1])
356
+ # Single ID param creates path segment, not query params
357
+ self.assertIn("/orgs/test-org/full-scans/scan-123", call_args[0][1])
358
358
 
359
359
  def test_diffscans_create_from_repo_corrected_unit(self):
360
360
  """Test diffscans creation from repo - CORRECTED PATH."""
@@ -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