Skip to content

Commit bf0d75c

Browse files
committed
test(salesforce): cover private-address DNS refusal in update-custom-field
1 parent 6f70ef0 commit bf0d75c

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

‎apps/sim/lib/internal/salesforce/operations/update-custom-field.test.ts‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
import { describe, expect, it } from 'vitest'
1+
import { beforeEach, describe, expect, it, vi } from 'vitest'
2+
3+
const { mockResolveHostAddresses } = vi.hoisted(() => ({
4+
mockResolveHostAddresses: vi.fn(),
5+
}))
6+
7+
vi.mock('@sim/security/dns', () => ({
8+
resolveHostAddresses: mockResolveHostAddresses,
9+
preferIpv4: (addresses: string[]) => addresses[0],
10+
}))
11+
212
import { executeSalesforceUpdateCustomFieldOperation } from '@/lib/internal/salesforce/operations/update-custom-field'
313

414
const PARAMS = {
@@ -9,6 +19,10 @@ const PARAMS = {
919
}
1020

1121
describe('salesforce update custom field operation', () => {
22+
beforeEach(() => {
23+
vi.stubGlobal('fetch', vi.fn())
24+
})
25+
1226
it('rejects a field ID that could escape the CustomField path before provider work', async () => {
1327
await expect(
1428
executeSalesforceUpdateCustomFieldOperation({
@@ -26,4 +40,13 @@ describe('salesforce update custom field operation', () => {
2640
} as never)
2741
).rejects.toThrow('Salesforce instance URL must be on a Salesforce domain')
2842
})
43+
44+
it('refuses a Salesforce host that resolves to a private address before sending the token', async () => {
45+
mockResolveHostAddresses.mockResolvedValue({ addresses: ['10.0.0.5'] })
46+
47+
await expect(executeSalesforceUpdateCustomFieldOperation(PARAMS as never)).rejects.toThrow(
48+
'instanceUrl resolves to a private or reserved address'
49+
)
50+
expect(fetch).not.toHaveBeenCalled()
51+
})
2952
})

0 commit comments

Comments
 (0)