plugin-git-manager 1.2.27 → 1.3.1
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/README.md +151 -108
- package/client-v2.d.ts +2 -2
- package/client-v2.js +1 -1
- package/client.d.ts +3 -3
- package/client.js +1 -1
- package/dist/client/{326.90c276058682b536.js → 313.d38fc1d40c4589b9.js} +1 -1
- package/dist/client/941.1793e67472872992.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/156.445366026c1cc9a8.js +10 -0
- package/dist/client-v2/{326.42b7b53651ffab3a.js → 313.3c867179c3a1e817.js} +1 -1
- package/dist/client-v2/434.19c7579c06b9077c.js +10 -0
- package/dist/client-v2/928.bba701b5a1ece58e.js +10 -0
- package/dist/client-v2/941.b0d55429cd053f32.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +9 -8
- package/dist/locale/en-US.json +396 -297
- package/dist/locale/vi-VN.json +384 -292
- package/dist/locale/zh-CN.json +150 -51
- package/dist/node_modules/simple-git/dist/cjs/index.js +25 -25
- package/dist/node_modules/simple-git/package.json +1 -1
- package/dist/node_modules/zod/index.cjs +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/actions/git-actions.js +90 -36
- package/dist/server/actions/gitlab-api.js +4 -2
- package/dist/server/actions/poller.js +5 -2
- package/dist/server/actions/review-cutover.js +137 -0
- package/dist/server/actions/review.js +150 -51
- package/dist/server/actions/role-permissions.js +1 -0
- package/dist/server/ai-tools.js +8 -9
- package/dist/server/collections/gitCodeReviews.js +10 -0
- package/dist/server/collections/gitReviewCutover.js +44 -0
- package/dist/server/collections/gitReviewFlows.js +3 -0
- package/dist/server/collections/gitReviewInbox.js +51 -0
- package/dist/server/collections/gitReviewProjects.js +43 -0
- package/dist/server/collections/gitReviewRequests.js +56 -0
- package/dist/server/index.js +8 -2
- package/dist/server/plugin.js +57 -20
- package/dist/server/poller.js +95 -74
- package/dist/server/repository-access.js +23 -5
- package/dist/server/request-method-policy.js +76 -0
- package/dist/server/review-control-access.js +79 -0
- package/dist/server/services/legacy-post-service.js +412 -0
- package/dist/server/services/registry-content-service.js +4 -3
- package/dist/server/services/review-service.js +1451 -0
- package/dist/server/services/review-source.js +325 -0
- package/dist/server/utils/get-repo-account.js +3 -2
- package/dist/server/utils/url-security.js +24 -0
- package/package.json +61 -43
- package/server.d.ts +2 -2
- package/server.js +1 -1
- package/src/client/__tests__/CommitHistory.test.tsx +79 -0
- package/src/client/__tests__/ReviewHistory.test.tsx +126 -0
- package/src/client/__tests__/RunReviewButton.test.tsx +84 -0
- package/src/client/__tests__/workflowRoutes.test.ts +65 -0
- package/src/client/ai-context.tsx +114 -114
- package/src/client/components/AIEmployeeSelect.tsx +63 -63
- package/src/client/components/CommitHistory.tsx +429 -374
- package/src/client/components/FileExplorer.tsx +386 -386
- package/src/client/components/GitAccounts.tsx +179 -179
- package/src/client/components/GitManagerSettings.tsx +160 -160
- package/src/client/components/GitOperations.tsx +220 -220
- package/src/client/components/LLMModelSelect.tsx +63 -63
- package/src/client/components/LLMServiceSelect.tsx +58 -58
- package/src/client/components/MarkdownView.tsx +80 -80
- package/src/client/components/MergeRequests.tsx +790 -790
- package/src/client/components/PollingStatus.tsx +225 -225
- package/src/client/components/RepositoryConfig.tsx +335 -335
- package/src/client/components/RepositoryPermissions.tsx +123 -123
- package/src/client/components/ReviewFlows.tsx +352 -303
- package/src/client/components/ReviewHistory.tsx +796 -566
- package/src/client/components/RunReviewButton.tsx +57 -173
- package/src/client/context/GitManagerContext.tsx +92 -92
- package/src/client/index.tsx +91 -82
- package/src/client/locale.ts +9 -9
- package/src/client/promptTemplates.ts +31 -31
- package/src/client/workflowRoutes.ts +42 -0
- package/src/client-v2/ai-context.tsx +99 -0
- package/src/client-v2/components/SubtreeSplits.tsx +547 -547
- package/src/client-v2/index.tsx +1 -1
- package/src/client-v2/locale.ts +8 -8
- package/src/client-v2/plugin.tsx +67 -39
- package/src/index.ts +2 -2
- package/src/locale/en-US.json +396 -297
- package/src/locale/vi-VN.json +384 -292
- package/src/locale/zh-CN.json +150 -51
- package/src/server/__tests__/git-actions.test.ts +24 -24
- package/src/server/__tests__/git-security.test.ts +170 -0
- package/src/server/__tests__/plugin-url-security.test.ts +17 -17
- package/src/server/__tests__/poller-lifecycle.test.ts +71 -0
- package/src/server/__tests__/poller.test.ts +37 -37
- package/src/server/__tests__/repository-access.test.ts +760 -752
- package/src/server/__tests__/review-service.integration.test.ts +1263 -0
- package/src/server/__tests__/review.test.ts +76 -137
- package/src/server/__tests__/role-permissions.test.ts +147 -147
- package/src/server/__tests__/smoke.test.ts +139 -17
- package/src/server/__tests__/subtree.test.ts +85 -85
- package/src/server/actions/git-actions.ts +540 -480
- package/src/server/actions/gitlab-api.ts +422 -411
- package/src/server/actions/poller.ts +39 -27
- package/src/server/actions/review-cutover.ts +121 -0
- package/src/server/actions/review.ts +1498 -1369
- package/src/server/actions/role-permissions.ts +331 -321
- package/src/server/actions/subtree.ts +508 -508
- package/src/server/ai-tools.ts +334 -319
- package/src/server/collections/gitAccounts.ts +56 -56
- package/src/server/collections/gitCodeReviews.ts +218 -199
- package/src/server/collections/gitRepositories.ts +87 -87
- package/src/server/collections/gitReviewCutover.ts +23 -0
- package/src/server/collections/gitReviewFlows.ts +120 -108
- package/src/server/collections/gitReviewInbox.ts +30 -0
- package/src/server/collections/gitReviewProjects.ts +22 -0
- package/src/server/collections/gitReviewRequests.ts +35 -0
- package/src/server/collections/gitSubtreeConfigs.ts +38 -38
- package/src/server/collections/gitSubtreeRuns.ts +30 -30
- package/src/server/index.ts +14 -2
- package/src/server/migrations/20260508000000-add-auto-review-flow-id.ts +29 -29
- package/src/server/migrations/20260712000000-add-git-accounts.ts +198 -198
- package/src/server/migrations/20260730000000-migrate-legacy-repository-permissions.ts +81 -81
- package/src/server/plugin.ts +409 -361
- package/src/server/poller.ts +365 -352
- package/src/server/repository-access.ts +803 -773
- package/src/server/request-method-policy.ts +56 -0
- package/src/server/review-control-access.ts +71 -0
- package/src/server/services/__tests__/registry-content-service.test.ts +359 -345
- package/src/server/services/__tests__/review-source.test.ts +226 -0
- package/src/server/services/legacy-post-service.ts +550 -0
- package/src/server/services/registry-content-service.ts +495 -484
- package/src/server/services/review-service.ts +1899 -0
- package/src/server/services/review-source.ts +359 -0
- package/src/server/utils/__tests__/redact.test.ts +56 -56
- package/src/server/utils/__tests__/url-security.test.ts +85 -85
- package/src/server/utils/get-repo-account.ts +51 -41
- package/src/server/utils/gitlab-url.ts +38 -38
- package/src/server/utils/redact.ts +87 -87
- package/src/server/utils/url-security.ts +128 -95
- package/dist/client/900.acf7d1fa22f95e71.js +0 -10
- package/dist/client-v2/434.7a27051db18526c0.js +0 -10
- package/dist/client-v2/900.f32b9dc85249fc0a.js +0 -10
|
@@ -1,752 +1,760 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
it('allows
|
|
132
|
-
const ctx = createContext(10, { id: 10 });
|
|
133
|
-
const next = vi.fn().mockResolvedValue(undefined);
|
|
134
|
-
|
|
135
|
-
await enforceRepositoryAccess(ctx, next);
|
|
136
|
-
|
|
137
|
-
expect(next).toHaveBeenCalledTimes(1);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it('allows a repository represented by
|
|
141
|
-
const ctx = createContext(10, { id:
|
|
142
|
-
const next = vi.fn().mockResolvedValue(undefined);
|
|
143
|
-
|
|
144
|
-
await enforceRepositoryAccess(ctx, next);
|
|
145
|
-
|
|
146
|
-
expect(next).toHaveBeenCalledTimes(1);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it('
|
|
150
|
-
const ctx = createContext(
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
await enforceRepositoryAccess(ctx,
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const next = vi.fn().mockResolvedValue(undefined);
|
|
169
|
-
|
|
170
|
-
await enforceRepositoryAccess(ctx, next);
|
|
171
|
-
|
|
172
|
-
expect(next).toHaveBeenCalledTimes(1);
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
it('
|
|
242
|
-
const { context } = createActionContext({
|
|
243
|
-
actionName: 'pollNow',
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
expect(
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
it('
|
|
261
|
-
const { context } = createActionContext({ actionName: '
|
|
262
|
-
|
|
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
|
-
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
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
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
const
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
const
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
const
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { enforceRepositoryAccess, enforceRepositoryCollectionAccess } from '../repository-access';
|
|
11
|
+
import { vi } from 'vitest';
|
|
12
|
+
|
|
13
|
+
function createContext(repositoryId: number, filter?: unknown, roles = ['developer']) {
|
|
14
|
+
const throwError = vi.fn((status: number, message: string) => {
|
|
15
|
+
const error = new Error(message) as Error & { status: number };
|
|
16
|
+
error.status = status;
|
|
17
|
+
throw error;
|
|
18
|
+
});
|
|
19
|
+
return {
|
|
20
|
+
action: { resourceName: 'gitManager', actionName: 'fileTree', params: { repositoryId } },
|
|
21
|
+
state: { currentRoles: roles },
|
|
22
|
+
app: {
|
|
23
|
+
acl: {
|
|
24
|
+
can: vi.fn().mockResolvedValue({ params: filter === undefined ? {} : { filter } }),
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
throw: throwError,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function createActionContext(input: {
|
|
32
|
+
actionName: string;
|
|
33
|
+
params?: Record<string, unknown>;
|
|
34
|
+
requestBody?: Record<string, unknown>;
|
|
35
|
+
query?: Record<string, unknown>;
|
|
36
|
+
requestQuery?: Record<string, unknown>;
|
|
37
|
+
filter?: unknown;
|
|
38
|
+
roles?: string[];
|
|
39
|
+
configRepositoryId?: number;
|
|
40
|
+
reviewRepositoryId?: number;
|
|
41
|
+
}) {
|
|
42
|
+
const throwError = vi.fn((status: number, message: string) => {
|
|
43
|
+
const error = new Error(message) as Error & { status: number };
|
|
44
|
+
error.status = status;
|
|
45
|
+
throw error;
|
|
46
|
+
});
|
|
47
|
+
const configFindOne = vi
|
|
48
|
+
.fn()
|
|
49
|
+
.mockResolvedValue(
|
|
50
|
+
input.configRepositoryId === undefined ? null : { get: (attribute: string) => input.configRepositoryId },
|
|
51
|
+
);
|
|
52
|
+
const reviewFindOne = vi
|
|
53
|
+
.fn()
|
|
54
|
+
.mockResolvedValue(
|
|
55
|
+
input.reviewRepositoryId === undefined ? null : { get: (attribute: string) => input.reviewRepositoryId },
|
|
56
|
+
);
|
|
57
|
+
const getRepository = vi.fn((name: string) => {
|
|
58
|
+
if (name === 'gitSubtreeConfigs') return { findOne: configFindOne };
|
|
59
|
+
if (name === 'gitCodeReviews') return { findOne: reviewFindOne };
|
|
60
|
+
throw new Error(`Unexpected repository ${name}`);
|
|
61
|
+
});
|
|
62
|
+
const context = {
|
|
63
|
+
action: { resourceName: 'gitManager', actionName: input.actionName, params: input.params || {} },
|
|
64
|
+
...(input.requestBody ? { request: { body: input.requestBody } } : {}),
|
|
65
|
+
state: { currentRoles: input.roles || ['developer'] },
|
|
66
|
+
db: { getRepository },
|
|
67
|
+
app: {
|
|
68
|
+
acl: {
|
|
69
|
+
can: vi.fn().mockResolvedValue({ params: input.filter === undefined ? {} : { filter: input.filter } }),
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
throw: throwError,
|
|
73
|
+
};
|
|
74
|
+
return { context, configFindOne, reviewFindOne };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function createCollectionContext(input: {
|
|
78
|
+
resourceName: string;
|
|
79
|
+
actionName: string;
|
|
80
|
+
params?: Record<string, unknown>;
|
|
81
|
+
requestBody?: unknown;
|
|
82
|
+
filter?: unknown;
|
|
83
|
+
roles?: string[];
|
|
84
|
+
configRepositoryId?: number;
|
|
85
|
+
}) {
|
|
86
|
+
const throwError = vi.fn((status: number, message: string) => {
|
|
87
|
+
const error = new Error(message) as Error & { status: number };
|
|
88
|
+
error.status = status;
|
|
89
|
+
throw error;
|
|
90
|
+
});
|
|
91
|
+
const mergeParams = vi.fn();
|
|
92
|
+
const configFindOne = vi
|
|
93
|
+
.fn()
|
|
94
|
+
.mockResolvedValue(
|
|
95
|
+
input.configRepositoryId === undefined ? null : { get: (attribute: string) => input.configRepositoryId },
|
|
96
|
+
);
|
|
97
|
+
const context = {
|
|
98
|
+
action: {
|
|
99
|
+
resourceName: input.resourceName,
|
|
100
|
+
actionName: input.actionName,
|
|
101
|
+
params: input.params || {},
|
|
102
|
+
mergeParams,
|
|
103
|
+
},
|
|
104
|
+
...(input.query ? { query: input.query } : {}),
|
|
105
|
+
...(input.requestBody || input.requestQuery
|
|
106
|
+
? {
|
|
107
|
+
request: {
|
|
108
|
+
...(input.requestBody ? { body: input.requestBody } : {}),
|
|
109
|
+
...(input.requestQuery ? { query: input.requestQuery } : {}),
|
|
110
|
+
},
|
|
111
|
+
}
|
|
112
|
+
: {}),
|
|
113
|
+
state: { currentRoles: input.roles || ['developer'] },
|
|
114
|
+
db: {
|
|
115
|
+
getRepository: vi.fn((name: string) => {
|
|
116
|
+
if (name === 'gitSubtreeConfigs') return { findOne: configFindOne };
|
|
117
|
+
throw new Error(`Unexpected repository ${name}`);
|
|
118
|
+
}),
|
|
119
|
+
},
|
|
120
|
+
app: {
|
|
121
|
+
acl: {
|
|
122
|
+
can: vi.fn().mockResolvedValue({ params: input.filter === undefined ? {} : { filter: input.filter } }),
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
throw: throwError,
|
|
126
|
+
};
|
|
127
|
+
return { context, mergeParams, configFindOne };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
describe('Git Manager repository access', () => {
|
|
131
|
+
it('allows the repository included in the role scope', async () => {
|
|
132
|
+
const ctx = createContext(10, { $and: [{ id: { $in: [10] } }] });
|
|
133
|
+
const next = vi.fn().mockResolvedValue(undefined);
|
|
134
|
+
|
|
135
|
+
await enforceRepositoryAccess(ctx, next);
|
|
136
|
+
|
|
137
|
+
expect(next).toHaveBeenCalledTimes(1);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('allows a repository represented by a legacy direct id scope', async () => {
|
|
141
|
+
const ctx = createContext(10, { id: 10 });
|
|
142
|
+
const next = vi.fn().mockResolvedValue(undefined);
|
|
143
|
+
|
|
144
|
+
await enforceRepositoryAccess(ctx, next);
|
|
145
|
+
|
|
146
|
+
expect(next).toHaveBeenCalledTimes(1);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('allows a repository represented by an equality scope', async () => {
|
|
150
|
+
const ctx = createContext(10, { id: { $eq: '10' } });
|
|
151
|
+
const next = vi.fn().mockResolvedValue(undefined);
|
|
152
|
+
|
|
153
|
+
await enforceRepositoryAccess(ctx, next);
|
|
154
|
+
|
|
155
|
+
expect(next).toHaveBeenCalledTimes(1);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('rejects another repository outside the role scope', async () => {
|
|
159
|
+
const ctx = createContext(20, { $and: [{ id: { $in: [10] } }] });
|
|
160
|
+
|
|
161
|
+
await expect(enforceRepositoryAccess(ctx, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('accepts a repository granted by one of multiple roles', async () => {
|
|
165
|
+
const ctx = createContext(20, {
|
|
166
|
+
$or: [{ $and: [{ id: { $in: [10] } }] }, { $and: [{ id: { $in: [20] } }] }],
|
|
167
|
+
});
|
|
168
|
+
const next = vi.fn().mockResolvedValue(undefined);
|
|
169
|
+
|
|
170
|
+
await enforceRepositoryAccess(ctx, next);
|
|
171
|
+
|
|
172
|
+
expect(next).toHaveBeenCalledTimes(1);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('allows root without evaluating repository scope', async () => {
|
|
176
|
+
const ctx = createContext(20, { $and: [{ id: { $in: [10] } }] }, ['root']);
|
|
177
|
+
const next = vi.fn().mockResolvedValue(undefined);
|
|
178
|
+
|
|
179
|
+
await enforceRepositoryAccess(ctx, next);
|
|
180
|
+
|
|
181
|
+
expect(next).toHaveBeenCalledTimes(1);
|
|
182
|
+
expect(ctx.app.acl.can).not.toHaveBeenCalled();
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('checks the repository ID from a request body and lets the body override URL params', async () => {
|
|
186
|
+
const { context } = createActionContext({
|
|
187
|
+
actionName: 'triggerReview',
|
|
188
|
+
params: { repositoryId: 10 },
|
|
189
|
+
requestBody: { repositoryId: 20 },
|
|
190
|
+
filter: { id: { $in: [10] } },
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
await expect(enforceRepositoryAccess(context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
194
|
+
expect(context.app.acl.can).toHaveBeenCalledWith({
|
|
195
|
+
roles: ['developer'],
|
|
196
|
+
resource: 'gitManager',
|
|
197
|
+
action: 'triggerReview',
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('checks the repository ID from the action values envelope', async () => {
|
|
202
|
+
const { context } = createActionContext({
|
|
203
|
+
actionName: 'subtreeOptions',
|
|
204
|
+
params: { values: { repositoryId: 20 } },
|
|
205
|
+
filter: { id: { $in: [10] } },
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
await expect(enforceRepositoryAccess(context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it.each(['subtreePreview', 'subtreeRun', 'subtreeReplace'])(
|
|
212
|
+
'resolves the repository scope from a subtree config for %s',
|
|
213
|
+
async (actionName) => {
|
|
214
|
+
const { context, configFindOne } = createActionContext({
|
|
215
|
+
actionName,
|
|
216
|
+
requestBody: { configId: 8 },
|
|
217
|
+
configRepositoryId: 20,
|
|
218
|
+
filter: { id: { $in: [10] } },
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
await expect(enforceRepositoryAccess(context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
222
|
+
expect(configFindOne).toHaveBeenCalledWith({ filterByTk: 8 });
|
|
223
|
+
},
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
it.each(['reviewApprovePost', 'reviewReject'])(
|
|
227
|
+
'resolves the repository scope from a code review for %s',
|
|
228
|
+
async (actionName) => {
|
|
229
|
+
const { context, reviewFindOne } = createActionContext({
|
|
230
|
+
actionName,
|
|
231
|
+
params: { values: { reviewId: 7 } },
|
|
232
|
+
reviewRepositoryId: 20,
|
|
233
|
+
filter: { id: { $in: [10] } },
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
await expect(enforceRepositoryAccess(context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
237
|
+
expect(reviewFindOne).toHaveBeenCalledWith({ filterByTk: 7 });
|
|
238
|
+
},
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
it('denies a scoped role from polling every repository', async () => {
|
|
242
|
+
const { context } = createActionContext({
|
|
243
|
+
actionName: 'pollNow',
|
|
244
|
+
filter: { id: { $in: [10] } },
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
await expect(enforceRepositoryAccess(context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it('checks a poll target supplied in the request body', async () => {
|
|
251
|
+
const { context } = createActionContext({
|
|
252
|
+
actionName: 'pollNow',
|
|
253
|
+
requestBody: { repositoryId: 20 },
|
|
254
|
+
filter: { id: { $in: [10] } },
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
await expect(enforceRepositoryAccess(context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('allows polling every repository only with an unscoped permission', async () => {
|
|
261
|
+
const { context } = createActionContext({ actionName: 'pollNow' });
|
|
262
|
+
const next = vi.fn().mockResolvedValue(undefined);
|
|
263
|
+
|
|
264
|
+
await enforceRepositoryAccess(context, next);
|
|
265
|
+
|
|
266
|
+
expect(next).toHaveBeenCalledTimes(1);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it('fails closed when a repository-scoped action has no repository ID', async () => {
|
|
270
|
+
const { context } = createActionContext({ actionName: 'fileTree', filter: { id: { $in: [10] } } });
|
|
271
|
+
|
|
272
|
+
await expect(enforceRepositoryAccess(context, vi.fn())).rejects.toMatchObject({ status: 400 });
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
describe('Git Manager repository collection access', () => {
|
|
277
|
+
it.each([
|
|
278
|
+
['gitCodeReviews', { repositoryId: { $in: [10] } }],
|
|
279
|
+
['gitReviewFlows', { repositoryId: { $in: [10] } }],
|
|
280
|
+
['gitSubtreeConfigs', { repositoryId: { $in: [10] } }],
|
|
281
|
+
['gitSubtreeRuns', { config: { repositoryId: { $in: [10] } } }],
|
|
282
|
+
['gitRepositories', { id: { $in: [10] } }],
|
|
283
|
+
])('merges repository scope into %s collection reads', async (resourceName, expectedFilter) => {
|
|
284
|
+
const { context, mergeParams } = createCollectionContext({
|
|
285
|
+
resourceName,
|
|
286
|
+
actionName: 'list',
|
|
287
|
+
filter: { id: { $in: [10] } },
|
|
288
|
+
});
|
|
289
|
+
const next = vi.fn().mockResolvedValue(undefined);
|
|
290
|
+
|
|
291
|
+
await enforceRepositoryCollectionAccess(context, next);
|
|
292
|
+
|
|
293
|
+
expect(mergeParams).toHaveBeenCalledWith({ filter: expectedFilter });
|
|
294
|
+
expect(next).toHaveBeenCalledOnce();
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it('rejects a scoped repository read that appends gitAccount from action params', async () => {
|
|
298
|
+
const { context, mergeParams } = createCollectionContext({
|
|
299
|
+
resourceName: 'gitRepositories',
|
|
300
|
+
actionName: 'list',
|
|
301
|
+
params: { appends: ['gitAccount'] },
|
|
302
|
+
filter: { id: { $in: [10] } },
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
await expect(enforceRepositoryCollectionAccess(context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
306
|
+
expect(mergeParams).not.toHaveBeenCalled();
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it('rejects an option-suffixed gitAccount append from action params', async () => {
|
|
310
|
+
const { context, mergeParams } = createCollectionContext({
|
|
311
|
+
resourceName: 'gitRepositories',
|
|
312
|
+
actionName: 'list',
|
|
313
|
+
params: { appends: 'gitAccount(recursively=true)' },
|
|
314
|
+
filter: { id: { $in: [10] } },
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
await expect(enforceRepositoryCollectionAccess(context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
318
|
+
expect(mergeParams).not.toHaveBeenCalled();
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it('rejects a scoped repository read that appends gitAccount from the request body', async () => {
|
|
322
|
+
const { context, mergeParams } = createCollectionContext({
|
|
323
|
+
resourceName: 'gitRepositories',
|
|
324
|
+
actionName: 'get',
|
|
325
|
+
requestBody: { appends: ['gitAccount'] },
|
|
326
|
+
filter: { id: { $in: [10] } },
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
await expect(enforceRepositoryCollectionAccess(context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
330
|
+
expect(mergeParams).not.toHaveBeenCalled();
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
it('rejects an ORM-style gitAccount include inside the action values envelope', async () => {
|
|
334
|
+
const { context, mergeParams } = createCollectionContext({
|
|
335
|
+
resourceName: 'gitRepositories',
|
|
336
|
+
actionName: 'list',
|
|
337
|
+
params: { values: { include: [{ association: 'gitAccount' }] } },
|
|
338
|
+
filter: { id: { $in: [10] } },
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
await expect(enforceRepositoryCollectionAccess(context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
342
|
+
expect(mergeParams).not.toHaveBeenCalled();
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
it('rejects a credential relation field path for a scoped repository read', async () => {
|
|
346
|
+
const { context, mergeParams } = createCollectionContext({
|
|
347
|
+
resourceName: 'gitRepositories',
|
|
348
|
+
actionName: 'list',
|
|
349
|
+
params: { fields: ['id', 'gitAccount.pat'] },
|
|
350
|
+
filter: { id: { $in: [10] } },
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
await expect(enforceRepositoryCollectionAccess(context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
354
|
+
expect(mergeParams).not.toHaveBeenCalled();
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
it.each([
|
|
358
|
+
['ctx.query', { query: { appends: 'gitAccount' } }],
|
|
359
|
+
['ctx.request.query', { requestQuery: { appends: 'gitAccount' } }],
|
|
360
|
+
])('rejects a credential append supplied through %s', async (_source, queryInput) => {
|
|
361
|
+
const { context, mergeParams } = createCollectionContext({
|
|
362
|
+
resourceName: 'gitRepositories',
|
|
363
|
+
actionName: 'list',
|
|
364
|
+
...queryInput,
|
|
365
|
+
filter: { id: { $in: [10] } },
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
await expect(enforceRepositoryCollectionAccess(context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
369
|
+
expect(mergeParams).not.toHaveBeenCalled();
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
it.each([
|
|
373
|
+
['gitReviewFlows', 'repository.gitAccount'],
|
|
374
|
+
['gitCodeReviews', 'repository.gitAccount'],
|
|
375
|
+
['gitSubtreeConfigs', 'repository.gitAccount'],
|
|
376
|
+
['gitSubtreeRuns', 'config.repository.gitAccount'],
|
|
377
|
+
])('rejects a credential append through scoped %s reads', async (resourceName, credentialPath) => {
|
|
378
|
+
const { context, mergeParams } = createCollectionContext({
|
|
379
|
+
resourceName,
|
|
380
|
+
actionName: 'list',
|
|
381
|
+
params: { appends: [credentialPath] },
|
|
382
|
+
filter: { id: { $in: [10] } },
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
await expect(enforceRepositoryCollectionAccess(context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
386
|
+
expect(mergeParams).not.toHaveBeenCalled();
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
it.each(['gitRepositories.10.gitAccount', 'gitAccounts.2.repositories'])(
|
|
390
|
+
'rejects a scoped credential association route %s',
|
|
391
|
+
async (resourceName) => {
|
|
392
|
+
const { context, mergeParams } = createCollectionContext({
|
|
393
|
+
resourceName,
|
|
394
|
+
actionName: 'list',
|
|
395
|
+
filter: { id: { $in: [10] } },
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
await expect(enforceRepositoryCollectionAccess(context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
399
|
+
expect(mergeParams).not.toHaveBeenCalled();
|
|
400
|
+
},
|
|
401
|
+
);
|
|
402
|
+
|
|
403
|
+
it('allows safe relation appends and preserves unscoped and root reads', async () => {
|
|
404
|
+
const scoped = createCollectionContext({
|
|
405
|
+
resourceName: 'gitRepositories',
|
|
406
|
+
actionName: 'list',
|
|
407
|
+
params: { appends: ['autoReviewFlow'] },
|
|
408
|
+
filter: { id: { $in: [10] } },
|
|
409
|
+
});
|
|
410
|
+
const unrestricted = createCollectionContext({
|
|
411
|
+
resourceName: 'gitRepositories',
|
|
412
|
+
actionName: 'list',
|
|
413
|
+
params: { appends: ['gitAccount'] },
|
|
414
|
+
});
|
|
415
|
+
const root = createCollectionContext({
|
|
416
|
+
resourceName: 'gitRepositories',
|
|
417
|
+
actionName: 'list',
|
|
418
|
+
params: { appends: ['gitAccount'] },
|
|
419
|
+
filter: { id: { $in: [10] } },
|
|
420
|
+
roles: ['root'],
|
|
421
|
+
});
|
|
422
|
+
const next = vi.fn().mockResolvedValue(undefined);
|
|
423
|
+
|
|
424
|
+
await enforceRepositoryCollectionAccess(scoped.context, next);
|
|
425
|
+
await enforceRepositoryCollectionAccess(unrestricted.context, next);
|
|
426
|
+
await enforceRepositoryCollectionAccess(root.context, next);
|
|
427
|
+
|
|
428
|
+
expect(scoped.mergeParams).toHaveBeenCalledWith({ filter: { id: { $in: [10] } } });
|
|
429
|
+
expect(next).toHaveBeenCalledTimes(3);
|
|
430
|
+
expect(root.context.app.acl.can).not.toHaveBeenCalled();
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
it('keeps a zero-selection scope restrictive instead of falling back to a global collection action', async () => {
|
|
434
|
+
const { context, mergeParams } = createCollectionContext({
|
|
435
|
+
resourceName: 'gitCodeReviews',
|
|
436
|
+
actionName: 'destroy',
|
|
437
|
+
params: { filterByTk: 20 },
|
|
438
|
+
filter: { $and: [{ id: { $in: [] } }] },
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
await expect(enforceRepositoryCollectionAccess(context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
442
|
+
expect(mergeParams).not.toHaveBeenCalled();
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
it.each(['gitAccounts', 'gitCodeReviews'])(
|
|
446
|
+
'rejects a gitRepositories request that redirects to %s with targetCollection',
|
|
447
|
+
async (targetCollection) => {
|
|
448
|
+
const { context } = createCollectionContext({
|
|
449
|
+
resourceName: 'gitRepositories',
|
|
450
|
+
actionName: 'get',
|
|
451
|
+
params: { filterByTk: 10, targetCollection },
|
|
452
|
+
filter: { id: { $in: [10] } },
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
await expect(enforceRepositoryCollectionAccess(context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
456
|
+
},
|
|
457
|
+
);
|
|
458
|
+
|
|
459
|
+
it('rejects an association payload that redirects a scoped repository request', async () => {
|
|
460
|
+
const { context } = createCollectionContext({
|
|
461
|
+
resourceName: 'gitRepositories',
|
|
462
|
+
actionName: 'update',
|
|
463
|
+
params: { filterByTk: 10, values: { __collection: 'gitAccounts' } },
|
|
464
|
+
filter: { id: { $in: [10] } },
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
await expect(enforceRepositoryCollectionAccess(context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
it.each([
|
|
471
|
+
['request body', { gitAccountId: 2 }],
|
|
472
|
+
['request body', { gitAccount: { id: 2 } }],
|
|
473
|
+
['request body', { repoUrl: 'https://git.example.test/other/project.git' }],
|
|
474
|
+
['request body', { localPath: 'other-project' }],
|
|
475
|
+
['action values', { gitAccountId: 2 }],
|
|
476
|
+
['action values', { gitAccount: { id: 2 } }],
|
|
477
|
+
['action values', { repoUrl: 'https://git.example.test/other/project.git' }],
|
|
478
|
+
['action values', { localPath: 'other-project' }],
|
|
479
|
+
])('rejects a scoped repository connection mutation from %s', async (source, values) => {
|
|
480
|
+
const { context } = createCollectionContext({
|
|
481
|
+
resourceName: 'gitRepositories',
|
|
482
|
+
actionName: 'update',
|
|
483
|
+
...(source === 'request body' ? { requestBody: values } : { params: { values } }),
|
|
484
|
+
filter: { id: { $in: [10] } },
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
await expect(enforceRepositoryCollectionAccess(context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
it('rejects a dotted gitAccount mutation key from action params', async () => {
|
|
491
|
+
const { context } = createCollectionContext({
|
|
492
|
+
resourceName: 'gitRepositories',
|
|
493
|
+
actionName: 'update',
|
|
494
|
+
params: { 'gitAccount.id': 2 },
|
|
495
|
+
filter: { id: { $in: [10] } },
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
await expect(enforceRepositoryCollectionAccess(context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
it('rejects a bracket gitAccount mutation key from action values', async () => {
|
|
502
|
+
const { context } = createCollectionContext({
|
|
503
|
+
resourceName: 'gitRepositories',
|
|
504
|
+
actionName: 'update',
|
|
505
|
+
params: { values: { 'gitAccount[pat]': 'secret' } },
|
|
506
|
+
filter: { id: { $in: [10] } },
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
await expect(enforceRepositoryCollectionAccess(context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
it('rejects a quoted bracket gitAccount mutation key from action params', async () => {
|
|
513
|
+
const { context } = createCollectionContext({
|
|
514
|
+
resourceName: 'gitRepositories',
|
|
515
|
+
actionName: 'update',
|
|
516
|
+
params: { 'values["gitAccount"]["pat"]': 'secret' },
|
|
517
|
+
filter: { id: { $in: [10] } },
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
await expect(enforceRepositoryCollectionAccess(context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
it('rejects nested credential values in an association-update payload', async () => {
|
|
524
|
+
const { context } = createCollectionContext({
|
|
525
|
+
resourceName: 'gitRepositories',
|
|
526
|
+
actionName: 'update',
|
|
527
|
+
requestBody: { updateAssociationValues: { gitAccount: { id: 2 } } },
|
|
528
|
+
filter: { id: { $in: [10] } },
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
await expect(enforceRepositoryCollectionAccess(context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
it.each([
|
|
535
|
+
['dotted repoUrl', { 'repoUrl.value': 'https://git.example.test/other/project.git' }],
|
|
536
|
+
['bracket localPath', { 'localPath[0]': 'other-project' }],
|
|
537
|
+
])('rejects a scoped repository mutation using %s', async (_source, values) => {
|
|
538
|
+
const { context } = createCollectionContext({
|
|
539
|
+
resourceName: 'gitRepositories',
|
|
540
|
+
actionName: 'update',
|
|
541
|
+
params: { values },
|
|
542
|
+
filter: { id: { $in: [10] } },
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
await expect(enforceRepositoryCollectionAccess(context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
it.each([
|
|
549
|
+
['ctx.query', { query: { 'gitAccount.id': '2' } }],
|
|
550
|
+
['ctx.request.query', { requestQuery: { 'gitAccount[pat]': 'secret' } }],
|
|
551
|
+
])('rejects a credential mutation supplied through %s', async (_source, queryInput) => {
|
|
552
|
+
const { context } = createCollectionContext({
|
|
553
|
+
resourceName: 'gitRepositories',
|
|
554
|
+
actionName: 'update',
|
|
555
|
+
...queryInput,
|
|
556
|
+
filter: { id: { $in: [10] } },
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
await expect(enforceRepositoryCollectionAccess(context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
it.each([
|
|
563
|
+
['request body array', { requestBody: [{ id: 10 }, { id: 20 }] }],
|
|
564
|
+
['action values array', { params: { values: [{ id: 10 }, { id: 20 }] } }],
|
|
565
|
+
])('rejects a scoped bulk mutation from %s', async (_source, bulkInput) => {
|
|
566
|
+
const { context, mergeParams } = createCollectionContext({
|
|
567
|
+
resourceName: 'gitCodeReviews',
|
|
568
|
+
actionName: 'update',
|
|
569
|
+
...bulkInput,
|
|
570
|
+
filter: { id: { $in: [10] } },
|
|
571
|
+
});
|
|
572
|
+
|
|
573
|
+
await expect(enforceRepositoryCollectionAccess(context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
574
|
+
expect(mergeParams).not.toHaveBeenCalled();
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
it.each([
|
|
578
|
+
['create', { repositoryId: 10, flowId: 8 }],
|
|
579
|
+
['update', { metadata: { aiEmployeeUsername: 'admin-reviewer', userId: 1 } }],
|
|
580
|
+
['update', { status: 'pending' }],
|
|
581
|
+
])('rejects scoped generic gitCodeReviews %s mutations', async (actionName, values) => {
|
|
582
|
+
const { context, mergeParams } = createCollectionContext({
|
|
583
|
+
resourceName: 'gitCodeReviews',
|
|
584
|
+
actionName,
|
|
585
|
+
requestBody: values,
|
|
586
|
+
filter: { id: { $in: [10] } },
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
await expect(enforceRepositoryCollectionAccess(context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
590
|
+
expect(mergeParams).not.toHaveBeenCalled();
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
it('does not block the checked custom gitManager review actions', async () => {
|
|
594
|
+
const { context } = createCollectionContext({
|
|
595
|
+
resourceName: 'gitManager',
|
|
596
|
+
actionName: 'triggerReview',
|
|
597
|
+
params: { repositoryId: 10 },
|
|
598
|
+
filter: { id: { $in: [10] } },
|
|
599
|
+
});
|
|
600
|
+
const next = vi.fn().mockResolvedValue(undefined);
|
|
601
|
+
|
|
602
|
+
await enforceRepositoryCollectionAccess(context, next);
|
|
603
|
+
|
|
604
|
+
expect(next).toHaveBeenCalledOnce();
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
it.each([
|
|
608
|
+
['gitReviewFlows', 'dotted action params', { params: { 'repository.id': 20 } }],
|
|
609
|
+
['gitCodeReviews', 'bracket action values', { params: { values: { 'repository[id]': 20 } } }],
|
|
610
|
+
[
|
|
611
|
+
'gitSubtreeConfigs',
|
|
612
|
+
'nested request body',
|
|
613
|
+
{ requestBody: { updateAssociationValues: { repository: { id: 20 } } } },
|
|
614
|
+
],
|
|
615
|
+
])('rejects a scoped %s repository association mutation from %s', async (resourceName, _source, mutationInput) => {
|
|
616
|
+
const { context } = createCollectionContext({
|
|
617
|
+
resourceName,
|
|
618
|
+
actionName: 'update',
|
|
619
|
+
...mutationInput,
|
|
620
|
+
filter: { id: { $in: [10] } },
|
|
621
|
+
});
|
|
622
|
+
|
|
623
|
+
await expect(enforceRepositoryCollectionAccess(context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
it.each([
|
|
627
|
+
['dotted action params', { params: { 'config.id': 8 } }],
|
|
628
|
+
['bracket action values', { params: { values: { 'config[id]': 8 } } }],
|
|
629
|
+
['nested request body', { requestBody: { updateAssociationValues: { config: { id: 8 } } } }],
|
|
630
|
+
])('rejects a scoped subtree-run config association mutation from %s', async (_source, mutationInput) => {
|
|
631
|
+
const { context } = createCollectionContext({
|
|
632
|
+
resourceName: 'gitSubtreeRuns',
|
|
633
|
+
actionName: 'update',
|
|
634
|
+
...mutationInput,
|
|
635
|
+
filter: { id: { $in: [10] } },
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
await expect(enforceRepositoryCollectionAccess(context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
639
|
+
});
|
|
640
|
+
|
|
641
|
+
it.each([
|
|
642
|
+
['gitReviewFlows', { name: 'Flow 10' }],
|
|
643
|
+
['gitSubtreeConfigs', { name: 'Config 10' }],
|
|
644
|
+
['gitSubtreeRuns', { status: 'queued' }],
|
|
645
|
+
])('allows a scoped %s metadata update without association changes', async (resourceName, values) => {
|
|
646
|
+
const { context } = createCollectionContext({
|
|
647
|
+
resourceName,
|
|
648
|
+
actionName: 'update',
|
|
649
|
+
requestBody: values,
|
|
650
|
+
filter: { id: { $in: [10] } },
|
|
651
|
+
});
|
|
652
|
+
const next = vi.fn().mockResolvedValue(undefined);
|
|
653
|
+
|
|
654
|
+
await enforceRepositoryCollectionAccess(context, next);
|
|
655
|
+
|
|
656
|
+
expect(next).toHaveBeenCalledOnce();
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
it('allows a scoped repository metadata update', async () => {
|
|
660
|
+
const { context } = createCollectionContext({
|
|
661
|
+
resourceName: 'gitRepositories',
|
|
662
|
+
actionName: 'update',
|
|
663
|
+
requestBody: { name: 'Repository 10', autoReview: true },
|
|
664
|
+
filter: { id: { $in: [10] } },
|
|
665
|
+
});
|
|
666
|
+
const next = vi.fn().mockResolvedValue(undefined);
|
|
667
|
+
|
|
668
|
+
await enforceRepositoryCollectionAccess(context, next);
|
|
669
|
+
|
|
670
|
+
expect(next).toHaveBeenCalledOnce();
|
|
671
|
+
});
|
|
672
|
+
|
|
673
|
+
it('rejects a body value that overrides an allowed URL/action value with another repository', async () => {
|
|
674
|
+
const { context } = createCollectionContext({
|
|
675
|
+
resourceName: 'gitCodeReviews',
|
|
676
|
+
actionName: 'update',
|
|
677
|
+
params: { values: { repositoryId: 10 } },
|
|
678
|
+
requestBody: { repositoryId: 20 },
|
|
679
|
+
filter: { id: { $in: [10] } },
|
|
680
|
+
});
|
|
681
|
+
|
|
682
|
+
await expect(enforceRepositoryCollectionAccess(context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
683
|
+
});
|
|
684
|
+
|
|
685
|
+
it('accepts matching string and numeric repository IDs for a scoped collection create', async () => {
|
|
686
|
+
const { context } = createCollectionContext({
|
|
687
|
+
resourceName: 'gitSubtreeConfigs',
|
|
688
|
+
actionName: 'create',
|
|
689
|
+
requestBody: { repositoryId: 10 },
|
|
690
|
+
filter: { id: { $eq: '10' } },
|
|
691
|
+
});
|
|
692
|
+
const next = vi.fn().mockResolvedValue(undefined);
|
|
693
|
+
|
|
694
|
+
await enforceRepositoryCollectionAccess(context, next);
|
|
695
|
+
|
|
696
|
+
expect(next).toHaveBeenCalledOnce();
|
|
697
|
+
});
|
|
698
|
+
|
|
699
|
+
it('rejects a global review flow and unknown generic mutation for a scoped role', async () => {
|
|
700
|
+
const globalFlow = createCollectionContext({
|
|
701
|
+
resourceName: 'gitReviewFlows',
|
|
702
|
+
actionName: 'create',
|
|
703
|
+
requestBody: { repositoryId: null },
|
|
704
|
+
filter: { id: { $in: [10] } },
|
|
705
|
+
});
|
|
706
|
+
const unknownMutation = createCollectionContext({
|
|
707
|
+
resourceName: 'gitCodeReviews',
|
|
708
|
+
actionName: 'updateOrCreate',
|
|
709
|
+
filter: { id: { $in: [10] } },
|
|
710
|
+
});
|
|
711
|
+
|
|
712
|
+
await expect(enforceRepositoryCollectionAccess(globalFlow.context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
713
|
+
await expect(enforceRepositoryCollectionAccess(unknownMutation.context, vi.fn())).rejects.toMatchObject({
|
|
714
|
+
status: 403,
|
|
715
|
+
});
|
|
716
|
+
});
|
|
717
|
+
|
|
718
|
+
it('checks a subtree run config before allowing a scoped create', async () => {
|
|
719
|
+
const denied = createCollectionContext({
|
|
720
|
+
resourceName: 'gitSubtreeRuns',
|
|
721
|
+
actionName: 'create',
|
|
722
|
+
requestBody: { configId: 8 },
|
|
723
|
+
configRepositoryId: 20,
|
|
724
|
+
filter: { id: { $in: [10] } },
|
|
725
|
+
});
|
|
726
|
+
const allowed = createCollectionContext({
|
|
727
|
+
resourceName: 'gitSubtreeRuns',
|
|
728
|
+
actionName: 'create',
|
|
729
|
+
requestBody: { configId: 8 },
|
|
730
|
+
configRepositoryId: 10,
|
|
731
|
+
filter: { id: { $in: [10] } },
|
|
732
|
+
});
|
|
733
|
+
const next = vi.fn().mockResolvedValue(undefined);
|
|
734
|
+
|
|
735
|
+
await expect(enforceRepositoryCollectionAccess(denied.context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
736
|
+
await enforceRepositoryCollectionAccess(allowed.context, next);
|
|
737
|
+
|
|
738
|
+
expect(denied.configFindOne).toHaveBeenCalledWith({ filterByTk: 8 });
|
|
739
|
+
expect(allowed.configFindOne).toHaveBeenCalledWith({ filterByTk: 8 });
|
|
740
|
+
expect(next).toHaveBeenCalledOnce();
|
|
741
|
+
});
|
|
742
|
+
|
|
743
|
+
it('fails closed for unsupported repository scopes and protects global credentials', async () => {
|
|
744
|
+
const unsupported = createCollectionContext({
|
|
745
|
+
resourceName: 'gitCodeReviews',
|
|
746
|
+
actionName: 'list',
|
|
747
|
+
filter: { status: 'active' },
|
|
748
|
+
});
|
|
749
|
+
const accounts = createCollectionContext({
|
|
750
|
+
resourceName: 'gitAccounts',
|
|
751
|
+
actionName: 'list',
|
|
752
|
+
filter: { id: { $in: [10] } },
|
|
753
|
+
});
|
|
754
|
+
|
|
755
|
+
await expect(enforceRepositoryCollectionAccess(unsupported.context, vi.fn())).rejects.toMatchObject({
|
|
756
|
+
status: 403,
|
|
757
|
+
});
|
|
758
|
+
await expect(enforceRepositoryCollectionAccess(accounts.context, vi.fn())).rejects.toMatchObject({ status: 403 });
|
|
759
|
+
});
|
|
760
|
+
});
|