Skip to content

Commit 93f98d4

Browse files
committed
test(repo): adapt DNS-guidance and sendApi tests to the fail-closed nock setup
1 parent 2474974 commit 93f98d4

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

test/repo/unit/socket-sdk-api-methods.coverage.test.mts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,8 +1181,12 @@ describe('SocketSdk - API Methods Coverage', () => {
11811181
})
11821182

11831183
it('covers sendApi method', async () => {
1184-
// Test the generic sendApi method with POST
1185-
const result = await client.sendApi('/scan', {
1184+
// Test the generic sendApi method with POST. The urlPath follows the
1185+
// documented form without a leading slash — the SDK appends it to the
1186+
// trailing-slash baseUrl, and a leading slash would produce a
1187+
// double-slash URL that nock's fail-closed net-connect guard misparses
1188+
// as protocol-relative and refuses.
1189+
const result = await client.sendApi('scan', {
11861190
body: { repo: 'test' },
11871191
method: 'POST',
11881192
})

test/repo/unit/socket-sdk-fail-paths.test.mts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import os from 'node:os'
1313
import path from 'node:path'
1414

15+
import nock from 'nock'
1516
import { describe, expect, it } from 'vitest'
1617

1718
import { SocketSdk } from '../../../src/index.mts'
@@ -150,6 +151,21 @@ describe('SocketSdk - downloadPatch error codes', () => {
150151

151152
it('should include ENOTFOUND guidance for unresolvable hostname', async () => {
152153
const client = new SocketSdk('test-token')
154+
// The fleet vitest setup fails network CLOSED (nock.disableNetConnect),
155+
// which refuses non-loopback requests BEFORE DNS resolution runs — the
156+
// refusal surfaces as ENETUNREACH, never ENOTFOUND. Mock the DNS failure
157+
// instead so the test still exercises the SDK's ENOTFOUND guidance
158+
// mapping deterministically.
159+
nock('http://this-host-does-not-exist-xyzzy.invalid')
160+
.get('/blob/sha256-test')
161+
.replyWithError(
162+
Object.assign(
163+
new Error(
164+
'getaddrinfo ENOTFOUND this-host-does-not-exist-xyzzy.invalid',
165+
),
166+
{ code: 'ENOTFOUND' },
167+
),
168+
)
153169
await expect(
154170
client.downloadPatch('sha256-test', {
155171
baseUrl: 'http://this-host-does-not-exist-xyzzy.invalid',

0 commit comments

Comments
 (0)