socketdev 3.0.32__tar.gz → 3.1.0__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.32 → socketdev-3.1.0}/.github/workflows/pr-preview.yml +2 -1
- {socketdev-3.0.32 → socketdev-3.1.0}/.github/workflows/release.yml +6 -3
- {socketdev-3.0.32 → socketdev-3.1.0}/.github/workflows/version-check.yml +7 -1
- {socketdev-3.0.32 → socketdev-3.1.0}/.gitignore +4 -1
- {socketdev-3.0.32 → socketdev-3.1.0}/PKG-INFO +10 -6
- {socketdev-3.0.32 → socketdev-3.1.0}/README.rst +8 -4
- {socketdev-3.0.32 → socketdev-3.1.0}/pyproject.toml +2 -2
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/fullscans/__init__.py +10 -1
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/purl/__init__.py +16 -2
- socketdev-3.1.0/socketdev/version.py +1 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/tests/integration/test_all_endpoints.py +14 -10
- {socketdev-3.0.32 → socketdev-3.1.0}/tests/integration/test_comprehensive_integration.py +9 -5
- {socketdev-3.0.32 → socketdev-3.1.0}/tests/unit/test_all_endpoints_unit.py +32 -15
- socketdev-3.1.0/tests/unit/test_socket_alert_category.py +63 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/tests/unit/test_socket_sdk_unit.py +3 -3
- {socketdev-3.0.32 → socketdev-3.1.0}/tests/unit/test_working_endpoints_unit.py +4 -4
- {socketdev-3.0.32 → socketdev-3.1.0}/uv.lock +1 -1
- socketdev-3.0.32/socketdev/version.py +0 -1
- {socketdev-3.0.32 → socketdev-3.1.0}/.github/CODEOWNERS +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/.github/PULL_REQUEST_TEMPLATE/bug-fix.md +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/.github/PULL_REQUEST_TEMPLATE/feature.md +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/.github/PULL_REQUEST_TEMPLATE/improvement.md +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/.hooks/sync_version.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/.python-version +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/LICENSE +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/scripts/build.sh +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/scripts/deploy-test-pypi.sh +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/alertfullscansearch/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/alerts/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/alerttypes/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/analytics/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/apitokens/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/auditlog/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/basics/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/core/api.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/core/classes.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/core/dedupe.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/core/issues.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/dependencies/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/diffscans/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/exceptions.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/export/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/fixes/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/historical/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/labels/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/licensemetadata/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/log.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/npm/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/openapi/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/org/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/quota/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/report/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/repos/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/repositories/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/sbom/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/settings/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/supportedfiles/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/telemetry/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/threatfeed/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/tools/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/triage/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/uploadmanifests/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/utils/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/socketdev/webhooks/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/tests/README.md +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/tests/conftest.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/tests/integration/test_diffscans_integration.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/tests/integration/test_new_endpoints.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/tests/run_tests.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/tests/unit/__init__.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/tests/unit/test_dedupe.py +0 -0
- {socketdev-3.0.32 → socketdev-3.1.0}/tests/unit/test_upload_manifests.py +0 -0
|
@@ -11,9 +11,10 @@ jobs:
|
|
|
11
11
|
contents: read
|
|
12
12
|
pull-requests: write
|
|
13
13
|
steps:
|
|
14
|
-
- uses: actions/checkout@
|
|
14
|
+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
15
15
|
with:
|
|
16
16
|
fetch-depth: 0
|
|
17
|
+
persist-credentials: false
|
|
17
18
|
- uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3
|
|
18
19
|
with:
|
|
19
20
|
python-version: '3.13'
|
|
@@ -10,9 +10,10 @@ jobs:
|
|
|
10
10
|
id-token: write
|
|
11
11
|
contents: read
|
|
12
12
|
steps:
|
|
13
|
-
- uses: actions/checkout@
|
|
13
|
+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
14
14
|
with:
|
|
15
15
|
fetch-depth: 0
|
|
16
|
+
persist-credentials: false
|
|
16
17
|
- uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3
|
|
17
18
|
with:
|
|
18
19
|
python-version: '3.13'
|
|
@@ -27,11 +28,13 @@ jobs:
|
|
|
27
28
|
|
|
28
29
|
- name: Get Version
|
|
29
30
|
id: version
|
|
31
|
+
env:
|
|
32
|
+
REF_NAME: ${{ github.ref_name }}
|
|
30
33
|
run: |
|
|
31
34
|
RAW_VERSION=$(hatch version)
|
|
32
35
|
echo "VERSION=$RAW_VERSION" >> $GITHUB_ENV
|
|
33
|
-
if [ "v$RAW_VERSION" != "$
|
|
34
|
-
echo "Error: Git tag ($
|
|
36
|
+
if [ "v$RAW_VERSION" != "$REF_NAME" ]; then
|
|
37
|
+
echo "Error: Git tag ($REF_NAME) does not match hatch version (v$RAW_VERSION)"
|
|
35
38
|
exit 1
|
|
36
39
|
fi
|
|
37
40
|
|
|
@@ -7,13 +7,19 @@ on:
|
|
|
7
7
|
- 'setup.py'
|
|
8
8
|
- 'pyproject.toml'
|
|
9
9
|
|
|
10
|
+
permissions:
|
|
11
|
+
contents: read
|
|
12
|
+
pull-requests: write
|
|
13
|
+
issues: write
|
|
14
|
+
|
|
10
15
|
jobs:
|
|
11
16
|
check_version:
|
|
12
17
|
runs-on: ubuntu-latest
|
|
13
18
|
steps:
|
|
14
|
-
- uses: actions/checkout@
|
|
19
|
+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
15
20
|
with:
|
|
16
21
|
fetch-depth: 0 # Fetch all history for all branches
|
|
22
|
+
persist-credentials: false
|
|
17
23
|
|
|
18
24
|
- name: Check version increment
|
|
19
25
|
id: version_check
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: socketdev
|
|
3
|
-
Version: 3.0
|
|
3
|
+
Version: 3.1.0
|
|
4
4
|
Summary: Socket Security Python SDK
|
|
5
|
-
Project-URL: Homepage, https://github.com/
|
|
5
|
+
Project-URL: Homepage, https://github.com/SocketDev/socket-sdk-python
|
|
6
6
|
Author-email: Douglas Coburn <douglas@socket.dev>
|
|
7
7
|
Maintainer-email: Douglas Coburn <douglas@socket.dev>
|
|
8
8
|
License: MIT License
|
|
@@ -78,9 +78,11 @@ Supported Functions
|
|
|
78
78
|
-------------------
|
|
79
79
|
|
|
80
80
|
|
|
81
|
-
purl.post(license, components)
|
|
82
|
-
""""""""""""""""""""""""""""""
|
|
83
|
-
Retrieve
|
|
81
|
+
purl.post(license, components, org_slug=None)
|
|
82
|
+
"""""""""""""""""""""""""""""""""""""""""""""
|
|
83
|
+
Retrieve package information for one or more PURLs. Pass ``org_slug`` to use the
|
|
84
|
+
current org-scoped endpoint. Omitting ``org_slug`` keeps the legacy deprecated
|
|
85
|
+
endpoint for backwards compatibility.
|
|
84
86
|
|
|
85
87
|
**Usage:**
|
|
86
88
|
|
|
@@ -88,6 +90,7 @@ Retrieve the package information for a purl post
|
|
|
88
90
|
|
|
89
91
|
from socketdev import socketdev
|
|
90
92
|
socket = socketdev(token="REPLACE_ME")
|
|
93
|
+
org_slug = "your-org-slug"
|
|
91
94
|
license = "true"
|
|
92
95
|
components = [
|
|
93
96
|
{
|
|
@@ -97,12 +100,13 @@ Retrieve the package information for a purl post
|
|
|
97
100
|
"purl": "pkg:pypi/socketsecurity"
|
|
98
101
|
}
|
|
99
102
|
]
|
|
100
|
-
print(socket.purl.post(license, components))
|
|
103
|
+
print(socket.purl.post(license, components, org_slug=org_slug))
|
|
101
104
|
|
|
102
105
|
**PARAMETERS:**
|
|
103
106
|
|
|
104
107
|
- **license (str)** - The license parameter if enabled will show alerts and license information. If disabled will only show the basic package metadata and scores. Default is true
|
|
105
108
|
- **components (array{dict})** - The components list of packages urls
|
|
109
|
+
- **org_slug (str, optional)** - Organization slug for the supported org-scoped PURL endpoint. If omitted, the SDK uses the deprecated legacy endpoint for backwards compatibility.
|
|
106
110
|
|
|
107
111
|
export.cdx_bom(org_slug, id, query_params)
|
|
108
112
|
""""""""""""""""""""""""""""""""""""""""""
|
|
@@ -28,9 +28,11 @@ Supported Functions
|
|
|
28
28
|
-------------------
|
|
29
29
|
|
|
30
30
|
|
|
31
|
-
purl.post(license, components)
|
|
32
|
-
""""""""""""""""""""""""""""""
|
|
33
|
-
Retrieve
|
|
31
|
+
purl.post(license, components, org_slug=None)
|
|
32
|
+
"""""""""""""""""""""""""""""""""""""""""""""
|
|
33
|
+
Retrieve package information for one or more PURLs. Pass ``org_slug`` to use the
|
|
34
|
+
current org-scoped endpoint. Omitting ``org_slug`` keeps the legacy deprecated
|
|
35
|
+
endpoint for backwards compatibility.
|
|
34
36
|
|
|
35
37
|
**Usage:**
|
|
36
38
|
|
|
@@ -38,6 +40,7 @@ Retrieve the package information for a purl post
|
|
|
38
40
|
|
|
39
41
|
from socketdev import socketdev
|
|
40
42
|
socket = socketdev(token="REPLACE_ME")
|
|
43
|
+
org_slug = "your-org-slug"
|
|
41
44
|
license = "true"
|
|
42
45
|
components = [
|
|
43
46
|
{
|
|
@@ -47,12 +50,13 @@ Retrieve the package information for a purl post
|
|
|
47
50
|
"purl": "pkg:pypi/socketsecurity"
|
|
48
51
|
}
|
|
49
52
|
]
|
|
50
|
-
print(socket.purl.post(license, components))
|
|
53
|
+
print(socket.purl.post(license, components, org_slug=org_slug))
|
|
51
54
|
|
|
52
55
|
**PARAMETERS:**
|
|
53
56
|
|
|
54
57
|
- **license (str)** - The license parameter if enabled will show alerts and license information. If disabled will only show the basic package metadata and scores. Default is true
|
|
55
58
|
- **components (array{dict})** - The components list of packages urls
|
|
59
|
+
- **org_slug (str, optional)** - Organization slug for the supported org-scoped PURL endpoint. If omitted, the SDK uses the deprecated legacy endpoint for backwards compatibility.
|
|
56
60
|
|
|
57
61
|
export.cdx_bom(org_slug, id, query_params)
|
|
58
62
|
""""""""""""""""""""""""""""""""""""""""""
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "socketdev"
|
|
7
|
-
version = "3.0
|
|
7
|
+
version = "3.1.0"
|
|
8
8
|
requires-python = ">= 3.9"
|
|
9
9
|
dependencies = [
|
|
10
10
|
'requests',
|
|
@@ -50,7 +50,7 @@ test = [
|
|
|
50
50
|
]
|
|
51
51
|
|
|
52
52
|
[project.urls]
|
|
53
|
-
Homepage = "https://github.com/
|
|
53
|
+
Homepage = "https://github.com/SocketDev/socket-sdk-python"
|
|
54
54
|
|
|
55
55
|
[tool.ruff]
|
|
56
56
|
# Exclude a variety of commonly ignored directories.
|
|
@@ -443,11 +443,20 @@ class SocketAlert:
|
|
|
443
443
|
|
|
444
444
|
@classmethod
|
|
445
445
|
def from_dict(cls, data: dict) -> "SocketAlert":
|
|
446
|
+
try:
|
|
447
|
+
category = SocketCategory(data["category"])
|
|
448
|
+
except ValueError:
|
|
449
|
+
log.warning(
|
|
450
|
+
"Unknown SocketCategory %r; falling back to MISCELLANEOUS. "
|
|
451
|
+
"Upgrade socketdev to pick up newer categories.",
|
|
452
|
+
data["category"],
|
|
453
|
+
)
|
|
454
|
+
category = SocketCategory.MISCELLANEOUS
|
|
446
455
|
return cls(
|
|
447
456
|
key=data["key"],
|
|
448
457
|
type=data["type"],
|
|
449
458
|
severity=SocketIssueSeverity(data["severity"]),
|
|
450
|
-
category=
|
|
459
|
+
category=category,
|
|
451
460
|
file=data.get("file"),
|
|
452
461
|
start=data.get("start"),
|
|
453
462
|
end=data.get("end"),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import json
|
|
2
2
|
import urllib.parse
|
|
3
|
+
import warnings
|
|
3
4
|
from socketdev.log import log
|
|
4
5
|
from ..core.dedupe import Dedupe
|
|
5
6
|
|
|
@@ -8,8 +9,21 @@ class Purl:
|
|
|
8
9
|
def __init__(self, api):
|
|
9
10
|
self.api = api
|
|
10
11
|
|
|
11
|
-
def post(
|
|
12
|
-
|
|
12
|
+
def post(
|
|
13
|
+
self,
|
|
14
|
+
license: str = "false",
|
|
15
|
+
components: list = None,
|
|
16
|
+
org_slug: str = None,
|
|
17
|
+
**kwargs,
|
|
18
|
+
) -> list:
|
|
19
|
+
if org_slug is None:
|
|
20
|
+
warnings.warn(
|
|
21
|
+
"Calling purl.post() without org_slug uses the deprecated POST /v0/purl endpoint. "
|
|
22
|
+
"Pass org_slug to migrate to POST /v0/orgs/{org_slug}/purl.",
|
|
23
|
+
DeprecationWarning,
|
|
24
|
+
stacklevel=2,
|
|
25
|
+
)
|
|
26
|
+
path = f"orgs/{org_slug}/purl?" if org_slug else "purl?"
|
|
13
27
|
if components is None:
|
|
14
28
|
components = []
|
|
15
29
|
purls = {"components": components}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "3.1.0"
|
|
@@ -181,13 +181,13 @@ class TestAllEndpointsMocked(unittest.TestCase):
|
|
|
181
181
|
def test_npm_issues_mocked(self):
|
|
182
182
|
"""Test npm issues endpoint."""
|
|
183
183
|
self._mock_success_response([{"type": "security", "severity": "high"}])
|
|
184
|
-
result = self.sdk.npm.issues("lodash", "4.
|
|
184
|
+
result = self.sdk.npm.issues("lodash", "4.18.1")
|
|
185
185
|
self.assertIsInstance(result, list)
|
|
186
186
|
|
|
187
187
|
def test_npm_score_mocked(self):
|
|
188
188
|
"""Test npm score endpoint."""
|
|
189
189
|
self._mock_success_response([{"category": "security", "value": 85}])
|
|
190
|
-
result = self.sdk.npm.score("lodash", "4.
|
|
190
|
+
result = self.sdk.npm.score("lodash", "4.18.1")
|
|
191
191
|
self.assertIsInstance(result, list)
|
|
192
192
|
|
|
193
193
|
# OpenAPI endpoints
|
|
@@ -206,9 +206,13 @@ class TestAllEndpointsMocked(unittest.TestCase):
|
|
|
206
206
|
|
|
207
207
|
# PURL endpoints
|
|
208
208
|
def test_purl_post_mocked(self):
|
|
209
|
-
"""Test purl post endpoint."""
|
|
210
|
-
|
|
211
|
-
|
|
209
|
+
"""Test org-scoped purl post endpoint."""
|
|
210
|
+
mock_response = Mock()
|
|
211
|
+
mock_response.status_code = 200
|
|
212
|
+
mock_response.headers = {'content-type': 'application/x-ndjson'}
|
|
213
|
+
mock_response.text = '{"inputPurl": "pkg:npm/lodash@4.18.1", "purl": "pkg:npm/lodash@4.18.1", "type": "npm", "name": "lodash", "version": "4.18.1", "valid": true, "alerts": []}'
|
|
214
|
+
self.mock_requests.request.return_value = mock_response
|
|
215
|
+
result = self.sdk.purl.post("false", [{"purl": "pkg:npm/lodash@4.18.1"}], org_slug="test-org")
|
|
212
216
|
self.assertIsInstance(result, list)
|
|
213
217
|
|
|
214
218
|
# Quota endpoints
|
|
@@ -372,7 +376,7 @@ class TestAllEndpointsIntegration(unittest.TestCase):
|
|
|
372
376
|
test_package = {
|
|
373
377
|
"name": "test-integration-package",
|
|
374
378
|
"version": "1.0.0",
|
|
375
|
-
"dependencies": {"lodash": "4.
|
|
379
|
+
"dependencies": {"lodash": "4.18.1"}
|
|
376
380
|
}
|
|
377
381
|
with open(cls.package_json_path, 'w') as f:
|
|
378
382
|
json.dump(test_package, f, indent=2)
|
|
@@ -414,20 +418,20 @@ class TestAllEndpointsIntegration(unittest.TestCase):
|
|
|
414
418
|
# NPM endpoints (should work for public packages)
|
|
415
419
|
def test_npm_issues_integration(self):
|
|
416
420
|
"""Test npm issues endpoint."""
|
|
417
|
-
result = self._try_endpoint(self.sdk.npm.issues, "lodash", "4.
|
|
421
|
+
result = self._try_endpoint(self.sdk.npm.issues, "lodash", "4.18.1")
|
|
418
422
|
if result:
|
|
419
423
|
self.assertIsInstance(result, list)
|
|
420
424
|
|
|
421
425
|
def test_npm_score_integration(self):
|
|
422
426
|
"""Test npm score endpoint."""
|
|
423
|
-
result = self._try_endpoint(self.sdk.npm.score, "lodash", "4.
|
|
427
|
+
result = self._try_endpoint(self.sdk.npm.score, "lodash", "4.18.1")
|
|
424
428
|
if result:
|
|
425
429
|
self.assertIsInstance(result, list)
|
|
426
430
|
|
|
427
431
|
# PURL endpoints
|
|
428
432
|
def test_purl_post_integration(self):
|
|
429
433
|
"""Test purl post endpoint."""
|
|
430
|
-
components = [{"purl": "pkg:npm/lodash@4.
|
|
434
|
+
components = [{"purl": "pkg:npm/lodash@4.18.1"}]
|
|
431
435
|
result = self._try_endpoint(self.sdk.purl.post, "false", components)
|
|
432
436
|
if result:
|
|
433
437
|
self.assertIsInstance(result, list)
|
|
@@ -515,7 +519,7 @@ class TestAllEndpointsIntegration(unittest.TestCase):
|
|
|
515
519
|
"""Test dependencies get endpoint."""
|
|
516
520
|
result = self._try_endpoint(
|
|
517
521
|
self.sdk.dependencies.get,
|
|
518
|
-
self.org_slug, "npm", "lodash", "4.
|
|
522
|
+
self.org_slug, "npm", "lodash", "4.18.1"
|
|
519
523
|
)
|
|
520
524
|
if result:
|
|
521
525
|
self.assertIsInstance(result, dict)
|
|
@@ -53,7 +53,7 @@ class TestSocketSDKIntegration(unittest.TestCase):
|
|
|
53
53
|
"name": "test-integration-project",
|
|
54
54
|
"version": "1.0.0",
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"lodash": "4.
|
|
56
|
+
"lodash": "4.18.1"
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
@@ -264,7 +264,7 @@ class TestSocketSDKIntegration(unittest.TestCase):
|
|
|
264
264
|
"""Test NPM-related endpoints."""
|
|
265
265
|
# Test getting package issues - this should work for most packages
|
|
266
266
|
try:
|
|
267
|
-
issues = self.sdk.npm.issues("lodash", "4.
|
|
267
|
+
issues = self.sdk.npm.issues("lodash", "4.18.1")
|
|
268
268
|
self.assertIsInstance(issues, dict)
|
|
269
269
|
except Exception as e:
|
|
270
270
|
print(f"NPM issues endpoint not available: {e}")
|
|
@@ -281,9 +281,13 @@ class TestSocketSDKIntegration(unittest.TestCase):
|
|
|
281
281
|
"""Test PURL (Package URL) functionality."""
|
|
282
282
|
try:
|
|
283
283
|
# Test with a common npm package
|
|
284
|
-
purl = "pkg:npm/lodash@4.
|
|
285
|
-
result = self.sdk.purl.post(
|
|
286
|
-
|
|
284
|
+
purl = "pkg:npm/lodash@4.18.1"
|
|
285
|
+
result = self.sdk.purl.post(
|
|
286
|
+
license="false",
|
|
287
|
+
components=[{"purl": purl}],
|
|
288
|
+
org_slug=self.org_slug,
|
|
289
|
+
)
|
|
290
|
+
self.assertIsInstance(result, list)
|
|
287
291
|
except Exception as e:
|
|
288
292
|
print(f"PURL endpoint not available: {e}")
|
|
289
293
|
|
|
@@ -44,11 +44,11 @@ class TestAllEndpointsUnit(unittest.TestCase):
|
|
|
44
44
|
# Dependencies endpoints
|
|
45
45
|
def test_dependencies_post_unit(self):
|
|
46
46
|
"""Test dependencies post with proper file handling."""
|
|
47
|
-
expected_data = {"packages": [{"name": "lodash", "version": "4.
|
|
47
|
+
expected_data = {"packages": [{"name": "lodash", "version": "4.18.1"}]}
|
|
48
48
|
self._mock_response(expected_data)
|
|
49
49
|
|
|
50
50
|
with tempfile.NamedTemporaryFile(mode='w', suffix='.json', delete=False) as f:
|
|
51
|
-
json.dump({"name": "test-package", "dependencies": {"lodash": "4.
|
|
51
|
+
json.dump({"name": "test-package", "dependencies": {"lodash": "4.18.1"}}, f)
|
|
52
52
|
f.flush()
|
|
53
53
|
|
|
54
54
|
try:
|
|
@@ -72,12 +72,12 @@ class TestAllEndpointsUnit(unittest.TestCase):
|
|
|
72
72
|
expected_data = {"dependencies": [{"name": "sub-dependency", "version": "1.0.0"}]}
|
|
73
73
|
self._mock_response(expected_data)
|
|
74
74
|
|
|
75
|
-
result = self.sdk.dependencies.get("test-org", "npm", "lodash", "4.
|
|
75
|
+
result = self.sdk.dependencies.get("test-org", "npm", "lodash", "4.18.1")
|
|
76
76
|
|
|
77
77
|
self.assertEqual(result, expected_data)
|
|
78
78
|
call_args = self.mock_requests.request.call_args
|
|
79
79
|
self.assertEqual(call_args[0][0], "GET")
|
|
80
|
-
self.assertIn("/orgs/test-org/dependencies/npm/lodash/4.
|
|
80
|
+
self.assertIn("/orgs/test-org/dependencies/npm/lodash/4.18.1", call_args[0][1])
|
|
81
81
|
|
|
82
82
|
# DiffScans endpoints
|
|
83
83
|
def test_diffscans_list_unit(self):
|
|
@@ -305,24 +305,24 @@ class TestAllEndpointsUnit(unittest.TestCase):
|
|
|
305
305
|
expected_data = [{"type": "security", "severity": "high", "title": "Test issue"}]
|
|
306
306
|
self._mock_response(expected_data)
|
|
307
307
|
|
|
308
|
-
result = self.sdk.npm.issues("lodash", "4.
|
|
308
|
+
result = self.sdk.npm.issues("lodash", "4.18.1")
|
|
309
309
|
|
|
310
310
|
self.assertEqual(result, expected_data)
|
|
311
311
|
call_args = self.mock_requests.request.call_args
|
|
312
312
|
self.assertEqual(call_args[0][0], "GET")
|
|
313
|
-
self.assertIn("/npm/lodash/4.
|
|
313
|
+
self.assertIn("/npm/lodash/4.18.1/issues", call_args[0][1])
|
|
314
314
|
|
|
315
315
|
def test_npm_score_unit(self):
|
|
316
316
|
"""Test npm score endpoint."""
|
|
317
317
|
expected_data = [{"category": "security", "value": 85}]
|
|
318
318
|
self._mock_response(expected_data)
|
|
319
319
|
|
|
320
|
-
result = self.sdk.npm.score("lodash", "4.
|
|
320
|
+
result = self.sdk.npm.score("lodash", "4.18.1")
|
|
321
321
|
|
|
322
322
|
self.assertEqual(result, expected_data)
|
|
323
323
|
call_args = self.mock_requests.request.call_args
|
|
324
324
|
self.assertEqual(call_args[0][0], "GET")
|
|
325
|
-
self.assertIn("/npm/lodash/4.
|
|
325
|
+
self.assertIn("/npm/lodash/4.18.1/score", call_args[0][1])
|
|
326
326
|
|
|
327
327
|
# OpenAPI endpoints
|
|
328
328
|
def test_openapi_get_unit(self):
|
|
@@ -352,14 +352,14 @@ class TestAllEndpointsUnit(unittest.TestCase):
|
|
|
352
352
|
|
|
353
353
|
# PURL endpoints
|
|
354
354
|
def test_purl_post_unit(self):
|
|
355
|
-
"""Test PURL validation endpoint."""
|
|
355
|
+
"""Test org-scoped PURL validation endpoint."""
|
|
356
356
|
# Expected final result after deduplication - should match what the dedupe function produces
|
|
357
357
|
expected_data = [{
|
|
358
|
-
"inputPurl": "pkg:npm/lodash@4.
|
|
359
|
-
"purl": "pkg:npm/lodash@4.
|
|
358
|
+
"inputPurl": "pkg:npm/lodash@4.18.1",
|
|
359
|
+
"purl": "pkg:npm/lodash@4.18.1",
|
|
360
360
|
"type": "npm",
|
|
361
361
|
"name": "lodash",
|
|
362
|
-
"version": "4.
|
|
362
|
+
"version": "4.18.1",
|
|
363
363
|
"valid": True,
|
|
364
364
|
"alerts": [],
|
|
365
365
|
"releases": ["npm"]
|
|
@@ -367,7 +367,7 @@ class TestAllEndpointsUnit(unittest.TestCase):
|
|
|
367
367
|
|
|
368
368
|
# Mock the NDJSON response that would come from the actual API
|
|
369
369
|
# This simulates what the API returns: newline-delimited JSON with SocketArtifact objects
|
|
370
|
-
mock_ndjson_response = '{"inputPurl": "pkg:npm/lodash@4.
|
|
370
|
+
mock_ndjson_response = '{"inputPurl": "pkg:npm/lodash@4.18.1", "purl": "pkg:npm/lodash@4.18.1", "type": "npm", "name": "lodash", "version": "4.18.1", "valid": true, "alerts": []}'
|
|
371
371
|
|
|
372
372
|
# Mock the response with NDJSON format
|
|
373
373
|
mock_response = Mock()
|
|
@@ -376,13 +376,30 @@ class TestAllEndpointsUnit(unittest.TestCase):
|
|
|
376
376
|
mock_response.text = mock_ndjson_response
|
|
377
377
|
self.mock_requests.request.return_value = mock_response
|
|
378
378
|
|
|
379
|
-
components = [{"purl": "pkg:npm/lodash@4.
|
|
380
|
-
result = self.sdk.purl.post("false", components)
|
|
379
|
+
components = [{"purl": "pkg:npm/lodash@4.18.1"}]
|
|
380
|
+
result = self.sdk.purl.post("false", components, org_slug="test-org")
|
|
381
381
|
|
|
382
382
|
self.assertEqual(result, expected_data)
|
|
383
|
+
call_args = self.mock_requests.request.call_args
|
|
384
|
+
self.assertEqual(call_args[0][0], "POST")
|
|
385
|
+
self.assertIn("/orgs/test-org/purl", call_args[0][1])
|
|
386
|
+
|
|
387
|
+
def test_purl_post_unit_legacy_path(self):
|
|
388
|
+
"""Test legacy PURL validation endpoint remains available for compatibility."""
|
|
389
|
+
mock_ndjson_response = '{"inputPurl": "pkg:npm/lodash@4.18.1", "purl": "pkg:npm/lodash@4.18.1", "type": "npm", "name": "lodash", "version": "4.18.1", "valid": true, "alerts": []}'
|
|
390
|
+
|
|
391
|
+
mock_response = Mock()
|
|
392
|
+
mock_response.status_code = 200
|
|
393
|
+
mock_response.headers = {'content-type': 'application/x-ndjson'}
|
|
394
|
+
mock_response.text = mock_ndjson_response
|
|
395
|
+
self.mock_requests.request.return_value = mock_response
|
|
396
|
+
|
|
397
|
+
self.sdk.purl.post("false", [{"purl": "pkg:npm/lodash@4.18.1"}])
|
|
398
|
+
|
|
383
399
|
call_args = self.mock_requests.request.call_args
|
|
384
400
|
self.assertEqual(call_args[0][0], "POST")
|
|
385
401
|
self.assertIn("/purl", call_args[0][1])
|
|
402
|
+
self.assertNotIn("/orgs/", call_args[0][1])
|
|
386
403
|
|
|
387
404
|
# Quota endpoints
|
|
388
405
|
def test_quota_get_unit(self):
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Unit tests for lenient SocketCategory parsing in SocketAlert.from_dict.
|
|
3
|
+
|
|
4
|
+
Regression coverage for
|
|
5
|
+
https://github.com/SocketDev/socket-sdk-python/issues/78: the Socket API can
|
|
6
|
+
emit category values the SDK does not yet know about (e.g. ``"other"``). Strict
|
|
7
|
+
enum parsing turned that into a hard failure that took down every consumer
|
|
8
|
+
(notably socketsecurity CI runs) whenever a diff included one of those alerts.
|
|
9
|
+
|
|
10
|
+
These tests pin the fallback behavior so the SDK stays forward-compatible with
|
|
11
|
+
new server-side categories.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import logging
|
|
15
|
+
import unittest
|
|
16
|
+
|
|
17
|
+
from socketdev.fullscans import SocketAlert, SocketCategory, SocketIssueSeverity
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class TestSocketAlertCategoryParsing(unittest.TestCase):
|
|
21
|
+
"""SocketAlert.from_dict should tolerate unknown category values."""
|
|
22
|
+
|
|
23
|
+
def _base_payload(self, category: str) -> dict:
|
|
24
|
+
return {
|
|
25
|
+
"key": "alert-key",
|
|
26
|
+
"type": "someAlertType",
|
|
27
|
+
"severity": "low",
|
|
28
|
+
"category": category,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
def test_known_category_is_preserved(self):
|
|
32
|
+
alert = SocketAlert.from_dict(self._base_payload("supplyChainRisk"))
|
|
33
|
+
self.assertEqual(alert.category, SocketCategory.SUPPLY_CHAIN_RISK)
|
|
34
|
+
self.assertEqual(alert.severity, SocketIssueSeverity.LOW)
|
|
35
|
+
|
|
36
|
+
def test_unknown_category_falls_back_to_miscellaneous(self):
|
|
37
|
+
alert = SocketAlert.from_dict(self._base_payload("other"))
|
|
38
|
+
self.assertEqual(alert.category, SocketCategory.MISCELLANEOUS)
|
|
39
|
+
|
|
40
|
+
def test_unknown_category_does_not_raise(self):
|
|
41
|
+
# Explicit regression assertion: no ValueError for brand-new categories.
|
|
42
|
+
try:
|
|
43
|
+
SocketAlert.from_dict(self._base_payload("somethingCompletelyNew"))
|
|
44
|
+
except ValueError as exc:
|
|
45
|
+
self.fail(f"SocketAlert.from_dict raised ValueError for unknown category: {exc}")
|
|
46
|
+
|
|
47
|
+
def test_unknown_category_emits_warning(self):
|
|
48
|
+
with self.assertLogs("socketdev", level=logging.WARNING) as captured:
|
|
49
|
+
SocketAlert.from_dict(self._base_payload("other"))
|
|
50
|
+
self.assertTrue(
|
|
51
|
+
any("Unknown SocketCategory" in message for message in captured.output),
|
|
52
|
+
f"expected a warning about the unknown category, got: {captured.output}",
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
def test_every_known_category_round_trips(self):
|
|
56
|
+
for category in SocketCategory:
|
|
57
|
+
with self.subTest(category=category):
|
|
58
|
+
alert = SocketAlert.from_dict(self._base_payload(category.value))
|
|
59
|
+
self.assertEqual(alert.category, category)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
if __name__ == "__main__":
|
|
63
|
+
unittest.main()
|
|
@@ -110,13 +110,13 @@ class TestSocketSDKUnit(unittest.TestCase):
|
|
|
110
110
|
type=SocketPURL_Type.NPM,
|
|
111
111
|
name="lodash",
|
|
112
112
|
namespace=None,
|
|
113
|
-
release="4.
|
|
113
|
+
release="4.18.1"
|
|
114
114
|
)
|
|
115
115
|
|
|
116
116
|
self.assertEqual(purl.type, SocketPURL_Type.NPM)
|
|
117
117
|
self.assertEqual(purl.name, "lodash")
|
|
118
118
|
self.assertIsNone(purl.namespace)
|
|
119
|
-
self.assertEqual(purl.release, "4.
|
|
119
|
+
self.assertEqual(purl.release, "4.18.1")
|
|
120
120
|
|
|
121
121
|
def test_integration_types(self):
|
|
122
122
|
"""Test that all integration types are available."""
|
|
@@ -223,7 +223,7 @@ class TestSocketSDKFileHandling(unittest.TestCase):
|
|
|
223
223
|
"name": "test-package",
|
|
224
224
|
"version": "1.0.0",
|
|
225
225
|
"dependencies": {
|
|
226
|
-
"lodash": "4.
|
|
226
|
+
"lodash": "4.18.1"
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
229
|
|
|
@@ -50,24 +50,24 @@ class TestWorkingEndpointsUnit(unittest.TestCase):
|
|
|
50
50
|
expected_data = [{"type": "security", "severity": "high"}]
|
|
51
51
|
self._mock_response(expected_data)
|
|
52
52
|
|
|
53
|
-
result = self.sdk.npm.issues("lodash", "4.
|
|
53
|
+
result = self.sdk.npm.issues("lodash", "4.18.1")
|
|
54
54
|
|
|
55
55
|
self.assertEqual(result, expected_data)
|
|
56
56
|
call_args = self.mock_requests.request.call_args
|
|
57
57
|
self.assertEqual(call_args[0][0], "GET")
|
|
58
|
-
self.assertIn("/npm/lodash/4.
|
|
58
|
+
self.assertIn("/npm/lodash/4.18.1/issues", call_args[0][1])
|
|
59
59
|
|
|
60
60
|
def test_npm_score_unit(self):
|
|
61
61
|
"""Test NPM score endpoint - WORKING."""
|
|
62
62
|
expected_data = [{"category": "security", "value": 85}]
|
|
63
63
|
self._mock_response(expected_data)
|
|
64
64
|
|
|
65
|
-
result = self.sdk.npm.score("lodash", "4.
|
|
65
|
+
result = self.sdk.npm.score("lodash", "4.18.1")
|
|
66
66
|
|
|
67
67
|
self.assertEqual(result, expected_data)
|
|
68
68
|
call_args = self.mock_requests.request.call_args
|
|
69
69
|
self.assertEqual(call_args[0][0], "GET")
|
|
70
|
-
self.assertIn("/npm/lodash/4.
|
|
70
|
+
self.assertIn("/npm/lodash/4.18.1/score", call_args[0][1])
|
|
71
71
|
|
|
72
72
|
def test_openapi_get_unit(self):
|
|
73
73
|
"""Test OpenAPI specification retrieval - WORKING."""
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "3.0.32"
|
|
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
|