plugin-git-manager 1.2.23 → 1.2.26
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/client/900.acf7d1fa22f95e71.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/900.f32b9dc85249fc0a.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +8 -8
- package/dist/locale/en-US.json +4 -3
- package/dist/locale/vi-VN.json +4 -3
- package/dist/locale/zh-CN.json +4 -3
- package/dist/server/actions/git-actions.js +21 -8
- package/dist/server/actions/gitlab-api.js +5 -8
- package/dist/server/actions/poller.js +2 -1
- package/dist/server/actions/review.js +50 -13
- package/dist/server/actions/role-permissions.js +109 -16
- package/dist/server/actions/subtree.js +4 -8
- package/dist/server/migrations/20260730000000-migrate-legacy-repository-permissions.js +23 -7
- package/dist/server/plugin.js +42 -19
- package/dist/server/repository-access.js +505 -27
- package/dist/server/services/registry-content-service.js +149 -32
- package/dist/server/utils/get-repo-account.js +5 -2
- package/dist/server/utils/gitlab-url.js +2 -0
- package/dist/server/utils/redact.js +51 -5
- package/dist/server/utils/url-security.js +109 -0
- package/package.json +4 -2
- package/src/client/components/RunReviewButton.tsx +437 -436
- package/src/client/index.tsx +2 -1
- package/src/locale/en-US.json +4 -3
- package/src/locale/vi-VN.json +4 -3
- package/src/locale/zh-CN.json +4 -3
- package/src/server/__tests__/git-actions.test.ts +24 -0
- package/src/server/__tests__/plugin-url-security.test.ts +17 -0
- package/src/server/__tests__/poller.test.ts +37 -0
- package/src/server/__tests__/repository-access.test.ts +695 -1
- package/src/server/__tests__/review.test.ts +137 -0
- package/src/server/__tests__/role-permissions.test.ts +123 -2
- package/src/server/actions/git-actions.ts +33 -10
- package/src/server/actions/gitlab-api.ts +5 -8
- package/src/server/actions/poller.ts +2 -1
- package/src/server/actions/review.ts +74 -15
- package/src/server/actions/role-permissions.ts +136 -14
- package/src/server/actions/subtree.ts +4 -8
- package/src/server/migrations/20260730000000-migrate-legacy-repository-permissions.ts +23 -8
- package/src/server/plugin.ts +46 -25
- package/src/server/repository-access.ts +737 -28
- package/src/server/services/__tests__/registry-content-service.test.ts +209 -13
- package/src/server/services/registry-content-service.ts +473 -315
- package/src/server/utils/__tests__/redact.test.ts +56 -0
- package/src/server/utils/__tests__/url-security.test.ts +85 -0
- package/src/server/utils/get-repo-account.ts +22 -4
- package/src/server/utils/gitlab-url.ts +3 -0
- package/src/server/utils/redact.ts +68 -5
- package/src/server/utils/url-security.ts +95 -0
- package/dist/client/900.ee2fa037aff389e2.js +0 -10
- package/dist/client-v2/900.bef1c41d267e50c5.js +0 -10
|
@@ -5,7 +5,13 @@ import { join } from 'path';
|
|
|
5
5
|
|
|
6
6
|
import type { Database } from '@nocobase/database';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
RegistryGitContentService,
|
|
10
|
+
SkillHubGitContentService,
|
|
11
|
+
type RegistryGitAccessContext,
|
|
12
|
+
} from '../registry-content-service';
|
|
13
|
+
|
|
14
|
+
const scheduledSyncAccess: RegistryGitAccessContext = { kind: 'system', reason: 'scheduled-sync' };
|
|
9
15
|
|
|
10
16
|
describe('RegistryGitContentService', () => {
|
|
11
17
|
const originalRepositoryRoot = process.env.GIT_REPOS_BASE_PATH;
|
|
@@ -54,10 +60,12 @@ describe('RegistryGitContentService', () => {
|
|
|
54
60
|
} as unknown as Database;
|
|
55
61
|
const service = new RegistryGitContentService(database);
|
|
56
62
|
|
|
57
|
-
await expect(
|
|
58
|
-
|
|
59
|
-
);
|
|
60
|
-
await expect(
|
|
63
|
+
await expect(
|
|
64
|
+
service.readFile({ repositoryId: 1, commitSha, filePath: 'payload.bin' }, scheduledSyncAccess),
|
|
65
|
+
).resolves.toEqual(Buffer.from([0, 255, 128, 17]));
|
|
66
|
+
await expect(
|
|
67
|
+
service.readFile({ repositoryId: 1, commitSha, filePath: 'missing.json' }, scheduledSyncAccess),
|
|
68
|
+
).rejects.toMatchObject({
|
|
61
69
|
code: 'REGISTRY_GIT_FILE_NOT_FOUND',
|
|
62
70
|
});
|
|
63
71
|
});
|
|
@@ -72,11 +80,11 @@ describe('RegistryGitContentService', () => {
|
|
|
72
80
|
} as unknown as Database;
|
|
73
81
|
const service = new RegistryGitContentService(database);
|
|
74
82
|
|
|
75
|
-
await expect(service.resolveCommit(1, 'HEAD')).rejects.toMatchObject({
|
|
83
|
+
await expect(service.resolveCommit(1, 'HEAD', scheduledSyncAccess)).rejects.toMatchObject({
|
|
76
84
|
code: 'REGISTRY_EXPORT_NOT_GRANTED',
|
|
77
85
|
});
|
|
78
86
|
await expect(
|
|
79
|
-
service.readFile({ repositoryId: 1, commitSha, filePath: 'payload.bin' }),
|
|
87
|
+
service.readFile({ repositoryId: 1, commitSha, filePath: 'payload.bin' }, scheduledSyncAccess),
|
|
80
88
|
).rejects.toMatchObject({
|
|
81
89
|
code: 'REGISTRY_EXPORT_NOT_GRANTED',
|
|
82
90
|
});
|
|
@@ -88,12 +96,20 @@ describe('RegistryGitContentService', () => {
|
|
|
88
96
|
} as unknown as Database;
|
|
89
97
|
const service = new RegistryGitContentService(database);
|
|
90
98
|
|
|
91
|
-
await expect(service.resolveCommit(404, 'HEAD')).rejects.toMatchObject({
|
|
99
|
+
await expect(service.resolveCommit(404, 'HEAD', scheduledSyncAccess)).rejects.toMatchObject({
|
|
92
100
|
code: 'REGISTRY_EXPORT_NOT_GRANTED',
|
|
93
101
|
});
|
|
94
102
|
});
|
|
95
103
|
|
|
96
|
-
it('
|
|
104
|
+
it('waits for a killed Git process to close before returning an output-limit error', async () => {
|
|
105
|
+
// Keep Git writing after the first stdout chunk. This makes the test cover
|
|
106
|
+
// the Windows handle race: the repository must be removable immediately
|
|
107
|
+
// after `readFile()` rejects, without depending on afterEach timing.
|
|
108
|
+
writeFileSync(join(repositoryPath, 'payload.bin'), Buffer.alloc(8 * 1024 * 1024, 255));
|
|
109
|
+
execFileSync('git', ['-C', repositoryPath, 'add', 'payload.bin'], { stdio: 'ignore' });
|
|
110
|
+
execFileSync('git', ['-C', repositoryPath, 'commit', '--amend', '--no-edit'], { stdio: 'ignore' });
|
|
111
|
+
commitSha = execFileSync('git', ['-C', repositoryPath, 'rev-parse', 'HEAD'], { encoding: 'utf8' }).trim();
|
|
112
|
+
|
|
97
113
|
const database = {
|
|
98
114
|
getRepository: () => ({
|
|
99
115
|
findOne: vi.fn().mockResolvedValue({
|
|
@@ -115,9 +131,10 @@ describe('RegistryGitContentService', () => {
|
|
|
115
131
|
maxTreeOutputBytes: 1024,
|
|
116
132
|
});
|
|
117
133
|
|
|
118
|
-
await expect(
|
|
119
|
-
|
|
120
|
-
);
|
|
134
|
+
await expect(
|
|
135
|
+
service.readFile({ repositoryId: 1, commitSha, filePath: 'payload.bin' }, scheduledSyncAccess),
|
|
136
|
+
).rejects.toThrow('Git file exceeds the registry source-file limit.');
|
|
137
|
+
expect(() => rmSync(repositoryRoot, { recursive: true, force: true, maxRetries: 0 })).not.toThrow();
|
|
121
138
|
});
|
|
122
139
|
|
|
123
140
|
it('rejects a Git tree that exceeds the configured entry limit', async () => {
|
|
@@ -143,7 +160,186 @@ describe('RegistryGitContentService', () => {
|
|
|
143
160
|
});
|
|
144
161
|
|
|
145
162
|
await expect(
|
|
146
|
-
service.listTree({ repositoryId: 1, commitSha, rootPath: '', recursive: true }),
|
|
163
|
+
service.listTree({ repositoryId: 1, commitSha, rootPath: '', recursive: true }, scheduledSyncAccess),
|
|
147
164
|
).rejects.toThrow('Git tree contains too many entries for registry export.');
|
|
148
165
|
});
|
|
166
|
+
|
|
167
|
+
it('requires an explicit actor instead of treating an internal call as a system sync', async () => {
|
|
168
|
+
const database = {
|
|
169
|
+
getRepository: vi.fn(),
|
|
170
|
+
} as unknown as Database;
|
|
171
|
+
const service = new RegistryGitContentService(database);
|
|
172
|
+
|
|
173
|
+
expect(service.contractVersion).toBe(2);
|
|
174
|
+
expect(service.capabilities).toEqual(
|
|
175
|
+
expect.arrayContaining(['registry-content-with-actor', 'registry-content-authorize-source']),
|
|
176
|
+
);
|
|
177
|
+
await expect(service.assertRepositoryAccess(1)).rejects.toMatchObject({
|
|
178
|
+
code: 'REGISTRY_REPOSITORY_ACCESS_DENIED',
|
|
179
|
+
});
|
|
180
|
+
expect(database.getRepository).not.toHaveBeenCalled();
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('allows a user whose Git Manager file-content scope includes the repository', async () => {
|
|
184
|
+
const acl = {
|
|
185
|
+
can: vi.fn().mockResolvedValue({ params: { filter: { $and: [{ id: { $in: [1] } }] } } }),
|
|
186
|
+
};
|
|
187
|
+
const database = {
|
|
188
|
+
getRepository: () => ({
|
|
189
|
+
findOne: vi.fn().mockResolvedValue({
|
|
190
|
+
get: (attribute: string) => {
|
|
191
|
+
if (attribute === 'localPath') return 'skills';
|
|
192
|
+
if (attribute === 'registryExportEnabled') return true;
|
|
193
|
+
return null;
|
|
194
|
+
},
|
|
195
|
+
}),
|
|
196
|
+
}),
|
|
197
|
+
} as unknown as Database;
|
|
198
|
+
const service = new RegistryGitContentService(database, undefined, acl);
|
|
199
|
+
|
|
200
|
+
await expect(service.resolveCommit(1, 'HEAD', { kind: 'user', roles: ['developer'] })).resolves.toBe(commitSha);
|
|
201
|
+
expect(acl.can).toHaveBeenCalledWith({
|
|
202
|
+
roles: ['developer'],
|
|
203
|
+
resource: 'gitManager',
|
|
204
|
+
action: 'fileContent',
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('rejects a user whose Git Manager scope excludes the requested repository', async () => {
|
|
209
|
+
const acl = {
|
|
210
|
+
can: vi.fn().mockResolvedValue({ params: { filter: { $and: [{ id: { $in: [1] } }] } } }),
|
|
211
|
+
};
|
|
212
|
+
const repositoryLookup = vi.fn();
|
|
213
|
+
const database = {
|
|
214
|
+
getRepository: repositoryLookup,
|
|
215
|
+
} as unknown as Database;
|
|
216
|
+
const service = new RegistryGitContentService(database, undefined, acl);
|
|
217
|
+
|
|
218
|
+
await expect(service.assertRepositoryAccess(2, { kind: 'user', roles: ['developer'] })).rejects.toMatchObject({
|
|
219
|
+
code: 'REGISTRY_REPOSITORY_ACCESS_DENIED',
|
|
220
|
+
});
|
|
221
|
+
expect(repositoryLookup).not.toHaveBeenCalled();
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('allows root without evaluating repository scope', async () => {
|
|
225
|
+
const acl = { can: vi.fn() };
|
|
226
|
+
const database = {
|
|
227
|
+
getRepository: () => ({
|
|
228
|
+
findOne: vi.fn().mockResolvedValue({
|
|
229
|
+
get: (attribute: string) => {
|
|
230
|
+
if (attribute === 'localPath') return 'skills';
|
|
231
|
+
if (attribute === 'registryExportEnabled') return true;
|
|
232
|
+
return null;
|
|
233
|
+
},
|
|
234
|
+
}),
|
|
235
|
+
}),
|
|
236
|
+
} as unknown as Database;
|
|
237
|
+
const service = new RegistryGitContentService(database, undefined, acl);
|
|
238
|
+
|
|
239
|
+
await expect(service.resolveCommit(1, 'HEAD', { kind: 'user', roles: ['root'] })).resolves.toBe(commitSha);
|
|
240
|
+
expect(acl.can).not.toHaveBeenCalled();
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it('allows a scheduled system sync but still requires the repository export opt-in', async () => {
|
|
244
|
+
const acl = { can: vi.fn() };
|
|
245
|
+
const database = {
|
|
246
|
+
getRepository: () => ({
|
|
247
|
+
findOne: vi.fn().mockResolvedValue({
|
|
248
|
+
get: (attribute: string) => {
|
|
249
|
+
if (attribute === 'localPath') return 'skills';
|
|
250
|
+
if (attribute === 'registryExportEnabled') return true;
|
|
251
|
+
return null;
|
|
252
|
+
},
|
|
253
|
+
}),
|
|
254
|
+
}),
|
|
255
|
+
} as unknown as Database;
|
|
256
|
+
const service = new RegistryGitContentService(database, undefined, acl);
|
|
257
|
+
|
|
258
|
+
await expect(service.resolveCommit(1, 'HEAD', scheduledSyncAccess)).resolves.toBe(commitSha);
|
|
259
|
+
expect(acl.can).not.toHaveBeenCalled();
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('rejects an otherwise authorized user when repository export is disabled', async () => {
|
|
263
|
+
const acl = {
|
|
264
|
+
can: vi.fn().mockResolvedValue({ params: { filter: { $and: [{ id: { $in: [1] } }] } } }),
|
|
265
|
+
};
|
|
266
|
+
const database = {
|
|
267
|
+
getRepository: () => ({
|
|
268
|
+
findOne: vi.fn().mockResolvedValue({
|
|
269
|
+
get: (attribute: string) => (attribute === 'registryExportEnabled' ? false : 'skills'),
|
|
270
|
+
}),
|
|
271
|
+
}),
|
|
272
|
+
} as unknown as Database;
|
|
273
|
+
const service = new RegistryGitContentService(database, undefined, acl);
|
|
274
|
+
|
|
275
|
+
await expect(service.assertRepositoryAccess(1, { kind: 'user', roles: ['developer'] })).rejects.toMatchObject({
|
|
276
|
+
code: 'REGISTRY_EXPORT_NOT_GRANTED',
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it('allows Skill Hub reads for a scoped user even when Registry export is disabled', async () => {
|
|
281
|
+
const acl = {
|
|
282
|
+
can: vi.fn().mockResolvedValue({ params: { filter: { $and: [{ id: { $in: [1] } }] } } }),
|
|
283
|
+
};
|
|
284
|
+
const database = {
|
|
285
|
+
getRepository: () => ({
|
|
286
|
+
findOne: vi.fn().mockResolvedValue({
|
|
287
|
+
get: (attribute: string) => {
|
|
288
|
+
if (attribute === 'localPath') return 'skills';
|
|
289
|
+
if (attribute === 'registryExportEnabled') return false;
|
|
290
|
+
return null;
|
|
291
|
+
},
|
|
292
|
+
}),
|
|
293
|
+
}),
|
|
294
|
+
} as unknown as Database;
|
|
295
|
+
const service = new SkillHubGitContentService(database, undefined, acl);
|
|
296
|
+
|
|
297
|
+
expect(service.contractVersion).toBe(2);
|
|
298
|
+
expect(service.capabilities).toContain('skill-hub-content-with-actor');
|
|
299
|
+
await expect(
|
|
300
|
+
service.readFile({ repositoryId: 1, commitSha, filePath: 'payload.bin' }, { kind: 'user', roles: ['developer'] }),
|
|
301
|
+
).resolves.toEqual(Buffer.from([0, 255, 128, 17]));
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it('rejects a Skill Hub user outside repository scope before reading the database', async () => {
|
|
305
|
+
const acl = {
|
|
306
|
+
can: vi.fn().mockResolvedValue({ params: { filter: { $and: [{ id: { $in: [1] } }] } } }),
|
|
307
|
+
};
|
|
308
|
+
const repositoryLookup = vi.fn();
|
|
309
|
+
const database = {
|
|
310
|
+
getRepository: repositoryLookup,
|
|
311
|
+
} as unknown as Database;
|
|
312
|
+
const service = new SkillHubGitContentService(database, undefined, acl);
|
|
313
|
+
|
|
314
|
+
await expect(service.assertRepositoryAccess(2, { kind: 'user', roles: ['developer'] })).rejects.toMatchObject({
|
|
315
|
+
code: 'SKILL_HUB_REPOSITORY_ACCESS_DENIED',
|
|
316
|
+
});
|
|
317
|
+
expect(repositoryLookup).not.toHaveBeenCalled();
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
it('rejects a Skill Hub call without an actor before reading the database', async () => {
|
|
321
|
+
const repositoryLookup = vi.fn();
|
|
322
|
+
const database = {
|
|
323
|
+
getRepository: repositoryLookup,
|
|
324
|
+
} as unknown as Database;
|
|
325
|
+
const service = new SkillHubGitContentService(database);
|
|
326
|
+
|
|
327
|
+
await expect(service.assertRepositoryAccess(1)).rejects.toMatchObject({
|
|
328
|
+
code: 'SKILL_HUB_REPOSITORY_ACCESS_DENIED',
|
|
329
|
+
});
|
|
330
|
+
expect(repositoryLookup).not.toHaveBeenCalled();
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
it('rejects a scheduled system actor from Skill Hub before reading the database', async () => {
|
|
334
|
+
const repositoryLookup = vi.fn();
|
|
335
|
+
const database = {
|
|
336
|
+
getRepository: repositoryLookup,
|
|
337
|
+
} as unknown as Database;
|
|
338
|
+
const service = new SkillHubGitContentService(database);
|
|
339
|
+
|
|
340
|
+
await expect(service.assertRepositoryAccess(1, scheduledSyncAccess)).rejects.toMatchObject({
|
|
341
|
+
code: 'SKILL_HUB_REPOSITORY_ACCESS_DENIED',
|
|
342
|
+
});
|
|
343
|
+
expect(repositoryLookup).not.toHaveBeenCalled();
|
|
344
|
+
});
|
|
149
345
|
});
|