Skip to content

Commit 8289bd6

Browse files
committed
Add org-scoped + legacy endpoint test coverage, bump lodash placeholders
Signed-off-by: lelia <2418071+lelia@users.noreply.github.com>
1 parent 8ff3a17 commit 8289bd6

5 files changed

Lines changed: 62 additions & 37 deletions

File tree

tests/integration/test_all_endpoints.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,13 @@ def test_historical_trend_mocked(self):
181181
def test_npm_issues_mocked(self):
182182
"""Test npm issues endpoint."""
183183
self._mock_success_response([{"type": "security", "severity": "high"}])
184-
result = self.sdk.npm.issues("lodash", "4.17.21")
184+
result = self.sdk.npm.issues("lodash", "4.18.1")
185185
self.assertIsInstance(result, list)
186186

187187
def test_npm_score_mocked(self):
188188
"""Test npm score endpoint."""
189189
self._mock_success_response([{"category": "security", "value": 85}])
190-
result = self.sdk.npm.score("lodash", "4.17.21")
190+
result = self.sdk.npm.score("lodash", "4.18.1")
191191
self.assertIsInstance(result, list)
192192

193193
# OpenAPI endpoints
@@ -206,9 +206,13 @@ def test_org_get_mocked(self):
206206

207207
# PURL endpoints
208208
def test_purl_post_mocked(self):
209-
"""Test purl post endpoint."""
210-
self._mock_success_response([{"purl": "pkg:npm/lodash@4.17.21", "valid": True}])
211-
result = self.sdk.purl.post("false", [{"purl": "pkg:npm/lodash@4.17.21"}])
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")
212216
self.assertIsInstance(result, list)
213217

214218
# Quota endpoints
@@ -372,7 +376,7 @@ def setUpClass(cls):
372376
test_package = {
373377
"name": "test-integration-package",
374378
"version": "1.0.0",
375-
"dependencies": {"lodash": "4.17.21"}
379+
"dependencies": {"lodash": "4.18.1"}
376380
}
377381
with open(cls.package_json_path, 'w') as f:
378382
json.dump(test_package, f, indent=2)
@@ -414,20 +418,20 @@ def test_openapi_get_integration(self):
414418
# NPM endpoints (should work for public packages)
415419
def test_npm_issues_integration(self):
416420
"""Test npm issues endpoint."""
417-
result = self._try_endpoint(self.sdk.npm.issues, "lodash", "4.17.21")
421+
result = self._try_endpoint(self.sdk.npm.issues, "lodash", "4.18.1")
418422
if result:
419423
self.assertIsInstance(result, list)
420424

421425
def test_npm_score_integration(self):
422426
"""Test npm score endpoint."""
423-
result = self._try_endpoint(self.sdk.npm.score, "lodash", "4.17.21")
427+
result = self._try_endpoint(self.sdk.npm.score, "lodash", "4.18.1")
424428
if result:
425429
self.assertIsInstance(result, list)
426430

427431
# PURL endpoints
428432
def test_purl_post_integration(self):
429433
"""Test purl post endpoint."""
430-
components = [{"purl": "pkg:npm/lodash@4.17.21"}]
434+
components = [{"purl": "pkg:npm/lodash@4.18.1"}]
431435
result = self._try_endpoint(self.sdk.purl.post, "false", components)
432436
if result:
433437
self.assertIsInstance(result, list)
@@ -515,7 +519,7 @@ def test_dependencies_get_integration(self):
515519
"""Test dependencies get endpoint."""
516520
result = self._try_endpoint(
517521
self.sdk.dependencies.get,
518-
self.org_slug, "npm", "lodash", "4.17.21"
522+
self.org_slug, "npm", "lodash", "4.18.1"
519523
)
520524
if result:
521525
self.assertIsInstance(result, dict)

tests/integration/test_comprehensive_integration.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def setUpClass(cls):
5353
"name": "test-integration-project",
5454
"version": "1.0.0",
5555
"dependencies": {
56-
"lodash": "4.17.21"
56+
"lodash": "4.18.1"
5757
}
5858
}
5959

