@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.
Files changed (150) hide show
  1. package/back/protos/cron.proto +4 -0
  2. package/docs/development/node-cron-migration.md +49 -0
  3. package/docs/development/task-startup.md +78 -0
  4. package/docs/releases/2.22.0.md +8 -0
  5. package/docs/releases/2.23.0.md +33 -0
  6. package/docs/script-history.md +53 -0
  7. package/package.json +9 -8
  8. package/scripts/benchmark-script-history.cjs +39 -0
  9. package/scripts/publish-static.sh +34 -0
  10. package/scripts/sync-static.sh +20 -0
  11. package/scripts/wait-for-mirror.sh +214 -0
  12. package/shell/api.sh +56 -70
  13. package/shell/node_path_cache.sh +10 -2
  14. package/shell/otask.sh +7 -9
  15. package/shell/preload/sitecustomize.js +6 -2
  16. package/shell/preload/sitecustomize.py +4 -2
  17. package/shell/share.sh +1 -1
  18. package/shell/task-timeout.sh +63 -0
  19. package/shell/task.sh +8 -6
  20. package/shell/update.sh +40 -95
  21. package/shell/upgrade.cjs +8 -0
  22. package/static/build/api/config.js +2 -6
  23. package/static/build/api/env.js +15 -14
  24. package/static/build/api/open.js +2 -1
  25. package/static/build/api/script.js +155 -9
  26. package/static/build/api/subscription.js +3 -6
  27. package/static/build/api/system.js +35 -3
  28. package/static/build/config/grpcCerts.js +89 -40
  29. package/static/build/config/subscription.js +19 -11
  30. package/static/build/config/util.js +6 -4
  31. package/static/build/loaders/express.js +2 -0
  32. package/static/build/loaders/initData.js +20 -30
  33. package/static/build/loaders/initTask.js +11 -1
  34. package/static/build/middlewares/uniqueConstraintError.js +15 -0
  35. package/static/build/protos/cron.js +63 -2
  36. package/static/build/schedule/addCron.js +45 -63
  37. package/static/build/schedule/client.js +19 -1
  38. package/static/build/schedule/delCron.js +1 -1
  39. package/static/build/schedule/setConcurrency.js +27 -0
  40. package/static/build/services/config.js +2 -3
  41. package/static/build/services/cron.js +36 -10
  42. package/static/build/services/env.js +1 -1
  43. package/static/build/services/grpc.js +2 -1
  44. package/static/build/services/log.js +1 -1
  45. package/static/build/services/open.js +106 -31
  46. package/static/build/services/schedule.js +20 -10
  47. package/static/build/services/script.js +1 -1
  48. package/static/build/services/scriptHistory.js +30 -0
  49. package/static/build/services/sshKey.js +39 -14
  50. package/static/build/services/subscription.js +104 -53
  51. package/static/build/services/system.js +67 -32
  52. package/static/build/services/user.js +15 -10
  53. package/static/build/shared/cronCommand.js +17 -0
  54. package/static/build/shared/cronSchedule.js +101 -0
  55. package/static/build/shared/cronScheduler.js +73 -0
  56. package/static/build/shared/i18n.js +3 -2
  57. package/static/build/shared/logPath.js +15 -0
  58. package/static/build/shared/loginThrottle.js +45 -0
  59. package/static/build/shared/pLimit.js +19 -6
  60. package/static/build/shared/runCron.js +13 -4
  61. package/static/build/shared/scriptHistory.js +445 -0
  62. package/static/build/shared/shellQuote.js +11 -0
  63. package/static/build/shared/subscriptionMutationLock.js +34 -0
  64. package/static/build/shared/subscriptionPath.js +41 -0
  65. package/static/build/shared/subscriptionStorage.js +98 -0
  66. package/static/build/shared/utils.js +2 -1
  67. package/static/build/token.js +3 -14
  68. package/static/build/validation/schedule.js +3 -18
  69. package/static/dist/292.264757f0.async.js +1 -0
  70. package/static/dist/3512.95e41255.async.js +1 -0
  71. package/static/dist/index.html +2 -2
  72. package/static/dist/preload_helper.01fcd534.js +1 -0
  73. package/static/dist/src__pages__dependence__modal.0fa8b421.async.js +1 -0
  74. package/static/dist/src__pages__diff__index.b94e5dc5.async.js +1 -0
  75. package/static/dist/src__pages__script__editModal.afabf073.async.js +1 -0
  76. package/static/dist/src__pages__script__editNameModal.789ad87b.async.js +1 -0
  77. package/static/dist/src__pages__script__historyDrawer.8c58d958.async.js +1 -0
  78. package/static/dist/src__pages__script__historyDrawer.a449193a.chunk.css +1 -0
  79. package/static/dist/src__pages__script__index.ab360776.chunk.css +1 -0
  80. package/static/dist/src__pages__script__index.fc575945.async.js +1 -0
  81. package/static/dist/src__pages__script__saveModal.8fca1a22.async.js +1 -0
  82. package/static/dist/src__pages__script__saveWithHistory.99ece830.async.js +1 -0
  83. package/static/dist/src__pages__subscription__modal.30868ba8.async.js +1 -0
  84. package/static/dist/{umi.fc019050.js → umi.3a24a9fa.js} +1 -1
  85. package/test/back/advisory-input-security.test.cjs +416 -0
  86. package/test/back/code-scanning-security.test.cjs +189 -0
  87. package/test/back/cron-macros.test.cjs +51 -0
  88. package/test/back/cron-schedule-compatibility.test.cjs +69 -0
  89. package/test/back/cron-scheduler-routing.test.cjs +59 -0
  90. package/test/back/draft-path-security.test.cjs +235 -0
  91. package/test/back/env-import-security.test.cjs +91 -0
  92. package/test/back/execution-lifecycle.test.cjs +1 -1
  93. package/test/back/file-access-scope.test.cjs +180 -0
  94. package/test/back/grpc-mtls-security.test.cjs +136 -0
  95. package/test/back/http-security.test.cjs +105 -5
  96. package/test/back/legacy-cron-recovery.test.cjs +76 -0
  97. package/test/back/linux-mirror-result.test.cjs +176 -0
  98. package/test/back/listen-security.test.cjs +1 -0
  99. package/test/back/mirror-status.test.cjs +257 -0
  100. package/test/back/node-cron-migration.test.cjs +65 -0
  101. package/test/back/node-path-cache.test.cjs +29 -0
  102. package/test/back/node-path-lock.test.cjs +6 -2
  103. package/test/back/preload-lazy-notify.test.cjs +168 -0
  104. package/test/back/queued-cron-invalidation.test.cjs +98 -0
  105. package/test/back/restart-instance-recovery.test.cjs +116 -0
  106. package/test/back/scheduler-bulk-recovery.test.cjs +40 -0
  107. package/test/back/scheduler-concurrency.test.cjs +411 -0
  108. package/test/back/scheduler-reconciliation.test.cjs +58 -4
  109. package/test/back/script-file-access.test.cjs +210 -0
  110. package/test/back/script-history-api.test.cjs +551 -0
  111. package/test/back/script-history.test.cjs +383 -0
  112. package/test/back/shell-api-parsing.test.cjs +4 -4
  113. package/test/back/shell-translation-output.test.cjs +16 -0
  114. package/test/back/shell-upgrade.test.cjs +312 -0
  115. package/test/back/shellApiToken.test.cjs +151 -0
  116. package/test/back/ssh-config-home.test.cjs +113 -0
  117. package/test/back/static-mirror-trigger.test.cjs +441 -0
  118. package/test/back/static-mirror.test.cjs +179 -0
  119. package/test/back/stop-race.test.cjs +5 -1
  120. package/test/back/subscription-mutation-lock.test.cjs +83 -0
  121. package/test/back/subscription-review-regression.test.cjs +607 -0
  122. package/test/back/subscription-storage-regression.test.cjs +553 -0
  123. package/test/back/system-dependence-cache.test.cjs +1 -0
  124. package/test/back/system-export-history.test.cjs +119 -0
  125. package/test/back/systemTokenRenewal.test.cjs +497 -0
  126. package/test/back/task-shell-lifecycle.test.cjs +194 -0
  127. package/test/back/unique-constraint-error.test.cjs +72 -0
  128. package/test/back/upgrade-guards.test.cjs +285 -0
  129. package/test/back/upgrade-lifecycle.test.cjs +288 -0
  130. package/test/back/upgrade-transaction.test.cjs +133 -0
  131. package/test/back/user-security.test.cjs +102 -1
  132. package/test/back/wpush-grpc.test.cjs +1 -0
  133. package/test/fixtures/legacy-cron.json +1371 -0
  134. package/test/front/diff-file-routing.test.cjs +126 -0
  135. package/test/front/script-history-save.test.cjs +121 -0
  136. package/test/helpers/upgrade-fixture.cjs +30 -0
  137. package/version.yaml +14 -19
  138. package/static/dist/2096.6d98fd12.async.js +0 -1
  139. package/static/dist/4859.97d6653c.async.js +0 -1
  140. package/static/dist/6707.801b886b.async.js +0 -1
  141. package/static/dist/preload_helper.cf7de3fa.js +0 -1
  142. package/static/dist/src__pages__dependence__modal.a29c1a0f.async.js +0 -1
  143. package/static/dist/src__pages__diff__index.1714b941.async.js +0 -1
  144. package/static/dist/src__pages__script__editModal.22acdf7c.async.js +0 -1
  145. package/static/dist/src__pages__script__editNameModal.1a521cc0.async.js +0 -1
  146. package/static/dist/src__pages__script__index.60b6f827.chunk.css +0 -1
  147. package/static/dist/src__pages__script__index.a18b2692.async.js +0 -1
  148. package/static/dist/src__pages__script__saveModal.8965b74c.async.js +0 -1
  149. package/static/dist/src__pages__subscription__modal.38991e1e.async.js +0 -1
  150. /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
+ });