Skip to content

Commit d1872a4

Browse files
fix feature flag
1 parent d44aad7 commit d1872a4

6 files changed

Lines changed: 360 additions & 1108 deletions

File tree

apps/sim/lib/api-key/crypto.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ describe('hashApiKey', () => {
4646
})
4747

4848
it('matches the published SHA-256 vector for the empty string', () => {
49-
expect(hashApiKey('')).toBe(
50-
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
51-
)
49+
expect(hashApiKey('')).toBe('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855')
5250
})
5351
})
5452

apps/sim/lib/api-key/service.test.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,7 @@ describe('authenticateApiKeyFromHeader', () => {
126126

127127
it('falls back to the decrypt loop when no row matches the hash, and warns on success', async () => {
128128
const record = personalKeyRecord()
129-
dbChainMockFns.where
130-
.mockResolvedValueOnce([])
131-
.mockResolvedValueOnce([record])
129+
dbChainMockFns.where.mockResolvedValueOnce([]).mockResolvedValueOnce([record])
132130
mockAuthenticateApiKey.mockResolvedValueOnce(true)
133131

134132
const result = await authenticateApiKeyFromHeader('sk-sim-plain-key', {
@@ -153,9 +151,7 @@ describe('authenticateApiKeyFromHeader', () => {
153151
})
154152

155153
it('returns invalid when the hash lookup misses and the fallback scan also misses', async () => {
156-
dbChainMockFns.where
157-
.mockResolvedValueOnce([])
158-
.mockResolvedValueOnce([])
154+
dbChainMockFns.where.mockResolvedValueOnce([]).mockResolvedValueOnce([])
159155

160156
const result = await authenticateApiKeyFromHeader('sk-sim-plain-key', {
161157
userId: 'user-1',
@@ -169,9 +165,7 @@ describe('authenticateApiKeyFromHeader', () => {
169165

170166
it('returns invalid when the hash lookup misses and every fallback candidate fails decrypt comparison', async () => {
171167
const record = personalKeyRecord()
172-
dbChainMockFns.where
173-
.mockResolvedValueOnce([])
174-
.mockResolvedValueOnce([record])
168+
dbChainMockFns.where.mockResolvedValueOnce([]).mockResolvedValueOnce([record])
175169
mockAuthenticateApiKey.mockResolvedValueOnce(false)
176170

177171
const result = await authenticateApiKeyFromHeader('sk-sim-plain-key', {

apps/sim/lib/api-key/service.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ import { and, eq } from 'drizzle-orm'
55
import { authenticateApiKey } from '@/lib/api-key/auth'
66
import { hashApiKey } from '@/lib/api-key/crypto'
77
import { getUserEntityPermissions } from '@/lib/workspaces/permissions/utils'
8-
import {
9-
getWorkspaceBillingSettings,
10-
type WorkspaceBillingSettings,
11-
} from '@/lib/workspaces/utils'
8+
import { getWorkspaceBillingSettings, type WorkspaceBillingSettings } from '@/lib/workspaces/utils'
129

1310
const logger = createLogger('ApiKeyService')
1411

@@ -221,7 +218,11 @@ async function applyHashGates(
221218
if (options.keyTypes?.length && !options.keyTypes.includes(keyType)) return INVALID
222219
if (record.expiresAt && record.expiresAt < new Date()) return INVALID
223220

224-
if (options.workspaceId && keyType === 'workspace' && record.workspaceId !== options.workspaceId) {
221+
if (
222+
options.workspaceId &&
223+
keyType === 'workspace' &&
224+
record.workspaceId !== options.workspaceId
225+
) {
225226
return INVALID
226227
}
227228

0 commit comments

Comments
 (0)