@@ -264,7 +264,7 @@ def test_npm_endpoints(self):
264264
"""Test NPM-related endpoints."""
265265
# Test getting package issues - this should work for most packages
266266
try:
267-
issues = self.sdk.npm.issues("lodash", "4.17.21")
267+
issues = self.sdk.npm.issues("lodash", "4.18.1")
268268
self.assertIsInstance(issues, dict)
269269
except Exception as e:
270270
print(f"NPM issues endpoint not available: {e}")
@@ -281,9 +281,13 @@ def test_purl_endpoint(self):
281281
"""Test PURL (Package URL) functionality."""
282282
try:
283283
# Test with a common npm package
284-
purl = "pkg:npm/lodash@4.17.21"
285-
result = self.sdk.purl.post([purl])
286-
self.assertIsInstance(result, dict)
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)
287291
except Exception as e:
288292
print(f"PURL endpoint not available: {e}")
289293

tests/unit/test_all_endpoints_unit.py

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ def _mock_response(self, data=None, status_code=200):
4444
# Dependencies endpoints
4545
def test_dependencies_post_unit(self):
4646
"""Test dependencies post with proper file handling."""
47-
expected_data = {"packages": [{"name": "lodash", "version": "4.17.21"}]}
47+
expected_data = {"packages": [{"name": "lodash", "version": "4.18.1"}]}
4848
self._mock_response(expected_data)
4949

5050
with tempfile.NamedTemporaryFile(mode='w', suffix='.json', delete=False) as f:
51-
json.dump({"name": "test-package", "dependencies": {"lodash": "4.17.21"}}, f)
51+
json.dump({"name": "test-package", "dependencies": {"lodash": "4.18.1"}}, f)
5252
f.flush()
5353

5454
try:
@@ -72,12 +72,12 @@ def test_dependencies_get_unit(self):
7272
expected_data = {"dependencies": [{"name": "sub-dependency", "version": "1.0.0"}]}
7373
self._mock_response(expected_data)
7474

75-
result = self.sdk.dependencies.get("test-org", "npm", "lodash", "4.17.21")
75+
result = self.sdk.dependencies.get("test-org", "npm", "lodash", "4.18.1")
7676

7777
self.assertEqual(result, expected_data)
7878
call_args = self.mock_requests.request.call_args
7979
self.assertEqual(call_args[0][0], "GET")
80-
self.assertIn("/orgs/test-org/dependencies/npm/lodash/4.17.21", call_args[0][1])
80+
self.assertIn("/orgs/test-org/dependencies/npm/lodash/4.18.1", call_args[0][1])
8181

8282
# DiffScans endpoints
8383
def test_diffscans_list_unit(self):
@@ -305,24 +305,24 @@ def test_npm_issues_unit(self):
305305
expected_data = [{"type": "security", "severity": "high", "title": "Test issue"}]
306306
self._mock_response(expected_data)
307307

308-
result = self.sdk.npm.issues("lodash", "4.17.21")
308+
result = self.sdk.npm.issues("lodash", "4.18.1")
309309

310310
self.assertEqual(result, expected_data)
311311
call_args = self.mock_requests.request.call_args
312312
self.assertEqual(call_args[0][0], "GET")
313-
self.assertIn("/npm/lodash/4.17.21/issues", call_args[0][1])
313+
self.assertIn("/npm/lodash/4.18.1/issues", call_args[0][1])
314314

315315
def test_npm_score_unit(self):
316316
"""Test npm score endpoint."""
317317
expected_data = [{"category": "security", "value": 85}]
318318
self._mock_response(expected_data)
319319

320-
result = self.sdk.npm.score("lodash", "4.17.21")
320+
result = self.sdk.npm.score("lodash", "4.18.1")
321321

322322
self.assertEqual(result, expected_data)
323323
call_args = self.mock_requests.request.call_args
324324
self.assertEqual(call_args[0][0], "GET")
325-
self.assertIn("/npm/lodash/4.17.21/score", call_args[0][1])
325+
self.assertIn("/npm/lodash/4.18.1/score", call_args[0][1])
326326

327327
# OpenAPI endpoints
328328
def test_openapi_get_unit(self):
@@ -352,22 +352,22 @@ def test_org_get_unit(self):
352352

