@elevasis/core 0.11.2 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -1
- package/dist/index.js +8 -1
- package/dist/organization-model/index.d.ts +2 -1
- package/dist/organization-model/index.js +8 -1
- package/dist/test-utils/index.d.ts +27 -15
- package/dist/test-utils/index.js +25 -0
- package/package.json +1 -1
- package/src/_gen/__tests__/__snapshots__/contracts.md.snap +27 -270
- package/src/auth/multi-tenancy/credentials/__tests__/encryption.test.ts +217 -216
- package/src/auth/multi-tenancy/credentials/server/encryption.ts +69 -39
- package/src/auth/multi-tenancy/credentials/server/kek-loader.ts +37 -0
- package/src/auth/multi-tenancy/index.ts +3 -0
- package/src/auth/multi-tenancy/invitations/api-schemas.ts +104 -107
- package/src/auth/multi-tenancy/memberships/api-schemas.ts +6 -5
- package/src/auth/multi-tenancy/memberships/membership.ts +130 -138
- package/src/auth/multi-tenancy/permissions.ts +12 -5
- package/src/auth/multi-tenancy/role-management/api-schemas.ts +78 -0
- package/src/auth/multi-tenancy/role-management/index.ts +16 -0
- package/src/business/acquisition/activity-events.ts +142 -0
- package/src/business/acquisition/api-schemas.ts +694 -689
- package/src/business/acquisition/derive-actions.ts +90 -0
- package/src/business/acquisition/index.ts +111 -109
- package/src/execution/engine/index.ts +434 -434
- package/src/execution/engine/tools/integration/server/adapters/apify/__tests__/apify-run-actor.integration.test.ts +298 -293
- package/src/execution/engine/tools/integration/server/adapters/attio/__tests__/attio-crud.integration.test.ts +0 -1
- package/src/execution/engine/tools/integration/service.test.ts +214 -0
- package/src/execution/engine/tools/integration/service.ts +169 -161
- package/src/execution/engine/tools/lead-service-types.ts +882 -879
- package/src/execution/engine/tools/registry.ts +699 -700
- package/src/execution/engine/tools/tool-maps.ts +777 -780
- package/src/integrations/credentials/__tests__/api-schemas.test.ts +420 -496
- package/src/integrations/credentials/api-schemas.ts +127 -143
- package/src/integrations/webhook-endpoints/__tests__/api-schemas.test.ts +327 -318
- package/src/integrations/webhook-endpoints/api-schemas.ts +103 -102
- package/src/integrations/webhook-endpoints/types.ts +58 -51
- package/src/operations/activities/api-schemas.ts +80 -79
- package/src/operations/activities/types.ts +64 -63
- package/src/organization-model/contracts.ts +1 -0
- package/src/organization-model/defaults.ts +6 -0
- package/src/organization-model/domains/navigation.ts +37 -23
- package/src/organization-model/organization-graph.mdx +2 -2
- package/src/organization-model/published.ts +2 -1
- package/src/platform/constants/versions.ts +1 -1
- package/src/reference/_generated/contracts.md +27 -270
- package/src/scaffold-registry/__tests__/index.test.ts +72 -7
- package/src/scaffold-registry/index.ts +163 -29
- package/src/scaffold-registry/schema.ts +68 -62
- package/src/server.ts +281 -272
- package/src/supabase/database.types.ts +16 -10
- package/src/test-utils/rls/RLSTestContext.ts +585 -553
|
@@ -1,496 +1,420 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Credential API schemas tests
|
|
3
|
-
* Tests all validation schemas for credentials endpoints
|
|
4
|
-
* Focus: Security (path traversal, DoS, mass assignment, type coercion)
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { describe, it, expect } from 'vitest'
|
|
8
|
-
import {
|
|
9
|
-
CredentialTypeSchema,
|
|
10
|
-
CreateCredentialRequestSchema,
|
|
11
|
-
UpdateCredentialParamsSchema,
|
|
12
|
-
UpdateCredentialRequestSchema,
|
|
13
|
-
DeleteCredentialParamsSchema,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
expect(CredentialTypeSchema.parse('
|
|
22
|
-
expect(CredentialTypeSchema.parse('
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
expect(() => CredentialTypeSchema.parse('
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
expect(() => CredentialTypeSchema.parse('
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
it('rejects missing
|
|
211
|
-
const {
|
|
212
|
-
expect(() => CreateCredentialRequestSchema.parse(payload)).toThrow()
|
|
213
|
-
})
|
|
214
|
-
|
|
215
|
-
it('rejects missing
|
|
216
|
-
const {
|
|
217
|
-
expect(() => CreateCredentialRequestSchema.parse(payload)).toThrow()
|
|
218
|
-
})
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
const result = CreateCredentialRequestSchema.parse(
|
|
235
|
-
expect(result.provider).
|
|
236
|
-
})
|
|
237
|
-
|
|
238
|
-
it('accepts
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
it('
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
expect(result.name).
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
expect(result.value).
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
)
|
|
330
|
-
expect(() => UpdateCredentialRequestSchema.parse({ value:
|
|
331
|
-
})
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
it('
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
expect(result.credentials[
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
})
|
|
422
|
-
|
|
423
|
-
describe('DecryptCredentialParamsSchema - CRITICAL ENDPOINT', () => {
|
|
424
|
-
describe('valid credential names', () => {
|
|
425
|
-
it('accepts valid credential name', () => {
|
|
426
|
-
const result = DecryptCredentialParamsSchema.parse({ credentialName: 'gmail-prod' })
|
|
427
|
-
expect(result.credentialName).toBe('gmail-prod')
|
|
428
|
-
})
|
|
429
|
-
|
|
430
|
-
it('accepts multi-segment names', () => {
|
|
431
|
-
const result = DecryptCredentialParamsSchema.parse({ credentialName: 'notion-dev-2024' })
|
|
432
|
-
expect(result.credentialName).toBe('notion-dev-2024')
|
|
433
|
-
})
|
|
434
|
-
|
|
435
|
-
it('trims whitespace', () => {
|
|
436
|
-
const result = DecryptCredentialParamsSchema.parse({ credentialName: ' gmail-prod ' })
|
|
437
|
-
expect(result.credentialName).toBe('gmail-prod')
|
|
438
|
-
})
|
|
439
|
-
|
|
440
|
-
it('auto-lowercases input', () => {
|
|
441
|
-
const result = DecryptCredentialParamsSchema.parse({ credentialName: 'Gmail-Prod' })
|
|
442
|
-
expect(result.credentialName).toBe('gmail-prod')
|
|
443
|
-
})
|
|
444
|
-
})
|
|
445
|
-
|
|
446
|
-
describe('CRITICAL SECURITY: path traversal prevention', () => {
|
|
447
|
-
it('rejects path traversal attempts', () => {
|
|
448
|
-
expect(() => DecryptCredentialParamsSchema.parse({ credentialName: '../admin-cred' })).toThrow(/must be lowercase/)
|
|
449
|
-
expect(() => DecryptCredentialParamsSchema.parse({ credentialName: '../../secrets' })).toThrow(/must be lowercase/)
|
|
450
|
-
expect(() => DecryptCredentialParamsSchema.parse({ credentialName: './../config' })).toThrow(/must be lowercase/)
|
|
451
|
-
})
|
|
452
|
-
|
|
453
|
-
it('rejects relative path characters', () => {
|
|
454
|
-
expect(() => DecryptCredentialParamsSchema.parse({ credentialName: './local-cred' })).toThrow(/must be lowercase/)
|
|
455
|
-
expect(() => DecryptCredentialParamsSchema.parse({ credentialName: '../parent' })).toThrow(/must be lowercase/)
|
|
456
|
-
})
|
|
457
|
-
})
|
|
458
|
-
|
|
459
|
-
describe('CRITICAL SECURITY: SQL injection prevention', () => {
|
|
460
|
-
it('rejects SQL injection attempts', () => {
|
|
461
|
-
expect(() => DecryptCredentialParamsSchema.parse({ credentialName: "' OR '1'='1" })).toThrow(/must be lowercase/)
|
|
462
|
-
expect(() => DecryptCredentialParamsSchema.parse({ credentialName: "admin'; DROP TABLE credentials;--" })).toThrow(/must be lowercase/)
|
|
463
|
-
})
|
|
464
|
-
})
|
|
465
|
-
|
|
466
|
-
describe('CRITICAL SECURITY: special character prevention', () => {
|
|
467
|
-
it('rejects names with spaces', () => {
|
|
468
|
-
expect(() => DecryptCredentialParamsSchema.parse({ credentialName: 'gmail prod' })).toThrow(/must be lowercase/)
|
|
469
|
-
})
|
|
470
|
-
|
|
471
|
-
it('rejects names with special characters', () => {
|
|
472
|
-
expect(() => DecryptCredentialParamsSchema.parse({ credentialName: 'gmail@prod' })).toThrow(/must be lowercase/)
|
|
473
|
-
expect(() => DecryptCredentialParamsSchema.parse({ credentialName: 'notion#dev' })).toThrow(/must be lowercase/)
|
|
474
|
-
expect(() => DecryptCredentialParamsSchema.parse({ credentialName: 'slack$prod' })).toThrow(/must be lowercase/)
|
|
475
|
-
})
|
|
476
|
-
})
|
|
477
|
-
|
|
478
|
-
describe('CRITICAL SECURITY: DoS prevention', () => {
|
|
479
|
-
it('rejects empty names', () => {
|
|
480
|
-
expect(() => DecryptCredentialParamsSchema.parse({ credentialName: '' })).toThrow(/required/)
|
|
481
|
-
expect(() => DecryptCredentialParamsSchema.parse({ credentialName: ' ' })).toThrow(/required/)
|
|
482
|
-
})
|
|
483
|
-
|
|
484
|
-
it('rejects names too long (over 100 chars)', () => {
|
|
485
|
-
const longName = 'a-' + 'b'.repeat(99)
|
|
486
|
-
expect(() => DecryptCredentialParamsSchema.parse({ credentialName: longName })).toThrow(/too long/)
|
|
487
|
-
})
|
|
488
|
-
|
|
489
|
-
it('accepts names at max length (100 chars)', () => {
|
|
490
|
-
const maxName = 'a'.repeat(49) + '-' + 'b'.repeat(49) + 'c'
|
|
491
|
-
const result = DecryptCredentialParamsSchema.parse({ credentialName: maxName })
|
|
492
|
-
expect(result.credentialName).toBe(maxName)
|
|
493
|
-
})
|
|
494
|
-
})
|
|
495
|
-
})
|
|
496
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Credential API schemas tests
|
|
3
|
+
* Tests all validation schemas for credentials endpoints
|
|
4
|
+
* Focus: Security (path traversal, DoS, mass assignment, type coercion)
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, it, expect } from 'vitest'
|
|
8
|
+
import {
|
|
9
|
+
CredentialTypeSchema,
|
|
10
|
+
CreateCredentialRequestSchema,
|
|
11
|
+
UpdateCredentialParamsSchema,
|
|
12
|
+
UpdateCredentialRequestSchema,
|
|
13
|
+
DeleteCredentialParamsSchema,
|
|
14
|
+
ListCredentialsResponseSchema
|
|
15
|
+
} from '../api-schemas'
|
|
16
|
+
|
|
17
|
+
describe('CredentialTypeSchema', () => {
|
|
18
|
+
it('accepts valid credential types', () => {
|
|
19
|
+
// These are the actual types stored in the database
|
|
20
|
+
expect(CredentialTypeSchema.parse('oauth')).toBe('oauth')
|
|
21
|
+
expect(CredentialTypeSchema.parse('api-key')).toBe('api-key')
|
|
22
|
+
expect(CredentialTypeSchema.parse('webhook-secret')).toBe('webhook-secret')
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('rejects invalid credential types', () => {
|
|
26
|
+
expect(() => CredentialTypeSchema.parse('invalid-type')).toThrow()
|
|
27
|
+
expect(() => CredentialTypeSchema.parse('')).toThrow()
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('rejects provider names (these are CREDENTIAL_SCHEMAS keys, not stored types)', () => {
|
|
31
|
+
// OAuth providers store type='oauth', not their provider name
|
|
32
|
+
expect(() => CredentialTypeSchema.parse('notion')).toThrow()
|
|
33
|
+
expect(() => CredentialTypeSchema.parse('google-sheets')).toThrow()
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
describe('CreateCredentialRequestSchema', () => {
|
|
38
|
+
const validPayload = {
|
|
39
|
+
name: 'gmail-prod',
|
|
40
|
+
type: 'api-key' as const,
|
|
41
|
+
value: { apiKey: 'test-key-123' }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
describe('valid requests', () => {
|
|
45
|
+
it('accepts valid credential creation request', () => {
|
|
46
|
+
const result = CreateCredentialRequestSchema.parse(validPayload)
|
|
47
|
+
expect(result).toEqual(validPayload)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
it('accepts oauth type credentials', () => {
|
|
51
|
+
const payload = {
|
|
52
|
+
name: 'notion-dev',
|
|
53
|
+
type: 'oauth' as const,
|
|
54
|
+
value: { accessToken: 'token', refreshToken: 'refresh' }
|
|
55
|
+
}
|
|
56
|
+
const result = CreateCredentialRequestSchema.parse(payload)
|
|
57
|
+
expect(result).toEqual(payload)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('accepts webhook-secret type credentials', () => {
|
|
61
|
+
const payload = {
|
|
62
|
+
name: 'stripe-webhook',
|
|
63
|
+
type: 'webhook-secret' as const,
|
|
64
|
+
value: { signingSecret: 'whsec_abc123' }
|
|
65
|
+
}
|
|
66
|
+
const result = CreateCredentialRequestSchema.parse(payload)
|
|
67
|
+
expect(result).toEqual(payload)
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
describe('SECURITY: mass assignment prevention', () => {
|
|
72
|
+
it('rejects unknown fields (strict mode)', () => {
|
|
73
|
+
const payload = {
|
|
74
|
+
...validPayload,
|
|
75
|
+
organizationId: 'attacker-org-id', // Injected field
|
|
76
|
+
createdBy: null // Override creator
|
|
77
|
+
}
|
|
78
|
+
expect(() => CreateCredentialRequestSchema.parse(payload)).toThrow()
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('rejects extra top-level fields', () => {
|
|
82
|
+
const payload = {
|
|
83
|
+
...validPayload,
|
|
84
|
+
maliciousField: 'value'
|
|
85
|
+
}
|
|
86
|
+
expect(() => CreateCredentialRequestSchema.parse(payload)).toThrow()
|
|
87
|
+
})
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
describe('SECURITY: credential name validation', () => {
|
|
91
|
+
it('rejects invalid credential names', () => {
|
|
92
|
+
const payload = { ...validPayload, name: 'gmail prod' }
|
|
93
|
+
expect(() => CreateCredentialRequestSchema.parse(payload)).toThrow(/must be lowercase/)
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
it('rejects path traversal in name', () => {
|
|
97
|
+
const payload = { ...validPayload, name: '../admin-cred' }
|
|
98
|
+
expect(() => CreateCredentialRequestSchema.parse(payload)).toThrow(/must be lowercase/)
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
it('rejects special characters in name', () => {
|
|
102
|
+
const payload = { ...validPayload, name: 'gmail@prod' }
|
|
103
|
+
expect(() => CreateCredentialRequestSchema.parse(payload)).toThrow(/must be lowercase/)
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
it('rejects names without hyphens', () => {
|
|
107
|
+
const payload = { ...validPayload, name: 'gmailprod' }
|
|
108
|
+
expect(() => CreateCredentialRequestSchema.parse(payload)).toThrow(/must be lowercase/)
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it('rejects underscores', () => {
|
|
112
|
+
const payload = { ...validPayload, name: 'gmail_prod' }
|
|
113
|
+
expect(() => CreateCredentialRequestSchema.parse(payload)).toThrow(/must be lowercase/)
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
it('auto-lowercases uppercase input', () => {
|
|
117
|
+
const payload = { ...validPayload, name: 'Gmail-Prod' }
|
|
118
|
+
const result = CreateCredentialRequestSchema.parse(payload)
|
|
119
|
+
expect(result.name).toBe('gmail-prod')
|
|
120
|
+
})
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
describe('SECURITY: credential type validation', () => {
|
|
124
|
+
it('rejects invalid credential types', () => {
|
|
125
|
+
const payload = { ...validPayload, type: 'invalid-type' }
|
|
126
|
+
expect(() => CreateCredentialRequestSchema.parse(payload)).toThrow()
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
it('rejects null type', () => {
|
|
130
|
+
const payload = { ...validPayload, type: null }
|
|
131
|
+
expect(() => CreateCredentialRequestSchema.parse(payload)).toThrow()
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
it('rejects array as type', () => {
|
|
135
|
+
const payload = { ...validPayload, type: ['api-key'] }
|
|
136
|
+
expect(() => CreateCredentialRequestSchema.parse(payload)).toThrow()
|
|
137
|
+
})
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
describe('SECURITY: credential value validation', () => {
|
|
141
|
+
it('rejects empty credential value', () => {
|
|
142
|
+
const payload = { ...validPayload, value: {} }
|
|
143
|
+
expect(() => CreateCredentialRequestSchema.parse(payload)).toThrow(/must not be empty/)
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
it('rejects non-object value', () => {
|
|
147
|
+
const payload = { ...validPayload, value: 'string-instead-of-object' }
|
|
148
|
+
expect(() => CreateCredentialRequestSchema.parse(payload)).toThrow()
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
it('rejects null value', () => {
|
|
152
|
+
const payload = { ...validPayload, value: null }
|
|
153
|
+
expect(() => CreateCredentialRequestSchema.parse(payload)).toThrow()
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
it('rejects array as value', () => {
|
|
157
|
+
const payload = { ...validPayload, value: ['array', 'as', 'value'] }
|
|
158
|
+
expect(() => CreateCredentialRequestSchema.parse(payload)).toThrow()
|
|
159
|
+
})
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
describe('SECURITY: DoS prevention - credential value size', () => {
|
|
163
|
+
it('rejects credential value with too many keys (over 50)', () => {
|
|
164
|
+
const largeValue = Object.fromEntries(Array.from({ length: 51 }, (_, i) => [`key${i}`, 'value']))
|
|
165
|
+
const payload = { ...validPayload, value: largeValue }
|
|
166
|
+
expect(() => CreateCredentialRequestSchema.parse(payload)).toThrow(/too many keys/)
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
it('accepts credential value with max keys (50)', () => {
|
|
170
|
+
const maxValue = Object.fromEntries(Array.from({ length: 50 }, (_, i) => [`key${i}`, 'value']))
|
|
171
|
+
const payload = { ...validPayload, value: maxValue }
|
|
172
|
+
const result = CreateCredentialRequestSchema.parse(payload)
|
|
173
|
+
expect(Object.keys(result.value).length).toBe(50)
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
it('rejects individual string values over 10KB', () => {
|
|
177
|
+
const hugeString = 'a'.repeat(10241)
|
|
178
|
+
const payload = { ...validPayload, value: { apiKey: hugeString } }
|
|
179
|
+
expect(() => CreateCredentialRequestSchema.parse(payload)).toThrow(/too large/)
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
it('accepts string values at max size (10KB)', () => {
|
|
183
|
+
const maxString = 'a'.repeat(10240)
|
|
184
|
+
const payload = { ...validPayload, value: { apiKey: maxString } }
|
|
185
|
+
const result = CreateCredentialRequestSchema.parse(payload)
|
|
186
|
+
expect(result.value.apiKey).toBe(maxString)
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
it('allows non-string values without size checks', () => {
|
|
190
|
+
const payload = {
|
|
191
|
+
...validPayload,
|
|
192
|
+
value: {
|
|
193
|
+
apiKey: 'test',
|
|
194
|
+
number: 12345,
|
|
195
|
+
boolean: true,
|
|
196
|
+
nested: { key: 'value' }
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
const result = CreateCredentialRequestSchema.parse(payload)
|
|
200
|
+
expect(result.value).toEqual(payload.value)
|
|
201
|
+
})
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
describe('required fields', () => {
|
|
205
|
+
it('rejects missing name', () => {
|
|
206
|
+
const { name: _name, ...payload } = validPayload
|
|
207
|
+
expect(() => CreateCredentialRequestSchema.parse(payload)).toThrow()
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
it('rejects missing type', () => {
|
|
211
|
+
const { type: _type, ...payload } = validPayload
|
|
212
|
+
expect(() => CreateCredentialRequestSchema.parse(payload)).toThrow()
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
it('rejects missing value', () => {
|
|
216
|
+
const { value: _value, ...payload } = validPayload
|
|
217
|
+
expect(() => CreateCredentialRequestSchema.parse(payload)).toThrow()
|
|
218
|
+
})
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
describe('provider field (OAuth provider identification)', () => {
|
|
222
|
+
it('accepts OAuth credential with provider', () => {
|
|
223
|
+
const payload = {
|
|
224
|
+
name: 'my-dropbox',
|
|
225
|
+
type: 'oauth' as const,
|
|
226
|
+
value: { accessToken: 'token', refreshToken: 'refresh' },
|
|
227
|
+
provider: 'dropbox'
|
|
228
|
+
}
|
|
229
|
+
const result = CreateCredentialRequestSchema.parse(payload)
|
|
230
|
+
expect(result.provider).toBe('dropbox')
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
it('accepts request without provider (optional field)', () => {
|
|
234
|
+
const result = CreateCredentialRequestSchema.parse(validPayload)
|
|
235
|
+
expect(result.provider).toBeUndefined()
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
it('accepts various OAuth provider values', () => {
|
|
239
|
+
const providers = ['dropbox', 'notion', 'google-sheets']
|
|
240
|
+
for (const provider of providers) {
|
|
241
|
+
const payload = {
|
|
242
|
+
name: `my-${provider}`,
|
|
243
|
+
type: 'oauth' as const,
|
|
244
|
+
value: { accessToken: 'token' },
|
|
245
|
+
provider
|
|
246
|
+
}
|
|
247
|
+
const result = CreateCredentialRequestSchema.parse(payload)
|
|
248
|
+
expect(result.provider).toBe(provider)
|
|
249
|
+
}
|
|
250
|
+
})
|
|
251
|
+
})
|
|
252
|
+
})
|
|
253
|
+
|
|
254
|
+
describe('UpdateCredentialParamsSchema', () => {
|
|
255
|
+
const validUuid = 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'
|
|
256
|
+
|
|
257
|
+
it('accepts valid UUID', () => {
|
|
258
|
+
const result = UpdateCredentialParamsSchema.parse({ credentialId: validUuid })
|
|
259
|
+
expect(result.credentialId).toBe(validUuid)
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
it('rejects invalid UUID format', () => {
|
|
263
|
+
expect(() => UpdateCredentialParamsSchema.parse({ credentialId: 'not-a-uuid' })).toThrow()
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
it('rejects empty string', () => {
|
|
267
|
+
expect(() => UpdateCredentialParamsSchema.parse({ credentialId: '' })).toThrow()
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
it('rejects number instead of UUID', () => {
|
|
271
|
+
expect(() => UpdateCredentialParamsSchema.parse({ credentialId: 12345 })).toThrow()
|
|
272
|
+
})
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
describe('UpdateCredentialRequestSchema', () => {
|
|
276
|
+
const validValue = { apiKey: 'updated-key' }
|
|
277
|
+
const validName = 'updated-name'
|
|
278
|
+
|
|
279
|
+
describe('valid requests', () => {
|
|
280
|
+
it('accepts update with value only', () => {
|
|
281
|
+
const result = UpdateCredentialRequestSchema.parse({ value: validValue })
|
|
282
|
+
expect(result.value).toEqual(validValue)
|
|
283
|
+
expect(result.name).toBeUndefined()
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
it('accepts update with name only', () => {
|
|
287
|
+
const result = UpdateCredentialRequestSchema.parse({ name: validName })
|
|
288
|
+
expect(result.name).toBe(validName)
|
|
289
|
+
expect(result.value).toBeUndefined()
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
it('accepts update with both value and name', () => {
|
|
293
|
+
const result = UpdateCredentialRequestSchema.parse({ value: validValue, name: validName })
|
|
294
|
+
expect(result.value).toEqual(validValue)
|
|
295
|
+
expect(result.name).toBe(validName)
|
|
296
|
+
})
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
describe('SECURITY: strict mode', () => {
|
|
300
|
+
it('rejects unknown fields', () => {
|
|
301
|
+
const payload = { value: validValue, unknownField: 'test' }
|
|
302
|
+
expect(() => UpdateCredentialRequestSchema.parse(payload)).toThrow()
|
|
303
|
+
})
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
describe('validation: at least one field required', () => {
|
|
307
|
+
it('rejects empty update (no fields)', () => {
|
|
308
|
+
expect(() => UpdateCredentialRequestSchema.parse({})).toThrow(/At least one field/)
|
|
309
|
+
})
|
|
310
|
+
|
|
311
|
+
it('rejects update with undefined fields only', () => {
|
|
312
|
+
expect(() => UpdateCredentialRequestSchema.parse({ value: undefined, name: undefined })).toThrow(
|
|
313
|
+
/At least one field/
|
|
314
|
+
)
|
|
315
|
+
})
|
|
316
|
+
})
|
|
317
|
+
|
|
318
|
+
describe('SECURITY: credential value validation', () => {
|
|
319
|
+
it('rejects empty value object', () => {
|
|
320
|
+
expect(() => UpdateCredentialRequestSchema.parse({ value: {} })).toThrow(/must not be empty/)
|
|
321
|
+
})
|
|
322
|
+
|
|
323
|
+
it('rejects value with too many keys', () => {
|
|
324
|
+
const largeValue = Object.fromEntries(Array.from({ length: 51 }, (_, i) => [`key${i}`, 'value']))
|
|
325
|
+
expect(() => UpdateCredentialRequestSchema.parse({ value: largeValue })).toThrow(/too many keys/)
|
|
326
|
+
})
|
|
327
|
+
|
|
328
|
+
it('rejects individual string values over 10KB', () => {
|
|
329
|
+
const hugeString = 'a'.repeat(10241)
|
|
330
|
+
expect(() => UpdateCredentialRequestSchema.parse({ value: { apiKey: hugeString } })).toThrow(/too large/)
|
|
331
|
+
})
|
|
332
|
+
})
|
|
333
|
+
|
|
334
|
+
describe('SECURITY: credential name validation', () => {
|
|
335
|
+
it('rejects invalid name format', () => {
|
|
336
|
+
expect(() => UpdateCredentialRequestSchema.parse({ name: 'gmail prod' })).toThrow(/must be lowercase/)
|
|
337
|
+
})
|
|
338
|
+
|
|
339
|
+
it('rejects path traversal in name', () => {
|
|
340
|
+
expect(() => UpdateCredentialRequestSchema.parse({ name: '../admin' })).toThrow(/must be lowercase/)
|
|
341
|
+
})
|
|
342
|
+
})
|
|
343
|
+
})
|
|
344
|
+
|
|
345
|
+
describe('DeleteCredentialParamsSchema', () => {
|
|
346
|
+
const validUuid = 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'
|
|
347
|
+
|
|
348
|
+
it('accepts valid UUID', () => {
|
|
349
|
+
const result = DeleteCredentialParamsSchema.parse({ credentialId: validUuid })
|
|
350
|
+
expect(result.credentialId).toBe(validUuid)
|
|
351
|
+
})
|
|
352
|
+
|
|
353
|
+
it('rejects invalid UUID format', () => {
|
|
354
|
+
expect(() => DeleteCredentialParamsSchema.parse({ credentialId: 'not-a-uuid' })).toThrow()
|
|
355
|
+
})
|
|
356
|
+
|
|
357
|
+
it('rejects empty string', () => {
|
|
358
|
+
expect(() => DeleteCredentialParamsSchema.parse({ credentialId: '' })).toThrow()
|
|
359
|
+
})
|
|
360
|
+
})
|
|
361
|
+
|
|
362
|
+
describe('ListCredentialsResponseSchema - Provider Field', () => {
|
|
363
|
+
const validUuid = 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'
|
|
364
|
+
|
|
365
|
+
it('validates response with provider set', () => {
|
|
366
|
+
const response = {
|
|
367
|
+
credentials: [
|
|
368
|
+
{
|
|
369
|
+
id: validUuid,
|
|
370
|
+
name: 'dropbox-cred',
|
|
371
|
+
type: 'oauth',
|
|
372
|
+
provider: 'dropbox',
|
|
373
|
+
createdAt: '2026-02-02T00:00:00.000Z'
|
|
374
|
+
}
|
|
375
|
+
]
|
|
376
|
+
}
|
|
377
|
+
const result = ListCredentialsResponseSchema.parse(response)
|
|
378
|
+
expect(result.credentials[0].provider).toBe('dropbox')
|
|
379
|
+
})
|
|
380
|
+
|
|
381
|
+
it('validates response with null provider (non-OAuth credentials)', () => {
|
|
382
|
+
const response = {
|
|
383
|
+
credentials: [
|
|
384
|
+
{
|
|
385
|
+
id: validUuid,
|
|
386
|
+
name: 'api-key',
|
|
387
|
+
type: 'api-key',
|
|
388
|
+
provider: null,
|
|
389
|
+
createdAt: '2026-02-02T00:00:00.000Z'
|
|
390
|
+
}
|
|
391
|
+
]
|
|
392
|
+
}
|
|
393
|
+
const result = ListCredentialsResponseSchema.parse(response)
|
|
394
|
+
expect(result.credentials[0].provider).toBeNull()
|
|
395
|
+
})
|
|
396
|
+
|
|
397
|
+
it('validates response with mixed provider values', () => {
|
|
398
|
+
const response = {
|
|
399
|
+
credentials: [
|
|
400
|
+
{
|
|
401
|
+
id: validUuid,
|
|
402
|
+
name: 'dropbox-cred',
|
|
403
|
+
type: 'oauth',
|
|
404
|
+
provider: 'dropbox',
|
|
405
|
+
createdAt: '2026-02-02T00:00:00.000Z'
|
|
406
|
+
},
|
|
407
|
+
{
|
|
408
|
+
id: 'b0eebc99-9c0b-4ef8-bb6d-6bb9bd380a22',
|
|
409
|
+
name: 'api-key',
|
|
410
|
+
type: 'api-key',
|
|
411
|
+
provider: null,
|
|
412
|
+
createdAt: '2026-02-02T00:00:00.000Z'
|
|
413
|
+
}
|
|
414
|
+
]
|
|
415
|
+
}
|
|
416
|
+
const result = ListCredentialsResponseSchema.parse(response)
|
|
417
|
+
expect(result.credentials[0].provider).toBe('dropbox')
|
|
418
|
+
expect(result.credentials[1].provider).toBeNull()
|
|
419
|
+
})
|
|
420
|
+
})
|