@whyour/qinglong 2.22.0 → 2.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/back/protos/cron.proto +4 -0
- package/docs/development/node-cron-migration.md +49 -0
- package/docs/development/task-startup.md +78 -0
- package/docs/releases/2.22.0.md +8 -0
- package/docs/releases/2.23.0.md +33 -0
- package/docs/script-history.md +53 -0
- package/package.json +9 -8
- package/scripts/benchmark-script-history.cjs +39 -0
- package/scripts/publish-static.sh +34 -0
- package/scripts/sync-static.sh +20 -0
- package/scripts/wait-for-mirror.sh +214 -0
- package/shell/api.sh +56 -70
- package/shell/node_path_cache.sh +10 -2
- package/shell/otask.sh +7 -9
- package/shell/preload/sitecustomize.js +6 -2
- package/shell/preload/sitecustomize.py +4 -2
- package/shell/share.sh +1 -1
- package/shell/task-timeout.sh +63 -0
- package/shell/task.sh +8 -6
- package/shell/update.sh +40 -95
- package/shell/upgrade.cjs +8 -0
- package/static/build/api/config.js +2 -6
- package/static/build/api/env.js +15 -14
- package/static/build/api/open.js +2 -1
- package/static/build/api/script.js +155 -9
- package/static/build/api/subscription.js +3 -6
- package/static/build/api/system.js +35 -3
- package/static/build/config/grpcCerts.js +89 -40
- package/static/build/config/subscription.js +19 -11
- package/static/build/config/util.js +6 -4
- package/static/build/loaders/express.js +2 -0
- package/static/build/loaders/initData.js +20 -30
- package/static/build/loaders/initTask.js +11 -1
- package/static/build/middlewares/uniqueConstraintError.js +15 -0
- package/static/build/protos/cron.js +63 -2
- package/static/build/schedule/addCron.js +45 -63
- package/static/build/schedule/client.js +19 -1
- package/static/build/schedule/delCron.js +1 -1
- package/static/build/schedule/setConcurrency.js +27 -0
- package/static/build/services/config.js +2 -3
- package/static/build/services/cron.js +36 -10
- package/static/build/services/env.js +1 -1
- package/static/build/services/grpc.js +2 -1
- package/static/build/services/log.js +1 -1
- package/static/build/services/open.js +106 -31
- package/static/build/services/schedule.js +20 -10
- package/static/build/services/script.js +1 -1
- package/static/build/services/scriptHistory.js +30 -0
- package/static/build/services/sshKey.js +39 -14
- package/static/build/services/subscription.js +104 -53
- package/static/build/services/system.js +67 -32
- package/static/build/services/user.js +15 -10
- package/static/build/shared/cronCommand.js +17 -0
- package/static/build/shared/cronSchedule.js +101 -0
- package/static/build/shared/cronScheduler.js +73 -0
- package/static/build/shared/i18n.js +3 -2
- package/static/build/shared/logPath.js +15 -0
- package/static/build/shared/loginThrottle.js +45 -0
- package/static/build/shared/pLimit.js +19 -6
- package/static/build/shared/runCron.js +13 -4
- package/static/build/shared/scriptHistory.js +445 -0
- package/static/build/shared/shellQuote.js +11 -0
- package/static/build/shared/subscriptionMutationLock.js +34 -0
- package/static/build/shared/subscriptionPath.js +41 -0
- package/static/build/shared/subscriptionStorage.js +98 -0
- package/static/build/shared/utils.js +2 -1
- package/static/build/token.js +3 -14
- package/static/build/validation/schedule.js +3 -18
- package/static/dist/292.264757f0.async.js +1 -0
- package/static/dist/3512.95e41255.async.js +1 -0
- package/static/dist/index.html +2 -2
- package/static/dist/preload_helper.01fcd534.js +1 -0
- package/static/dist/src__pages__dependence__modal.0fa8b421.async.js +1 -0
- package/static/dist/src__pages__diff__index.b94e5dc5.async.js +1 -0
- package/static/dist/src__pages__script__editModal.afabf073.async.js +1 -0
- package/static/dist/src__pages__script__editNameModal.789ad87b.async.js +1 -0
- package/static/dist/src__pages__script__historyDrawer.8c58d958.async.js +1 -0
- package/static/dist/src__pages__script__historyDrawer.a449193a.chunk.css +1 -0
- package/static/dist/src__pages__script__index.ab360776.chunk.css +1 -0
- package/static/dist/src__pages__script__index.fc575945.async.js +1 -0
- package/static/dist/src__pages__script__saveModal.8fca1a22.async.js +1 -0
- package/static/dist/src__pages__script__saveWithHistory.99ece830.async.js +1 -0
- package/static/dist/src__pages__subscription__modal.30868ba8.async.js +1 -0
- package/static/dist/{umi.fc019050.js → umi.3a24a9fa.js} +1 -1
- package/test/back/advisory-input-security.test.cjs +416 -0
- package/test/back/code-scanning-security.test.cjs +189 -0
- package/test/back/cron-macros.test.cjs +51 -0
- package/test/back/cron-schedule-compatibility.test.cjs +69 -0
- package/test/back/cron-scheduler-routing.test.cjs +59 -0
- package/test/back/draft-path-security.test.cjs +235 -0
- package/test/back/env-import-security.test.cjs +91 -0
- package/test/back/execution-lifecycle.test.cjs +1 -1
- package/test/back/file-access-scope.test.cjs +180 -0
- package/test/back/grpc-mtls-security.test.cjs +136 -0
- package/test/back/http-security.test.cjs +105 -5
- package/test/back/legacy-cron-recovery.test.cjs +76 -0
- package/test/back/linux-mirror-result.test.cjs +176 -0
- package/test/back/listen-security.test.cjs +1 -0
- package/test/back/mirror-status.test.cjs +257 -0
- package/test/back/node-cron-migration.test.cjs +65 -0
- package/test/back/node-path-cache.test.cjs +29 -0
- package/test/back/node-path-lock.test.cjs +6 -2
- package/test/back/preload-lazy-notify.test.cjs +168 -0
- package/test/back/queued-cron-invalidation.test.cjs +98 -0
- package/test/back/restart-instance-recovery.test.cjs +116 -0
- package/test/back/scheduler-bulk-recovery.test.cjs +40 -0
- package/test/back/scheduler-concurrency.test.cjs +411 -0
- package/test/back/scheduler-reconciliation.test.cjs +58 -4
- package/test/back/script-file-access.test.cjs +210 -0
- package/test/back/script-history-api.test.cjs +551 -0
- package/test/back/script-history.test.cjs +383 -0
- package/test/back/shell-api-parsing.test.cjs +4 -4
- package/test/back/shell-translation-output.test.cjs +16 -0
- package/test/back/shell-upgrade.test.cjs +312 -0
- package/test/back/shellApiToken.test.cjs +151 -0
- package/test/back/ssh-config-home.test.cjs +113 -0
- package/test/back/static-mirror-trigger.test.cjs +441 -0
- package/test/back/static-mirror.test.cjs +179 -0
- package/test/back/stop-race.test.cjs +5 -1
- package/test/back/subscription-mutation-lock.test.cjs +83 -0
- package/test/back/subscription-review-regression.test.cjs +607 -0
- package/test/back/subscription-storage-regression.test.cjs +553 -0
- package/test/back/system-dependence-cache.test.cjs +1 -0
- package/test/back/system-export-history.test.cjs +119 -0
- package/test/back/systemTokenRenewal.test.cjs +497 -0
- package/test/back/task-shell-lifecycle.test.cjs +194 -0
- package/test/back/unique-constraint-error.test.cjs +72 -0
- package/test/back/upgrade-guards.test.cjs +285 -0
- package/test/back/upgrade-lifecycle.test.cjs +288 -0
- package/test/back/upgrade-transaction.test.cjs +133 -0
- package/test/back/user-security.test.cjs +102 -1
- package/test/back/wpush-grpc.test.cjs +1 -0
- package/test/fixtures/legacy-cron.json +1371 -0
- package/test/front/diff-file-routing.test.cjs +126 -0
- package/test/front/script-history-save.test.cjs +121 -0
- package/test/helpers/upgrade-fixture.cjs +30 -0
- package/version.yaml +14 -19
- package/static/dist/2096.6d98fd12.async.js +0 -1
- package/static/dist/4859.97d6653c.async.js +0 -1
- package/static/dist/6707.801b886b.async.js +0 -1
- package/static/dist/preload_helper.cf7de3fa.js +0 -1
- package/static/dist/src__pages__dependence__modal.a29c1a0f.async.js +0 -1
- package/static/dist/src__pages__diff__index.1714b941.async.js +0 -1
- package/static/dist/src__pages__script__editModal.22acdf7c.async.js +0 -1
- package/static/dist/src__pages__script__editNameModal.1a521cc0.async.js +0 -1
- package/static/dist/src__pages__script__index.60b6f827.chunk.css +0 -1
- package/static/dist/src__pages__script__index.a18b2692.async.js +0 -1
- package/static/dist/src__pages__script__saveModal.8965b74c.async.js +0 -1
- package/static/dist/src__pages__subscription__modal.38991e1e.async.js +0 -1
- /package/static/dist/{4859.1b962b29.chunk.css → 292.1b962b29.chunk.css} +0 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
const assert = require('node:assert/strict');
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const os = require('node:os');
|
|
5
|
+
const path = require('node:path');
|
|
6
|
+
const express = require('express');
|
|
7
|
+
const load = require('../helpers/load-security-module.cjs');
|
|
8
|
+
|
|
9
|
+
test('script file operations allow token.json while protecting panel configuration', async (t) => {
|
|
10
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'ql-script-access-'));
|
|
11
|
+
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
12
|
+
for (const dir of [
|
|
13
|
+
'config/grpc',
|
|
14
|
+
'scripts/ZaiZaiCat-Checkin',
|
|
15
|
+
'scripts/token.json',
|
|
16
|
+
'bak',
|
|
17
|
+
'tmp',
|
|
18
|
+
])
|
|
19
|
+
fs.mkdirSync(path.join(root, dir), { recursive: true });
|
|
20
|
+
const config = {
|
|
21
|
+
dataPath: root,
|
|
22
|
+
scriptPath: path.join(root, 'scripts'),
|
|
23
|
+
configPath: path.join(root, 'config'),
|
|
24
|
+
tmpPath: path.join(root, 'tmp'),
|
|
25
|
+
bakPath: path.join(root, 'bak'),
|
|
26
|
+
blackFileList: ['token.json', 'auth.json', 'grpc'],
|
|
27
|
+
};
|
|
28
|
+
config.writePathList = [config.configPath, config.scriptPath];
|
|
29
|
+
const secret = path.join(config.configPath, 'token.json');
|
|
30
|
+
fs.writeFileSync(secret, 'PANEL-SECRET');
|
|
31
|
+
fs.symlinkSync(secret, path.join(config.scriptPath, 'secret-link'));
|
|
32
|
+
fs.symlinkSync(
|
|
33
|
+
config.configPath,
|
|
34
|
+
path.join(config.scriptPath, 'config-link'),
|
|
35
|
+
);
|
|
36
|
+
fs.symlinkSync(secret, path.join(config.configPath, 'secret-alias'));
|
|
37
|
+
const mocks = {
|
|
38
|
+
'../config': config,
|
|
39
|
+
'../config/const': {},
|
|
40
|
+
'../config/util': {
|
|
41
|
+
getFileContentByName: (p) => fs.promises.readFile(p, 'utf8'),
|
|
42
|
+
fileExist: async (p) => fs.existsSync(p),
|
|
43
|
+
rmPath: (p) => fs.promises.rm(p, { recursive: true }),
|
|
44
|
+
readDir: async () => [],
|
|
45
|
+
},
|
|
46
|
+
'../shared/i18n': { t: (x) => x },
|
|
47
|
+
'./sock': {},
|
|
48
|
+
'./cron': {},
|
|
49
|
+
'./schedule': {},
|
|
50
|
+
'../shared/pLimit': {},
|
|
51
|
+
typedi: { Service: () => (x) => x, Inject: () => () => {} },
|
|
52
|
+
};
|
|
53
|
+
const cache = new Map();
|
|
54
|
+
const Script = load(
|
|
55
|
+
path.join(__dirname, '../../back/services/script.ts'),
|
|
56
|
+
mocks,
|
|
57
|
+
cache,
|
|
58
|
+
).default;
|
|
59
|
+
const service = new Script();
|
|
60
|
+
mocks['../services/script'] = Script;
|
|
61
|
+
const History = load(
|
|
62
|
+
path.join(__dirname, '../../back/services/scriptHistory.ts'),
|
|
63
|
+
mocks,
|
|
64
|
+
cache,
|
|
65
|
+
).default;
|
|
66
|
+
const history = new History();
|
|
67
|
+
mocks.typedi = {
|
|
68
|
+
...mocks.typedi,
|
|
69
|
+
Container: { get: (type) => (type === History ? history : service) },
|
|
70
|
+
};
|
|
71
|
+
const app = express.Router();
|
|
72
|
+
load(path.join(__dirname, '../../back/api/script.ts'), mocks, cache).default(
|
|
73
|
+
app,
|
|
74
|
+
);
|
|
75
|
+
const router = app.stack.find((layer) => layer.name === 'router').handle;
|
|
76
|
+
const invoke = async (method, url, body = {}, query = {}, file) => {
|
|
77
|
+
const route = router.stack.find(
|
|
78
|
+
(layer) => layer.route?.path === url && layer.route.methods[method],
|
|
79
|
+
).route;
|
|
80
|
+
let result;
|
|
81
|
+
await route.stack.at(-1).handle(
|
|
82
|
+
{ body, query, file },
|
|
83
|
+
{
|
|
84
|
+
send: (value) => {
|
|
85
|
+
result = value;
|
|
86
|
+
},
|
|
87
|
+
download: (p) => {
|
|
88
|
+
result = { code: 200, data: fs.readFileSync(p, 'utf8') };
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
(error) => {
|
|
92
|
+
throw error;
|
|
93
|
+
},
|
|
94
|
+
);
|
|
95
|
+
return result;
|
|
96
|
+
};
|
|
97
|
+
for (const directory of ['', 'ZaiZaiCat-Checkin']) {
|
|
98
|
+
const filename = directory ? 'token.json' : 'auth.json';
|
|
99
|
+
const body = {
|
|
100
|
+
path: directory,
|
|
101
|
+
filename,
|
|
102
|
+
content: '{"account":"initial"}',
|
|
103
|
+
};
|
|
104
|
+
assert.equal((await invoke('post', '/', body)).code, 200);
|
|
105
|
+
assert.deepEqual(
|
|
106
|
+
await invoke('get', '/detail', {}, { path: directory, file: filename }),
|
|
107
|
+
{ code: 200, data: body.content },
|
|
108
|
+
);
|
|
109
|
+
assert.equal(
|
|
110
|
+
(await invoke('put', '/', { ...body, content: '{"account":"updated"}' }))
|
|
111
|
+
.code,
|
|
112
|
+
200,
|
|
113
|
+
);
|
|
114
|
+
assert.deepEqual(await invoke('post', '/download', body), {
|
|
115
|
+
code: 200,
|
|
116
|
+
data: '{"account":"updated"}',
|
|
117
|
+
});
|
|
118
|
+
assert.equal(
|
|
119
|
+
(await invoke('put', '/rename', { ...body, newFilename: 'renamed.json' }))
|
|
120
|
+
.code,
|
|
121
|
+
200,
|
|
122
|
+
);
|
|
123
|
+
assert.equal(
|
|
124
|
+
(
|
|
125
|
+
await invoke('put', '/rename', {
|
|
126
|
+
...body,
|
|
127
|
+
filename: 'renamed.json',
|
|
128
|
+
newFilename: filename,
|
|
129
|
+
})
|
|
130
|
+
).code,
|
|
131
|
+
200,
|
|
132
|
+
);
|
|
133
|
+
assert.equal((await invoke('delete', '/', body)).code, 200);
|
|
134
|
+
}
|
|
135
|
+
assert.equal(
|
|
136
|
+
(await invoke('get', '/', {}, { path: 'token.json' })).code,
|
|
137
|
+
200,
|
|
138
|
+
);
|
|
139
|
+
const upload = path.join(config.tmpPath, 'upload');
|
|
140
|
+
fs.writeFileSync(upload, 'uploaded');
|
|
141
|
+
assert.equal(
|
|
142
|
+
(
|
|
143
|
+
await invoke(
|
|
144
|
+
'post',
|
|
145
|
+
'/',
|
|
146
|
+
{ filename: 'token.json', path: 'ZaiZaiCat-Checkin' },
|
|
147
|
+
{},
|
|
148
|
+
{ path: upload },
|
|
149
|
+
)
|
|
150
|
+
).code,
|
|
151
|
+
200,
|
|
152
|
+
);
|
|
153
|
+
assert.equal(
|
|
154
|
+
await service.getFile('ZaiZaiCat-Checkin', 'token.json'),
|
|
155
|
+
'uploaded',
|
|
156
|
+
);
|
|
157
|
+
for (const filename of [
|
|
158
|
+
'../config/token.json',
|
|
159
|
+
secret,
|
|
160
|
+
'secret-link',
|
|
161
|
+
'config-link/token.json',
|
|
162
|
+
]) {
|
|
163
|
+
assert.equal(service.checkFilePath('', filename), '', filename);
|
|
164
|
+
assert.equal(
|
|
165
|
+
(await invoke('post', '/download', { filename })).code,
|
|
166
|
+
403,
|
|
167
|
+
filename,
|
|
168
|
+
);
|
|
169
|
+
assert.equal(
|
|
170
|
+
(await invoke('put', '/', { filename, content: 'changed' })).code,
|
|
171
|
+
403,
|
|
172
|
+
filename,
|
|
173
|
+
);
|
|
174
|
+
if (!path.isAbsolute(filename))
|
|
175
|
+
assert.equal(
|
|
176
|
+
(await invoke('post', '/', { filename, content: 'changed' })).code,
|
|
177
|
+
403,
|
|
178
|
+
filename,
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
for (const filename of [
|
|
182
|
+
'token.json',
|
|
183
|
+
'auth.json',
|
|
184
|
+
'grpc/client.key',
|
|
185
|
+
'secret-alias',
|
|
186
|
+
]) {
|
|
187
|
+
assert.equal(
|
|
188
|
+
(
|
|
189
|
+
await invoke('post', '/', {
|
|
190
|
+
path: config.configPath,
|
|
191
|
+
filename,
|
|
192
|
+
content: 'changed',
|
|
193
|
+
})
|
|
194
|
+
).code,
|
|
195
|
+
403,
|
|
196
|
+
filename,
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
assert.equal(fs.readFileSync(secret, 'utf8'), 'PANEL-SECRET');
|
|
200
|
+
assert.equal(
|
|
201
|
+
(
|
|
202
|
+
await invoke('post', '/', {
|
|
203
|
+
path: config.configPath,
|
|
204
|
+
filename: 'normal.txt',
|
|
205
|
+
content: 'normal',
|
|
206
|
+
})
|
|
207
|
+
).code,
|
|
208
|
+
200,
|
|
209
|
+
);
|
|
210
|
+
});
|