Skip to content

Commit 77f3713

Browse files
committed
test(databricks): assert every tool refuses a foreign host with the allowlist error
1 parent 21d20ca commit 77f3713

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

‎apps/sim/tools/databricks/databricks.test.ts‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { inputValidationMock } from '@sim/testing'
22
import { partialToolRegistry } from '@sim/testing/mocks/tool-registry.mock'
3+
import { getErrorMessage } from '@sim/utils/errors'
34
import { describe, expect, it, vi } from 'vitest'
45

56
vi.mock('@/lib/core/security/input-validation.server', () => inputValidationMock)
@@ -36,13 +37,13 @@ const REQUEST_PARAMS = {
3637
rating: 'POSITIVE',
3738
}
3839

40+
/** The validator's refusal, naming the `host` param and every allowlisted Databricks domain. */
41+
const HOST_ALLOWLIST_ERROR =
42+
'host must be a Databricks-hosted domain (e.g., *.cloud.databricks.com, *.cloud.databricks.us, *.cloud.databricks.mil, *.gcp.databricks.com, *.databricks.com, *.azuredatabricks.net, *.databricks.azure.us, *.databricks.azure.cn)'
43+
3944
const DATABRICKS_TOOL_IDS = Object.keys(tools).filter((id) => id.startsWith('databricks_'))
4045

4146
describe('databricks workspace host allowlist', () => {
42-
it('registers the Databricks tools', () => {
43-
expect(DATABRICKS_TOOL_IDS).not.toEqual([])
44-
})
45-
4647
it.each([
4748
'attacker.example.com',
4849
'https://attacker.example.com/',
@@ -51,16 +52,15 @@ describe('databricks workspace host allowlist', () => {
5152
'dbc-1.cloud.databricks.com@attacker.example.com',
5253
'databricks.com',
5354
'acme-databricks.com',
54-
])('refuses %s in every tool before a URL is built', (host) => {
55-
const accepted = DATABRICKS_TOOL_IDS.filter((id) => {
55+
])('refuses %s in every tool with the host allowlist error', (host) => {
56+
const notRefusedByAllowlist = DATABRICKS_TOOL_IDS.map((id) => {
5657
try {
57-
urlBuilder(id)({ ...REQUEST_PARAMS, host })
58-
return true
59-
} catch {
60-
return false
58+
return `${id}: built ${urlBuilder(id)({ ...REQUEST_PARAMS, host })}`
59+
} catch (error) {
60+
return `${id}: ${getErrorMessage(error)}`
6161
}
62-
})
63-
expect(accepted).toEqual([])
62+
}).filter((outcome) => !outcome.endsWith(`: ${HOST_ALLOWLIST_ERROR}`))
63+
expect(notRefusedByAllowlist).toEqual([])
6464
})
6565

6666
it('fails the tool call for a foreign host with the allowlist error', async () => {
@@ -70,7 +70,7 @@ describe('databricks workspace host allowlist', () => {
7070
})
7171

7272
expect(result.success).toBe(false)
73-
expect(result.error).toContain('host must be a Databricks-hosted domain')
73+
expect(result.error).toContain(HOST_ALLOWLIST_ERROR)
7474
})
7575

7676
it.each([

0 commit comments

Comments
 (0)