plugin-git-manager 1.2.26 → 1.2.28
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 +133 -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/900.a48beac7e2ebee7d.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/900.e6155002a9c97e7f.js +10 -0
- package/dist/client-v2/928.bba701b5a1ece58e.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +9 -8
- package/dist/locale/en-US.json +307 -297
- package/dist/locale/vi-VN.json +295 -292
- package/dist/locale/zh-CN.json +61 -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.js +20 -10
- package/dist/server/plugin.js +6 -4
- package/dist/server/poller.js +46 -45
- package/dist/server/request-method-policy.js +75 -0
- package/dist/server/services/registry-content-service.js +23 -10
- 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__/RunReviewButton.test.tsx +73 -0
- package/src/client/ai-context.tsx +114 -114
- package/src/client/components/AIEmployeeSelect.tsx +63 -63
- package/src/client/components/CommitHistory.tsx +374 -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 +303 -303
- package/src/client/components/ReviewHistory.tsx +566 -566
- package/src/client/components/RunReviewButton.tsx +63 -55
- 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-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 +307 -297
- package/src/locale/vi-VN.json +295 -292
- package/src/locale/zh-CN.json +61 -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 +752 -752
- package/src/server/__tests__/review.test.ts +137 -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.ts +1388 -1369
- package/src/server/actions/role-permissions.ts +321 -321
- package/src/server/actions/subtree.ts +508 -508
- package/src/server/ai-tools.ts +319 -319
- package/src/server/collections/gitAccounts.ts +56 -56
- package/src/server/collections/gitCodeReviews.ts +199 -199
- package/src/server/collections/gitRepositories.ts +87 -87
- package/src/server/collections/gitReviewFlows.ts +108 -108
- package/src/server/collections/gitSubtreeConfigs.ts +38 -38
- package/src/server/collections/gitSubtreeRuns.ts +30 -30
- package/src/server/index.ts +2 -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 +372 -361
- package/src/server/poller.ts +351 -352
- package/src/server/repository-access.ts +773 -773
- package/src/server/request-method-policy.ts +55 -0
- package/src/server/services/__tests__/registry-content-service.test.ts +359 -345
- package/src/server/services/registry-content-service.ts +33 -11
- 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
package/src/locale/zh-CN.json
CHANGED
|
@@ -1,51 +1,61 @@
|
|
|
1
|
-
{
|
|
2
|
-
"Git Manager": "Git 管理器",
|
|
3
|
-
"Allow Skill Registry export": "允许 Skill Registry 导出",
|
|
4
|
-
"Subtree Splits": "Subtree 拆分",
|
|
5
|
-
"Add subtree configuration": "添加 subtree 配置",
|
|
6
|
-
"Edit subtree configuration": "编辑 subtree 配置",
|
|
7
|
-
"Subtree configuration created": "已创建 subtree 配置",
|
|
8
|
-
"Subtree configuration updated": "已更新 subtree 配置",
|
|
9
|
-
"Delete this subtree configuration?": "删除此 subtree 配置?",
|
|
10
|
-
"Name": "名称",
|
|
11
|
-
"Repository": "仓库",
|
|
12
|
-
"Source": "源",
|
|
13
|
-
"Source branch": "源分支",
|
|
14
|
-
"Source folder": "源文件夹",
|
|
15
|
-
"Target branch": "目标分支",
|
|
16
|
-
"Remote name": "远程名称",
|
|
17
|
-
"Default policy": "默认策略",
|
|
18
|
-
"Push after run": "运行后推送",
|
|
19
|
-
"Enabled": "已启用",
|
|
20
|
-
"Last status": "最近状态",
|
|
21
|
-
"Actions": "操作",
|
|
22
|
-
"Run": "运行",
|
|
23
|
-
"Edit": "编辑",
|
|
24
|
-
"Delete": "删除",
|
|
25
|
-
"Deleted": "已删除",
|
|
26
|
-
"Run subtree split": "运行 subtree 拆分",
|
|
27
|
-
"Preview": "预览",
|
|
28
|
-
"Fast-forward only": "仅快进",
|
|
29
|
-
"Replace target": "替换目标分支",
|
|
30
|
-
"Merge histories": "合并历史",
|
|
31
|
-
"Replace target may discard target-only commits": "替换目标分支可能丢弃仅存在于目标分支的提交",
|
|
32
|
-
"Type the target branch name to confirm": "输入目标分支名称以确认",
|
|
33
|
-
"Push target branch after success": "成功后推送目标分支",
|
|
34
|
-
"Target branch does not exist": "目标分支不存在",
|
|
35
|
-
"Subtree split completed": "Subtree 拆分完成",
|
|
36
|
-
"Subtree relationship: target-missing": "目标分支不存在",
|
|
37
|
-
"Subtree relationship: already-up-to-date": "目标分支已是最新",
|
|
38
|
-
"Subtree relationship: fast-forward": "目标分支可以快进",
|
|
39
|
-
"Subtree relationship: diverged": "目标分支已分叉",
|
|
40
|
-
"Run history": "运行历史",
|
|
41
|
-
"Started at": "开始时间",
|
|
42
|
-
"Policy": "策略",
|
|
43
|
-
"Status": "状态",
|
|
44
|
-
"Split SHA": "拆分 SHA",
|
|
45
|
-
"Target before": "更新前目标",
|
|
46
|
-
"Target after": "更新后目标",
|
|
47
|
-
"Error": "错误",
|
|
48
|
-
"Execution mode": "执行模式",
|
|
49
|
-
"App process": "应用进程",
|
|
50
|
-
"Credential-bearing URLs are not allowed": "URL 中不允许包含用户名或凭据"
|
|
51
|
-
|
|
1
|
+
{
|
|
2
|
+
"Git Manager": "Git 管理器",
|
|
3
|
+
"Allow Skill Registry export": "允许 Skill Registry 导出",
|
|
4
|
+
"Subtree Splits": "Subtree 拆分",
|
|
5
|
+
"Add subtree configuration": "添加 subtree 配置",
|
|
6
|
+
"Edit subtree configuration": "编辑 subtree 配置",
|
|
7
|
+
"Subtree configuration created": "已创建 subtree 配置",
|
|
8
|
+
"Subtree configuration updated": "已更新 subtree 配置",
|
|
9
|
+
"Delete this subtree configuration?": "删除此 subtree 配置?",
|
|
10
|
+
"Name": "名称",
|
|
11
|
+
"Repository": "仓库",
|
|
12
|
+
"Source": "源",
|
|
13
|
+
"Source branch": "源分支",
|
|
14
|
+
"Source folder": "源文件夹",
|
|
15
|
+
"Target branch": "目标分支",
|
|
16
|
+
"Remote name": "远程名称",
|
|
17
|
+
"Default policy": "默认策略",
|
|
18
|
+
"Push after run": "运行后推送",
|
|
19
|
+
"Enabled": "已启用",
|
|
20
|
+
"Last status": "最近状态",
|
|
21
|
+
"Actions": "操作",
|
|
22
|
+
"Run": "运行",
|
|
23
|
+
"Edit": "编辑",
|
|
24
|
+
"Delete": "删除",
|
|
25
|
+
"Deleted": "已删除",
|
|
26
|
+
"Run subtree split": "运行 subtree 拆分",
|
|
27
|
+
"Preview": "预览",
|
|
28
|
+
"Fast-forward only": "仅快进",
|
|
29
|
+
"Replace target": "替换目标分支",
|
|
30
|
+
"Merge histories": "合并历史",
|
|
31
|
+
"Replace target may discard target-only commits": "替换目标分支可能丢弃仅存在于目标分支的提交",
|
|
32
|
+
"Type the target branch name to confirm": "输入目标分支名称以确认",
|
|
33
|
+
"Push target branch after success": "成功后推送目标分支",
|
|
34
|
+
"Target branch does not exist": "目标分支不存在",
|
|
35
|
+
"Subtree split completed": "Subtree 拆分完成",
|
|
36
|
+
"Subtree relationship: target-missing": "目标分支不存在",
|
|
37
|
+
"Subtree relationship: already-up-to-date": "目标分支已是最新",
|
|
38
|
+
"Subtree relationship: fast-forward": "目标分支可以快进",
|
|
39
|
+
"Subtree relationship: diverged": "目标分支已分叉",
|
|
40
|
+
"Run history": "运行历史",
|
|
41
|
+
"Started at": "开始时间",
|
|
42
|
+
"Policy": "策略",
|
|
43
|
+
"Status": "状态",
|
|
44
|
+
"Split SHA": "拆分 SHA",
|
|
45
|
+
"Target before": "更新前目标",
|
|
46
|
+
"Target after": "更新后目标",
|
|
47
|
+
"Error": "错误",
|
|
48
|
+
"Execution mode": "执行模式",
|
|
49
|
+
"App process": "应用进程",
|
|
50
|
+
"Credential-bearing URLs are not allowed": "URL 中不允许包含用户名或凭据",
|
|
51
|
+
"Git Repository": "Git 仓库",
|
|
52
|
+
"Git Merge Request": "Git 合并请求",
|
|
53
|
+
"Git Commit": "Git 提交",
|
|
54
|
+
"Method not allowed": "不允许的请求方法",
|
|
55
|
+
"Invalid repository or account URL": "仓库或账号 URL 无效",
|
|
56
|
+
"Only HTTPS repository and account URLs are allowed": "仓库和账号 URL 只允许使用 HTTPS",
|
|
57
|
+
"Repository URL must match the Git account origin": "仓库 URL 必须与 Git 账号使用相同的协议、主机和端口",
|
|
58
|
+
"GitHub accounts currently require github.com": "GitHub 账号目前仅支持 github.com",
|
|
59
|
+
"Invalid local path": "本地路径无效",
|
|
60
|
+
"Invalid local path: path traversal detected or path is outside the allowed base directory": "本地路径无效:检测到路径穿越或路径位于允许的基础目录之外"
|
|
61
|
+
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { Context } from '@nocobase/actions';
|
|
2
|
-
import { vi } from 'vitest';
|
|
3
|
-
|
|
4
|
-
import { getRepo } from '../actions/git-actions';
|
|
5
|
-
|
|
6
|
-
describe('Git Manager git actions', () => {
|
|
7
|
-
it('uses the repository ID from the request body over the URL parameter', async () => {
|
|
8
|
-
const repository = { id: 20 };
|
|
9
|
-
const findOne = vi.fn().mockResolvedValue(repository);
|
|
10
|
-
const context = {
|
|
11
|
-
action: { params: { repositoryId: 10 } },
|
|
12
|
-
request: { body: { repositoryId: 20 } },
|
|
13
|
-
db: {
|
|
14
|
-
getRepository: vi.fn().mockReturnValue({ findOne }),
|
|
15
|
-
},
|
|
16
|
-
throw: vi.fn(),
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const result = await getRepo(context as unknown as Context);
|
|
20
|
-
|
|
21
|
-
expect(findOne).toHaveBeenCalledWith({ filterByTk: 20 });
|
|
22
|
-
expect(result).toBe(repository);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
1
|
+
import { Context } from '@nocobase/actions';
|
|
2
|
+
import { vi } from 'vitest';
|
|
3
|
+
|
|
4
|
+
import { getRepo } from '../actions/git-actions';
|
|
5
|
+
|
|
6
|
+
describe('Git Manager git actions', () => {
|
|
7
|
+
it('uses the repository ID from the request body over the URL parameter', async () => {
|
|
8
|
+
const repository = { id: 20 };
|
|
9
|
+
const findOne = vi.fn().mockResolvedValue(repository);
|
|
10
|
+
const context = {
|
|
11
|
+
action: { params: { repositoryId: 10 } },
|
|
12
|
+
request: { body: { repositoryId: 20 } },
|
|
13
|
+
db: {
|
|
14
|
+
getRepository: vi.fn().mockReturnValue({ findOne }),
|
|
15
|
+
},
|
|
16
|
+
throw: vi.fn(),
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const result = await getRepo(context as unknown as Context);
|
|
20
|
+
|
|
21
|
+
expect(findOne).toHaveBeenCalledWith({ filterByTk: 20 });
|
|
22
|
+
expect(result).toBe(repository);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,170 @@
|
|
|
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 { execFileSync } from 'child_process';
|
|
11
|
+
import { mkdtempSync, mkdirSync, readFileSync, rmSync, symlinkSync, unlinkSync } from 'fs';
|
|
12
|
+
import { tmpdir } from 'os';
|
|
13
|
+
import { join } from 'path';
|
|
14
|
+
import type { Context } from '@nocobase/actions';
|
|
15
|
+
import type { SimpleGit } from 'simple-git';
|
|
16
|
+
import { createGit, credentialEnvironment, validateLocalPath, withAuth } from '../actions/git-actions';
|
|
17
|
+
import { mergeRequests } from '../actions/gitlab-api';
|
|
18
|
+
import { getRepoAccount } from '../utils/get-repo-account';
|
|
19
|
+
|
|
20
|
+
const repoUrl = 'https://trusted.invalid/team/project.git';
|
|
21
|
+
const fakePat = 'test-only-secret';
|
|
22
|
+
const record = (values: Record<string, unknown>) => ({ get: (key: string) => values[key] });
|
|
23
|
+
|
|
24
|
+
function database(url = repoUrl, baseUrl: string | null = 'https://trusted.invalid', provider = 'gitlab') {
|
|
25
|
+
const repo = record({ gitAccountId: 1, repoUrl: url });
|
|
26
|
+
return {
|
|
27
|
+
repo,
|
|
28
|
+
db: {
|
|
29
|
+
getRepository: (name: string) => ({
|
|
30
|
+
findOne: async () => (name === 'gitAccounts' ? record({ baseUrl, provider, pat: fakePat }) : repo),
|
|
31
|
+
}),
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
describe('Git credential destination', () => {
|
|
37
|
+
afterEach(() => {
|
|
38
|
+
vi.unstubAllGlobals();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it.each([
|
|
42
|
+
['https://different.invalid/team/r', 'https://trusted.invalid', 'gitlab'],
|
|
43
|
+
['http://trusted.invalid/team/r', 'https://trusted.invalid', 'gitlab'],
|
|
44
|
+
['https://trusted.invalid:444/team/r', 'https://trusted.invalid', 'gitlab'],
|
|
45
|
+
['https://selfhost.invalid/team/r', null, 'gitlab'],
|
|
46
|
+
['https://enterprise.invalid/team/r', 'https://enterprise.invalid', 'github'],
|
|
47
|
+
])('rejects an untrusted credential destination %s', async (url, baseUrl, provider) => {
|
|
48
|
+
const { db, repo } = database(url, baseUrl, provider);
|
|
49
|
+
await expect(getRepoAccount(db, repo)).rejects.toThrow();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it.each([
|
|
53
|
+
[repoUrl, 'https://trusted.invalid', 'gitlab'],
|
|
54
|
+
['https://gitlab.com/team/r', null, 'gitlab'],
|
|
55
|
+
['https://github.com/team/r', null, 'github'],
|
|
56
|
+
])('accepts an explicitly bound or public default origin %s', async (url, baseUrl, provider) => {
|
|
57
|
+
const { db, repo } = database(url, baseUrl, provider);
|
|
58
|
+
await expect(getRepoAccount(db, repo)).resolves.toMatchObject({ pat: fakePat });
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('blocks the API request before sending a token to a mismatched repository host', async () => {
|
|
62
|
+
const fetchMock = vi.fn();
|
|
63
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
64
|
+
const { db } = database('https://different.invalid/team/r');
|
|
65
|
+
await expect(
|
|
66
|
+
mergeRequests({ db, action: { params: { repositoryId: 1 } } } as unknown as Context, async () => {}),
|
|
67
|
+
).rejects.toThrow('Repository URL must match');
|
|
68
|
+
expect(fetchMock).not.toHaveBeenCalled();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it.each([
|
|
72
|
+
[repoUrl, 'https://trusted.invalid', 'gitlab'],
|
|
73
|
+
['https://github.com/team/r', null, 'github'],
|
|
74
|
+
])('disables redirects for authenticated provider API requests', async (url, baseUrl, provider) => {
|
|
75
|
+
const fetchMock = vi.fn().mockResolvedValue({ ok: true, headers: new Headers(), json: async () => [] });
|
|
76
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
77
|
+
const { db } = database(url, baseUrl, provider);
|
|
78
|
+
await mergeRequests({ db, action: { params: { repositoryId: 1 } } } as unknown as Context, async () => {});
|
|
79
|
+
expect(fetchMock).toHaveBeenCalledWith(expect.any(String), expect.objectContaining({ redirect: 'error' }));
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('Git filesystem and process credentials', () => {
|
|
84
|
+
let fixture: string;
|
|
85
|
+
let base: string;
|
|
86
|
+
const originalBase = process.env.GIT_REPOS_BASE_PATH;
|
|
87
|
+
|
|
88
|
+
beforeEach(() => {
|
|
89
|
+
fixture = mkdtempSync(join(tmpdir(), 'git-manager-security-'));
|
|
90
|
+
base = join(fixture, 'base');
|
|
91
|
+
mkdirSync(base);
|
|
92
|
+
process.env.GIT_REPOS_BASE_PATH = base;
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
afterEach(() => {
|
|
96
|
+
vi.restoreAllMocks();
|
|
97
|
+
if (originalBase === undefined) delete process.env.GIT_REPOS_BASE_PATH;
|
|
98
|
+
else process.env.GIT_REPOS_BASE_PATH = originalBase;
|
|
99
|
+
rmSync(fixture, { recursive: true, force: true });
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('rejects base itself, traversal, junction escapes and new clones below a junction', () => {
|
|
103
|
+
const outside = join(fixture, 'outside');
|
|
104
|
+
mkdirSync(outside);
|
|
105
|
+
const alias = join(base, 'alias');
|
|
106
|
+
symlinkSync(outside, alias, 'junction');
|
|
107
|
+
try {
|
|
108
|
+
for (const candidate of ['.', '../outside', 'alias', 'alias/new/clone']) {
|
|
109
|
+
expect(() => validateLocalPath(candidate)).toThrow('Invalid local path');
|
|
110
|
+
}
|
|
111
|
+
expect(validateLocalPath('nested/new')).toBe(join(base, 'nested/new'));
|
|
112
|
+
} finally {
|
|
113
|
+
unlinkSync(alias);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('releases the lock when the initial remote setup fails', async () => {
|
|
118
|
+
const git = {
|
|
119
|
+
env: vi.fn(),
|
|
120
|
+
remote: vi.fn().mockRejectedValueOnce(new Error('setup failed')).mockResolvedValue(''),
|
|
121
|
+
};
|
|
122
|
+
const operation = vi.fn().mockResolvedValue('done');
|
|
123
|
+
await expect(withAuth(git as unknown as SimpleGit, base, repoUrl, fakePat, operation)).rejects.toThrow(
|
|
124
|
+
'setup failed',
|
|
125
|
+
);
|
|
126
|
+
await expect(withAuth(git as unknown as SimpleGit, base, repoUrl, fakePat, operation)).resolves.toBe('done');
|
|
127
|
+
expect(operation).toHaveBeenCalledTimes(1);
|
|
128
|
+
expect(git.env.mock.calls.at(-1)?.[0]).not.toHaveProperty('GIT_CONFIG_COUNT');
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('releases the lock even if credential setup fails', async () => {
|
|
132
|
+
const git = {
|
|
133
|
+
env: vi.fn().mockImplementationOnce(() => {
|
|
134
|
+
throw new Error('env failed');
|
|
135
|
+
}),
|
|
136
|
+
remote: vi.fn(),
|
|
137
|
+
};
|
|
138
|
+
await expect(withAuth(git as unknown as SimpleGit, base, repoUrl, fakePat, async () => true)).rejects.toThrow(
|
|
139
|
+
'env failed',
|
|
140
|
+
);
|
|
141
|
+
await expect(withAuth(git as unknown as SimpleGit, base, repoUrl, fakePat, async () => true)).resolves.toBe(true);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('never writes PAT or the authorization header into Git config, including on operation failure', async () => {
|
|
145
|
+
execFileSync('git', ['init', base], { stdio: 'ignore' });
|
|
146
|
+
const git = createGit(base);
|
|
147
|
+
await git.addRemote('origin', repoUrl);
|
|
148
|
+
const authorization = Buffer.from(`oauth2:${fakePat}`).toString('base64');
|
|
149
|
+
await expect(
|
|
150
|
+
withAuth(git, base, repoUrl, fakePat, async () => {
|
|
151
|
+
const config = readFileSync(join(base, '.git/config'), 'utf8');
|
|
152
|
+
expect(config).not.toContain(fakePat);
|
|
153
|
+
expect(config).not.toContain(authorization);
|
|
154
|
+
throw new Error(`failure ${fakePat} ${authorization}`);
|
|
155
|
+
}),
|
|
156
|
+
).rejects.toThrow('failure *** ***');
|
|
157
|
+
expect(readFileSync(join(base, '.git/config'), 'utf8')).not.toContain(fakePat);
|
|
158
|
+
await expect(withAuth(git, base, repoUrl, fakePat, async () => 'recovered')).resolves.toBe('recovered');
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('scopes the auth header to the trusted repository and disables Git redirects', () => {
|
|
162
|
+
const env = credentialEnvironment(repoUrl, fakePat);
|
|
163
|
+
const config = (url: string) =>
|
|
164
|
+
execFileSync('git', ['config', '--get-urlmatch', 'http', url], { env, encoding: 'utf8' });
|
|
165
|
+
expect(config(`${repoUrl}/info/refs`)).toContain('Authorization: Basic');
|
|
166
|
+
expect(config('https://different.invalid/team/project.git/info/refs')).not.toContain('Authorization: Basic');
|
|
167
|
+
expect(config('https://trusted.invalid/other/project.git/info/refs')).not.toContain('Authorization: Basic');
|
|
168
|
+
expect(config(repoUrl)).toContain('http.followredirects false');
|
|
169
|
+
});
|
|
170
|
+
});
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { isGitConfigurationUrlMutation } from '../plugin';
|
|
4
|
-
|
|
5
|
-
describe('Git Manager generic URL mutation policy', () => {
|
|
6
|
-
it('covers direct and association collection create/update routes', () => {
|
|
7
|
-
expect(isGitConfigurationUrlMutation('gitRepositories', 'create')).toBe(true);
|
|
8
|
-
expect(isGitConfigurationUrlMutation('gitAccounts', 'update')).toBe(true);
|
|
9
|
-
expect(isGitConfigurationUrlMutation('gitAccounts.repositories', 'update')).toBe(true);
|
|
10
|
-
expect(isGitConfigurationUrlMutation('gitRepositories.10.gitAccount', 'create')).toBe(true);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('does not treat a read or a custom Git Manager action as a generic URL mutation', () => {
|
|
14
|
-
expect(isGitConfigurationUrlMutation('gitAccounts.repositories', 'list')).toBe(false);
|
|
15
|
-
expect(isGitConfigurationUrlMutation('gitManager', 'clone')).toBe(false);
|
|
16
|
-
});
|
|
17
|
-
});
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { isGitConfigurationUrlMutation } from '../plugin';
|
|
4
|
+
|
|
5
|
+
describe('Git Manager generic URL mutation policy', () => {
|
|
6
|
+
it('covers direct and association collection create/update routes', () => {
|
|
7
|
+
expect(isGitConfigurationUrlMutation('gitRepositories', 'create')).toBe(true);
|
|
8
|
+
expect(isGitConfigurationUrlMutation('gitAccounts', 'update')).toBe(true);
|
|
9
|
+
expect(isGitConfigurationUrlMutation('gitAccounts.repositories', 'update')).toBe(true);
|
|
10
|
+
expect(isGitConfigurationUrlMutation('gitRepositories.10.gitAccount', 'create')).toBe(true);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('does not treat a read or a custom Git Manager action as a generic URL mutation', () => {
|
|
14
|
+
expect(isGitConfigurationUrlMutation('gitAccounts.repositories', 'list')).toBe(false);
|
|
15
|
+
expect(isGitConfigurationUrlMutation('gitManager', 'clone')).toBe(false);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
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 type { Application } from '@nocobase/server';
|
|
11
|
+
import { getPollerStatus, pollAllRepos, startPoller, stopPoller } from '../poller';
|
|
12
|
+
|
|
13
|
+
function mockApp(find = vi.fn().mockResolvedValue([])) {
|
|
14
|
+
return { db: { getRepository: () => ({ find }) }, log: {} } as unknown as Application;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
describe('Poller application isolation', () => {
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
vi.useRealTimers();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('starts one timer per application and stops only the requested application', async () => {
|
|
23
|
+
vi.useFakeTimers();
|
|
24
|
+
const firstFind = vi.fn().mockResolvedValue([]);
|
|
25
|
+
const secondFind = vi.fn().mockResolvedValue([]);
|
|
26
|
+
const first = mockApp(firstFind);
|
|
27
|
+
const second = mockApp(secondFind);
|
|
28
|
+
try {
|
|
29
|
+
startPoller(first);
|
|
30
|
+
startPoller(first);
|
|
31
|
+
startPoller(second);
|
|
32
|
+
expect(vi.getTimerCount()).toBe(2);
|
|
33
|
+
await vi.advanceTimersByTimeAsync(5 * 60 * 1000);
|
|
34
|
+
expect(firstFind).toHaveBeenCalledTimes(1);
|
|
35
|
+
expect(secondFind).toHaveBeenCalledTimes(1);
|
|
36
|
+
stopPoller(second);
|
|
37
|
+
expect(getPollerStatus(first).running).toBe(true);
|
|
38
|
+
expect(getPollerStatus(second).running).toBe(false);
|
|
39
|
+
await vi.advanceTimersByTimeAsync(5 * 60 * 1000);
|
|
40
|
+
expect(firstFind).toHaveBeenCalledTimes(2);
|
|
41
|
+
expect(secondFind).toHaveBeenCalledTimes(1);
|
|
42
|
+
} finally {
|
|
43
|
+
stopPoller(first);
|
|
44
|
+
stopPoller(second);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('prevents concurrent cycles in one application while allowing another application', async () => {
|
|
49
|
+
let finish = () => {};
|
|
50
|
+
const pending = new Promise<never[]>((resolve) => {
|
|
51
|
+
finish = () => resolve([]);
|
|
52
|
+
});
|
|
53
|
+
const firstFind = vi.fn().mockReturnValue(pending);
|
|
54
|
+
const secondFind = vi.fn().mockResolvedValue([]);
|
|
55
|
+
const first = mockApp(firstFind);
|
|
56
|
+
const second = mockApp(secondFind);
|
|
57
|
+
const running = pollAllRepos(first);
|
|
58
|
+
try {
|
|
59
|
+
await pollAllRepos(first);
|
|
60
|
+
await pollAllRepos(second);
|
|
61
|
+
expect(firstFind).toHaveBeenCalledTimes(1);
|
|
62
|
+
expect(secondFind).toHaveBeenCalledTimes(1);
|
|
63
|
+
expect(getPollerStatus(first).polling).toBe(true);
|
|
64
|
+
expect(getPollerStatus(second).polling).toBe(false);
|
|
65
|
+
} finally {
|
|
66
|
+
finish();
|
|
67
|
+
await running;
|
|
68
|
+
}
|
|
69
|
+
expect(getPollerStatus(first).polling).toBe(false);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import { Context } from '@nocobase/actions';
|
|
2
|
-
import { vi } from 'vitest';
|
|
3
|
-
|
|
4
|
-
vi.mock('../poller', () => ({
|
|
5
|
-
pollAllRepos: vi.fn(),
|
|
6
|
-
pollOneRepo: vi.fn(),
|
|
7
|
-
getPollerStatus: vi.fn(),
|
|
8
|
-
}));
|
|
9
|
-
|
|
10
|
-
import { pollNow } from '../actions/poller';
|
|
11
|
-
import { pollAllRepos, pollOneRepo } from '../poller';
|
|
12
|
-
|
|
13
|
-
describe('Git Manager poll action', () => {
|
|
14
|
-
it('uses a repository ID sent in the request body instead of polling every repository', async () => {
|
|
15
|
-
const repository = { id: 10 };
|
|
16
|
-
vi.mocked(pollOneRepo).mockResolvedValue({ scanned: 1, triggered: 0 });
|
|
17
|
-
const context = {
|
|
18
|
-
action: { params: {} },
|
|
19
|
-
request: { body: { repositoryId: 10 } },
|
|
20
|
-
app: {},
|
|
21
|
-
db: {
|
|
22
|
-
getRepository: vi.fn().mockReturnValue({
|
|
23
|
-
findOne: vi.fn().mockResolvedValue(repository),
|
|
24
|
-
}),
|
|
25
|
-
},
|
|
26
|
-
throw: vi.fn(),
|
|
27
|
-
body: undefined as unknown,
|
|
28
|
-
};
|
|
29
|
-
const next = vi.fn().mockResolvedValue(undefined);
|
|
30
|
-
|
|
31
|
-
await pollNow(context as unknown as Context, next);
|
|
32
|
-
|
|
33
|
-
expect(pollOneRepo).toHaveBeenCalledWith(context.app, repository);
|
|
34
|
-
expect(pollAllRepos).not.toHaveBeenCalled();
|
|
35
|
-
expect(context.body).toEqual({ success: true, data: { scanned: 1, triggered: 0 } });
|
|
36
|
-
});
|
|
37
|
-
});
|
|
1
|
+
import { Context } from '@nocobase/actions';
|
|
2
|
+
import { vi } from 'vitest';
|
|
3
|
+
|
|
4
|
+
vi.mock('../poller', () => ({
|
|
5
|
+
pollAllRepos: vi.fn(),
|
|
6
|
+
pollOneRepo: vi.fn(),
|
|
7
|
+
getPollerStatus: vi.fn(),
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
import { pollNow } from '../actions/poller';
|
|
11
|
+
import { pollAllRepos, pollOneRepo } from '../poller';
|
|
12
|
+
|
|
13
|
+
describe('Git Manager poll action', () => {
|
|
14
|
+
it('uses a repository ID sent in the request body instead of polling every repository', async () => {
|
|
15
|
+
const repository = { id: 10 };
|
|
16
|
+
vi.mocked(pollOneRepo).mockResolvedValue({ scanned: 1, triggered: 0 });
|
|
17
|
+
const context = {
|
|
18
|
+
action: { params: {} },
|
|
19
|
+
request: { body: { repositoryId: 10 } },
|
|
20
|
+
app: {},
|
|
21
|
+
db: {
|
|
22
|
+
getRepository: vi.fn().mockReturnValue({
|
|
23
|
+
findOne: vi.fn().mockResolvedValue(repository),
|
|
24
|
+
}),
|
|
25
|
+
},
|
|
26
|
+
throw: vi.fn(),
|
|
27
|
+
body: undefined as unknown,
|
|
28
|
+
};
|
|
29
|
+
const next = vi.fn().mockResolvedValue(undefined);
|
|
30
|
+
|
|
31
|
+
await pollNow(context as unknown as Context, next);
|
|
32
|
+
|
|
33
|
+
expect(pollOneRepo).toHaveBeenCalledWith(context.app, repository);
|
|
34
|
+
expect(pollAllRepos).not.toHaveBeenCalled();
|
|
35
|
+
expect(context.body).toEqual({ success: true, data: { scanned: 1, triggered: 0 } });
|
|
36
|
+
});
|
|
37
|
+
});
|