Skip to content

Commit 0a08bd2

Browse files
committed
fix failing tests
1 parent 4eaad05 commit 0a08bd2

File tree

2 files changed

+42
-38
lines changed

2 files changed

+42
-38
lines changed

apps/sim/ee/access-control/utils/permission-check.test.ts

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,36 @@
44
import { databaseMock, drizzleOrmMock, loggerMock } from '@sim/testing'
55
import { beforeEach, describe, expect, it, vi } from 'vitest'
66

7-
const DEFAULT_PERMISSION_GROUP_CONFIG = {
8-
allowedIntegrations: null,
9-
allowedModelProviders: null,
10-
hideTraceSpans: false,
11-
hideKnowledgeBaseTab: false,
12-
hideCopilot: false,
13-
hideApiKeysTab: false,
14-
hideEnvironmentTab: false,
15-
hideFilesTab: false,
16-
disableMcpTools: false,
17-
disableCustomTools: false,
18-
disableSkills: false,
19-
hideTemplates: false,
20-
disableInvitations: false,
21-
hideDeployApi: false,
22-
hideDeployMcp: false,
23-
hideDeployA2a: false,
24-
hideDeployChatbot: false,
25-
hideDeployTemplate: false,
26-
}
27-
28-
const mockGetAllowedIntegrationsFromEnv = vi.fn<() => string[] | null>()
29-
const mockIsOrganizationOnEnterprisePlan = vi.fn<() => Promise<boolean>>()
30-
const mockGetProviderFromModel = vi.fn<(model: string) => string>()
7+
const {
8+
DEFAULT_PERMISSION_GROUP_CONFIG,
9+
mockGetAllowedIntegrationsFromEnv,
10+
mockIsOrganizationOnEnterprisePlan,
11+
mockGetProviderFromModel,
12+
} = vi.hoisted(() => ({
13+
DEFAULT_PERMISSION_GROUP_CONFIG: {
14+
allowedIntegrations: null,
15+
allowedModelProviders: null,
16+
hideTraceSpans: false,
17+
hideKnowledgeBaseTab: false,
18+
hideCopilot: false,
19+
hideApiKeysTab: false,
20+
hideEnvironmentTab: false,
21+
hideFilesTab: false,
22+
disableMcpTools: false,
23+
disableCustomTools: false,
24+
disableSkills: false,
25+
hideTemplates: false,
26+
disableInvitations: false,
27+
hideDeployApi: false,
28+
hideDeployMcp: false,
29+
hideDeployA2a: false,
30+
hideDeployChatbot: false,
31+
hideDeployTemplate: false,
32+
},
33+
mockGetAllowedIntegrationsFromEnv: vi.fn<() => string[] | null>(),
34+
mockIsOrganizationOnEnterprisePlan: vi.fn<() => Promise<boolean>>(),
35+
mockGetProviderFromModel: vi.fn<(model: string) => string>(),
36+
}))
3137

3238
vi.mock('@sim/db', () => databaseMock)
3339
vi.mock('@sim/db/schema', () => ({}))
@@ -52,7 +58,6 @@ vi.mock('@/providers/utils', () => ({
5258
getProviderFromModel: mockGetProviderFromModel,
5359
}))
5460

55-
import { getAllowedIntegrationsFromEnv } from '@/lib/core/config/feature-flags'
5661
import {
5762
getUserPermissionConfig,
5863
IntegrationNotAllowedError,
@@ -112,13 +117,13 @@ describe('env allowlist fallback when userId is absent', () => {
112117
vi.clearAllMocks()
113118
})
114119

115-
it('returns null config when no userId and no env allowlist', async () => {
120+
it('returns null allowlist when no userId and no env allowlist', async () => {
116121
mockGetAllowedIntegrationsFromEnv.mockReturnValue(null)
117122

118123
const userId: string | undefined = undefined
119124
const permissionConfig = userId ? await getUserPermissionConfig(userId) : null
120125
const allowedIntegrations =
121-
permissionConfig?.allowedIntegrations ?? getAllowedIntegrationsFromEnv()
126+
permissionConfig?.allowedIntegrations ?? mockGetAllowedIntegrationsFromEnv()
122127

123128
expect(allowedIntegrations).toBeNull()
124129
})
@@ -129,7 +134,7 @@ describe('env allowlist fallback when userId is absent', () => {
129134
const userId: string | undefined = undefined
130135
const permissionConfig = userId ? await getUserPermissionConfig(userId) : null
131136
const allowedIntegrations =
132-
permissionConfig?.allowedIntegrations ?? getAllowedIntegrationsFromEnv()
137+
permissionConfig?.allowedIntegrations ?? mockGetAllowedIntegrationsFromEnv()
133138

134139
expect(allowedIntegrations).toEqual(['slack', 'gmail'])
135140
})
@@ -140,7 +145,7 @@ describe('env allowlist fallback when userId is absent', () => {
140145
const userId: string | undefined = undefined
141146
const permissionConfig = userId ? await getUserPermissionConfig(userId) : null
142147
const allowedIntegrations =
143-
permissionConfig?.allowedIntegrations ?? getAllowedIntegrationsFromEnv()
148+
permissionConfig?.allowedIntegrations ?? mockGetAllowedIntegrationsFromEnv()
144149

145150
expect(allowedIntegrations).not.toBeNull()
146151
expect(allowedIntegrations!.includes('slack')).toBe(true)
@@ -210,14 +215,12 @@ describe('validateBlockType', () => {
210215
await validateBlockType(undefined, 'GOOGLE_DRIVE')
211216
})
212217

213-
it('includes reason in error for env-only enforcement', async () => {
218+
it('includes env reason in error when env allowlist is the source', async () => {
214219
await expect(validateBlockType(undefined, 'discord')).rejects.toThrow(/ALLOWED_INTEGRATIONS/)
215220
})
216221

217-
it('does not include env reason when userId is provided', async () => {
218-
await expect(validateBlockType('user-123', 'discord')).rejects.toThrow(
219-
/permission group settings/
220-
)
222+
it('includes env reason even when userId is present if env is the source', async () => {
223+
await expect(validateBlockType('user-123', 'discord')).rejects.toThrow(/ALLOWED_INTEGRATIONS/)
221224
})
222225
})
223226
})

apps/sim/ee/access-control/utils/permission-check.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,17 @@ export async function validateBlockType(
195195
}
196196

197197
if (!config.allowedIntegrations.includes(blockType.toLowerCase())) {
198-
const isEnvOnly = !userId
198+
const envAllowlist = getAllowedIntegrationsFromEnv()
199+
const blockedByEnv = envAllowlist !== null && !envAllowlist.includes(blockType.toLowerCase())
199200
logger.warn(
200-
isEnvOnly
201+
blockedByEnv
201202
? 'Integration blocked by env allowlist'
202-
: 'Integration blocked by permission config',
203+
: 'Integration blocked by permission group',
203204
{ userId, blockType }
204205
)
205206
throw new IntegrationNotAllowedError(
206207
blockType,
207-
isEnvOnly ? 'blocked by server ALLOWED_INTEGRATIONS policy' : undefined
208+
blockedByEnv ? 'blocked by server ALLOWED_INTEGRATIONS policy' : undefined
208209
)
209210
}
210211
}

0 commit comments

Comments
 (0)