353353
# PURL endpoints
354354
def test_purl_post_unit(self):
355-
"""Test PURL validation endpoint."""
355+
"""Test org-scoped PURL validation endpoint."""
356356
# Expected final result after deduplication - should match what the dedupe function produces
357357
expected_data = [{
358-
"inputPurl": "pkg:npm/lodash@4.17.21",
359-
"purl": "pkg:npm/lodash@4.17.21",
358+
"inputPurl": "pkg:npm/lodash@4.18.1",
359+
"purl": "pkg:npm/lodash@4.18.1",
360360
"type": "npm",
361361
"name": "lodash",
362-
"version": "4.17.21",
362+
"version": "4.18.1",
363363
"valid": True,
364364
"alerts": [],
365365
"releases": ["npm"]
366366
}]
367367

368368
# Mock the NDJSON response that would come from the actual API
369369
# 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": []}'
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": []}'
371371

372372
# Mock the response with NDJSON format
373373
mock_response = Mock()
@@ -376,13 +376,30 @@ def test_purl_post_unit(self):
376376
mock_response.text = mock_ndjson_response
377377
self.mock_requests.request.return_value = mock_response
378378

379-
components = [{"purl": "pkg:npm/lodash@4.17.21"}]
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")
381381

382382
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+
383399
call_args = self.mock_requests.request.call_args
384400
self.assertEqual(call_args[0][0], "POST")
385401
self.assertIn("/purl", call_args[0][1])
402+
self.assertNotIn("/orgs/", call_args[0][1])
386403

387404
# Quota endpoints
388405
def test_quota_get_unit(self):

tests/unit/test_socket_sdk_unit.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ def test_socket_purl_creation(self):
110110
type=SocketPURL_Type.NPM,
111111
name="lodash",
112112
namespace=None,
113-
release="4.17.21"
113+
release="4.18.1"
114114
)
115115

116116
self.assertEqual(purl.type, SocketPURL_Type.NPM)
117117
self.assertEqual(purl.name, "lodash")
118118
self.assertIsNone(purl.namespace)
119-
self.assertEqual(purl.release, "4.17.21")
119+
self.assertEqual(purl.release, "4.18.1")
120120

121121
def test_integration_types(self):
122122
"""Test that all integration types are available."""
@@ -223,7 +223,7 @@ def setUp(self):
223223
"name": "test-package",
224224
"version": "1.0.0",
225225
"dependencies": {
226-
"lodash": "4.17.21"
226+
"lodash": "4.18.1"
227227
}
228228
}
229229

tests/unit/test_working_endpoints_unit.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,24 @@ def test_npm_issues_unit(self):
5050
expected_data = [{"type": "security", "severity": "high"}]
5151
self._mock_response(expected_data)
5252

53-
result = self.sdk.npm.issues("lodash", "4.17.21")
53+
result = self.sdk.npm.issues("lodash", "4.18.1")
5454

5555
self.assertEqual(result, expected_data)
5656
call_args = self.mock_requests.request.call_args
5757
self.assertEqual(call_args[0][0], "GET")
58-
self.assertIn("/npm/lodash/4.17.21/issues", call_args[0][1])
58+
self.assertIn("/npm/lodash/4.18.1/issues", call_args[0][1])
5959

6060
def test_npm_score_unit(self):
6161
"""Test NPM score endpoint - WORKING."""
6262
expected_data = [{"category": "security", "value": 85}]
6363
self._mock_response(expected_data)
6464

65-
result = self.sdk.npm.score("lodash", "4.17.21")
65+
result = self.sdk.npm.score("lodash", "4.18.1")
6666

6767
self.assertEqual(result, expected_data)
6868
call_args = self.mock_requests.request.call_args
6969
self.assertEqual(call_args[0][0], "GET")
70-
self.assertIn("/npm/lodash/4.17.21/score", call_args[0][1])
70+
self.assertIn("/npm/lodash/4.18.1/score", call_args[0][1])
7171

7272
def test_openapi_get_unit(self):
7373
"""Test OpenAPI specification retrieval - WORKING."""

0 commit comments

Comments
 (0)