d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
85 lines
2.8 KiB
TypeScript
85 lines
2.8 KiB
TypeScript
/**
|
|
* @vitest-environment node
|
|
*/
|
|
import { dbChainMock, dbChainMockFns, resetDbChainMock } from '@sim/testing'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
const { mockCheckWorkspaceAccess } = vi.hoisted(() => ({
|
|
mockCheckWorkspaceAccess: vi.fn(),
|
|
}))
|
|
|
|
vi.mock('@sim/db', () => dbChainMock)
|
|
|
|
vi.mock('@/lib/workspaces/permissions/utils', () => ({
|
|
checkWorkspaceAccess: mockCheckWorkspaceAccess,
|
|
}))
|
|
|
|
vi.mock('drizzle-orm', () => ({
|
|
and: vi.fn((...args: unknown[]) => ({ type: 'and', args })),
|
|
eq: vi.fn((...args: unknown[]) => ({ type: 'eq', args })),
|
|
inArray: vi.fn((...args: unknown[]) => ({ type: 'inArray', args })),
|
|
isNotNull: vi.fn((field: unknown) => ({ type: 'isNotNull', field })),
|
|
isNull: vi.fn((field: unknown) => ({ type: 'isNull', field })),
|
|
or: vi.fn((...args: unknown[]) => ({ type: 'or', args })),
|
|
}))
|
|
|
|
import { validateSelectorIds } from './selector-validator'
|
|
|
|
describe('validateSelectorIds', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
resetDbChainMock()
|
|
mockCheckWorkspaceAccess.mockResolvedValue({ canAdmin: false })
|
|
})
|
|
|
|
it('accepts shared workspace credential ids and legacy account ids for oauth-input', async () => {
|
|
dbChainMockFns.where.mockResolvedValueOnce([{ credentialId: 'cred-1', accountId: 'acct-1' }])
|
|
|
|
const result = await validateSelectorIds('oauth-input', ['cred-1', 'acct-1'], {
|
|
userId: 'user-1',
|
|
workspaceId: 'workspace-1',
|
|
})
|
|
|
|
expect(result).toEqual({
|
|
valid: ['cred-1', 'acct-1'],
|
|
invalid: [],
|
|
})
|
|
expect(dbChainMockFns.select).toHaveBeenCalledTimes(1)
|
|
})
|
|
|
|
it('reports accessible workspace credentials in warnings for invalid oauth-input ids', async () => {
|
|
dbChainMockFns.where.mockResolvedValueOnce([]).mockResolvedValueOnce([
|
|
{
|
|
id: 'cred-2',
|
|
displayName: 'Shared Gmail',
|
|
accountId: 'acct-2',
|
|
credentialProviderId: null,
|
|
accountProviderId: 'google-email',
|
|
},
|
|
])
|
|
|
|
const result = await validateSelectorIds('oauth-input', 'missing-cred', {
|
|
userId: 'user-1',
|
|
workspaceId: 'workspace-1',
|
|
})
|
|
|
|
expect(result.valid).toEqual([])
|
|
expect(result.invalid).toEqual(['missing-cred'])
|
|
expect(result.warning).toContain('Accessible workspace credentials:')
|
|
expect(result.warning).toContain('Shared Gmail [cred-2]')
|
|
})
|
|
|
|
it('lets a derived workspace admin reference shared credentials without membership', async () => {
|
|
mockCheckWorkspaceAccess.mockResolvedValueOnce({ canAdmin: true })
|
|
dbChainMockFns.where.mockResolvedValueOnce([{ credentialId: 'shared-cred', accountId: null }])
|
|
|
|
const result = await validateSelectorIds('oauth-input', ['shared-cred'], {
|
|
userId: 'admin-user',
|
|
workspaceId: 'workspace-1',
|
|
})
|
|
|
|
expect(result).toEqual({ valid: ['shared-cred'], invalid: [] })
|
|
expect(dbChainMockFns.select).toHaveBeenCalledTimes(1)
|
|
})
|
|
})
|