@whyour/qinglong 2.21.0-8 → 2.22.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/.dockerignore +13 -0
- package/.env.example +7 -0
- package/AGENTS.md +2 -2
- package/README-en.md +24 -0
- package/README.md +24 -0
- package/back/protos/api.proto +6 -1
- package/back/protos/cron.proto +4 -1
- package/docker/Dockerfile +31 -12
- package/docker/Dockerfile.310 +31 -12
- package/docker/Dockerfile.debian +22 -14
- package/docker/Dockerfile.debian310 +24 -14
- package/docker/build-manifest.cjs +28 -0
- package/docker/verify-build.cjs +49 -0
- package/docs/releases/2.22.0-validation.md +49 -0
- package/docs/releases/2.22.0.md +54 -0
- package/ecosystem.config.js +10 -1
- package/package.json +11 -6
- package/sample/config.sample.sh +10 -0
- package/sample/notify.js +54 -0
- package/sample/notify.py +37 -0
- package/scripts/benchmark-execution.cjs +96 -0
- package/scripts/write-build-info.cjs +27 -0
- package/shell/api.sh +34 -13
- package/shell/check.sh +59 -19
- package/shell/lang/en.sh +6 -0
- package/shell/lang/zh.sh +6 -0
- package/shell/node_path_cache.sh +128 -0
- package/shell/otask.sh +7 -1
- package/shell/preload/sitecustomize.js +5 -1
- package/shell/share.sh +25 -8
- package/shell/start.sh +6 -3
- package/shell/task.sh +13 -3
- package/shell/update.sh +65 -4
- package/static/build/api/clientIp.js +42 -0
- package/static/build/api/config.js +8 -16
- package/static/build/api/cron.js +38 -2
- package/static/build/api/dashboard.js +37 -0
- package/static/build/api/health.js +2 -2
- package/static/build/api/index.js +4 -0
- package/static/build/api/log.js +30 -19
- package/static/build/api/retention.js +63 -0
- package/static/build/api/script.js +23 -22
- package/static/build/api/subscription.js +16 -2
- package/static/build/api/system.js +25 -2
- package/static/build/api/user.js +75 -15
- package/static/build/app.js +54 -45
- package/static/build/bootstrap/database.js +51 -0
- package/static/build/config/const.js +1 -0
- package/static/build/config/share.js +5 -4
- package/static/build/config/util.js +133 -38
- package/static/build/data/cron.js +1 -0
- package/static/build/data/notify.js +11 -1
- package/static/build/loaders/app.js +2 -0
- package/static/build/loaders/db.js +3 -33
- package/static/build/loaders/deps.js +29 -0
- package/static/build/loaders/express.js +30 -21
- package/static/build/loaders/initData.js +10 -7
- package/static/build/loaders/sock.js +72 -6
- package/static/build/middlewares/monitoring.js +12 -33
- package/static/build/middlewares/protectedPathCase.js +17 -0
- package/static/build/protos/api.js +56 -2
- package/static/build/protos/cron.js +21 -4
- package/static/build/protos/health.js +1 -1
- package/static/build/schedule/addCron.js +9 -0
- package/static/build/schedule/api.js +5 -2
- package/static/build/schedule/client.js +38 -6
- package/static/build/schedule/health.js +72 -7
- package/static/build/services/config.js +5 -42
- package/static/build/services/cron.js +338 -199
- package/static/build/services/dependence.js +47 -0
- package/static/build/services/grpc.js +1 -1
- package/static/build/services/health.js +4 -7
- package/static/build/services/http.js +8 -2
- package/static/build/services/log.js +2 -3
- package/static/build/services/metrics.js +46 -14
- package/static/build/services/notify.js +26 -0
- package/static/build/services/retention.js +123 -0
- package/static/build/services/schedule.js +57 -33
- package/static/build/services/script.js +4 -5
- package/static/build/services/subscription.js +55 -34
- package/static/build/services/system.js +37 -9
- package/static/build/services/user.js +213 -25
- package/static/build/shared/auth.js +18 -5
- package/static/build/shared/authMutation.js +17 -0
- package/static/build/shared/childProcess.js +82 -0
- package/static/build/shared/clientIp.js +27 -0
- package/static/build/shared/errors.js +9 -0
- package/static/build/shared/fileAccess.js +60 -0
- package/static/build/shared/i18n.js +12 -5
- package/static/build/shared/logReader.js +85 -0
- package/static/build/shared/logStreamManager.js +80 -60
- package/static/build/shared/password.js +30 -0
- package/static/build/shared/retention.js +58 -0
- package/static/build/shared/runCron.js +28 -15
- package/static/build/shared/schedulerMutationLock.js +44 -0
- package/static/build/shared/schedulerReadiness.js +82 -0
- package/static/build/shared/schemaMigrations.js +58 -0
- package/static/build/shared/startupProcess.js +48 -0
- package/static/build/shared/store.js +7 -0
- package/static/build/shared/trustProxy.js +119 -0
- package/static/build/validation/schedule.js +3 -3
- package/static/dist/{1885.e1ea09f6.async.js → 1885.b8f427bf.async.js} +1 -1
- package/static/dist/2031.6af40025.async.js +1 -0
- package/static/dist/2693.51c2636b.async.js +1 -0
- package/static/dist/{2890.9e373f5b.async.js → 2890.add55e85.async.js} +1 -1
- package/static/dist/2901.2ca95295.async.js +1 -0
- package/static/dist/445.a65ff63b.async.js +1 -0
- package/static/dist/4736.1d2b5cb6.async.js +1 -0
- package/static/dist/{4859.6592cebb.async.js → 4859.97d6653c.async.js} +1 -1
- package/static/dist/{6013.4e38de36.async.js → 6013.db535339.async.js} +1 -1
- package/static/dist/6212.9e6d9913.async.js +1 -0
- package/static/dist/{6339.ab305e96.async.js → 6431.4603ad0e.async.js} +1 -1
- package/static/dist/{6872.42f939f1.async.js → 6872.a503ef55.async.js} +1 -1
- package/static/dist/7231.f7e5b668.async.js +1 -0
- package/static/dist/{7355.f9f263d8.async.js → 7355.fca746f5.async.js} +1 -1
- package/static/dist/{7508.7dcee91c.async.js → 7508.d90eac63.async.js} +1 -1
- package/static/dist/{7984.594296a5.async.js → 7984.eaac7402.async.js} +1 -1
- package/static/dist/8844.a0fef08e.async.js +1 -0
- package/static/dist/index.html +2 -2
- package/static/dist/layouts__index.633d3553.async.js +1 -0
- package/static/dist/preload_helper.cf7de3fa.js +1 -0
- package/static/dist/{src__pages__config__index.a22ff7dc.async.js → src__pages__config__index.9aba4054.async.js} +1 -1
- package/static/dist/src__pages__crontab__detail.86b2eebb.async.js +1 -0
- package/static/dist/src__pages__crontab__index.ae4e06f2.async.js +1 -0
- package/static/dist/{src__pages__crontab__logModal.831d5e4b.async.js → src__pages__crontab__logModal.930535e2.async.js} +1 -1
- package/static/dist/src__pages__crontab__modal.a2c8fdcc.async.js +1 -0
- package/static/dist/src__pages__crontab__viewCreateModal.7b4f9cbe.async.js +1 -0
- package/static/dist/src__pages__crontab__viewManageModal.cd454ea0.async.js +1 -0
- package/static/dist/src__pages__dashboard__index.243c5a35.async.js +1 -0
- package/static/dist/src__pages__dashboard__taskResultModal.7795d6e1.async.js +1 -0
- package/static/dist/src__pages__dependence__index.874d501f.async.js +1 -0
- package/static/dist/src__pages__dependence__logModal.154efe7a.async.js +1 -0
- package/static/dist/src__pages__dependence__modal.a29c1a0f.async.js +1 -0
- package/static/dist/{src__pages__diff__index.013b7c75.async.js → src__pages__diff__index.1714b941.async.js} +1 -1
- package/static/dist/src__pages__env__editNameModal.c13d47d2.async.js +1 -0
- package/static/dist/src__pages__env__index.fd6fd2b0.async.js +1 -0
- package/static/dist/src__pages__env__modal.4d71adb3.async.js +1 -0
- package/static/dist/src__pages__error__index.aae50c94.async.js +1 -0
- package/static/dist/src__pages__initialization__index.82a2e967.async.js +1 -0
- package/static/dist/src__pages__log__index.71250e0d.async.js +1 -0
- package/static/dist/{src__pages__login__index.8c813eb1.async.js → src__pages__login__index.a0fd5ed8.async.js} +1 -1
- package/static/dist/src__pages__script__editModal.22acdf7c.async.js +1 -0
- package/static/dist/src__pages__script__editNameModal.1a521cc0.async.js +1 -0
- package/static/dist/src__pages__script__index.a18b2692.async.js +1 -0
- package/static/dist/src__pages__script__renameModal.0ab029e7.async.js +1 -0
- package/static/dist/src__pages__script__saveModal.8965b74c.async.js +1 -0
- package/static/dist/src__pages__script__setting.35ad4f02.async.js +1 -0
- package/static/dist/src__pages__setting__appModal.7eaeb9d3.async.js +1 -0
- package/static/dist/{src__pages__setting__checkUpdate.34d773f2.async.js → src__pages__setting__checkUpdate.d175b154.async.js} +1 -1
- package/static/dist/src__pages__setting__clientIp.3a8711ed.async.js +1 -0
- package/static/dist/src__pages__setting__dependence.9c0f749b.async.js +1 -0
- package/static/dist/src__pages__setting__index.cb397741.async.js +1 -0
- package/static/dist/src__pages__setting__loginLog.e0a1f54d.async.js +1 -0
- package/static/dist/src__pages__setting__notification.2ffe4e5a.async.js +1 -0
- package/static/dist/src__pages__setting__other.3d0b8492.async.js +1 -0
- package/static/dist/{src__pages__setting__progress.8823ac90.async.js → src__pages__setting__progress.2ccae3d7.async.js} +1 -1
- package/static/dist/src__pages__setting__security.e2d71ebb.async.js +1 -0
- package/static/dist/src__pages__setting__systemLog.b3046955.async.js +1 -0
- package/static/dist/src__pages__subscription__index.43086a06.async.js +1 -0
- package/static/dist/src__pages__subscription__logModal.cdba5139.async.js +1 -0
- package/static/dist/src__pages__subscription__modal.38991e1e.async.js +1 -0
- package/static/dist/{umi.a54a59f6.js → umi.fc019050.js} +1 -1
- package/test/back/auth-security.test.cjs +74 -0
- package/test/back/build-provenance.test.cjs +150 -0
- package/test/back/cron-log-name.test.cjs +110 -0
- package/test/back/cron-validation.test.cjs +45 -0
- package/test/back/dashboard-failures.test.cjs +173 -0
- package/test/back/database-bootstrap.test.cjs +193 -0
- package/test/back/dependence-cache-status.test.cjs +125 -0
- package/test/back/deprecated-file-routes.test.cjs +82 -0
- package/test/back/ecosystem.test.cjs +28 -0
- package/test/back/env-name-parsing.test.cjs +96 -0
- package/test/back/execution-lifecycle.test.cjs +236 -0
- package/test/back/file-access-security.test.cjs +47 -0
- package/test/back/fileTreeListing.test.cjs +57 -0
- package/test/back/grpc-cron-response.test.cjs +60 -0
- package/test/back/http-exclusive-listen.test.cjs +31 -0
- package/test/back/http-security.test.cjs +213 -0
- package/test/back/listen-security.test.cjs +67 -0
- package/test/back/log-path-security.test.cjs +158 -0
- package/test/back/logReader.test.cjs +72 -0
- package/test/back/manual-execution.test.cjs +85 -0
- package/test/back/manual-stop-claim.test.cjs +220 -0
- package/test/back/metrics.test.cjs +34 -0
- package/test/back/monitoring.test.cjs +73 -0
- package/test/back/node-path-cache.test.cjs +173 -0
- package/test/back/node-path-lock.test.cjs +178 -0
- package/test/back/npm-publication.test.cjs +70 -0
- package/test/back/primary-apm.test.cjs +24 -0
- package/test/back/process-exit-state.test.cjs +81 -0
- package/test/back/process-stop-signal.test.cjs +77 -0
- package/test/back/protected-path-case.test.cjs +58 -0
- package/test/back/qlServiceLogCommand.test.cjs +128 -0
- package/test/back/retention.test.cjs +131 -0
- package/test/back/role-loading.test.cjs +118 -0
- package/test/back/schedule-health.test.cjs +86 -0
- package/test/back/scheduler-file-lock.test.cjs +51 -0
- package/test/back/scheduler-mutation.test.cjs +312 -0
- package/test/back/scheduler-readiness.test.cjs +85 -0
- package/test/back/scheduler-reconciliation.test.cjs +152 -0
- package/test/back/scheduler-rpc-timeout.test.cjs +49 -0
- package/test/back/schema-migrations.test.cjs +127 -0
- package/test/back/shell-api-parsing.test.cjs +184 -0
- package/test/back/sock-polling.test.cjs +297 -0
- package/test/back/sock-security.test.cjs +72 -0
- package/test/back/start-env-preservation.test.cjs +53 -0
- package/test/back/stop-failure-feedback.test.cjs +158 -0
- package/test/back/stop-race.test.cjs +167 -0
- package/test/back/subscription-cleanup.test.cjs +53 -0
- package/test/back/subscription-stop-state.test.cjs +66 -0
- package/test/back/system-dependence-cache.test.cjs +126 -0
- package/test/back/task-time.test.cjs +116 -0
- package/test/back/user-api.test.cjs +99 -0
- package/test/back/user-security.test.cjs +248 -0
- package/test/back/worker-apm.test.cjs +84 -0
- package/test/back/wpush-grpc.test.cjs +115 -0
- package/test/front/cron-log-pagination.test.cjs +214 -0
- package/test/front/http-auth.test.cjs +152 -0
- package/test/front/http-error.test.cjs +29 -0
- package/test/helpers/load-security-module.cjs +42 -0
- package/version.yaml +19 -34
- package/CLAUDE.md +0 -43
- package/static/dist/1147.62793604.async.js +0 -1
- package/static/dist/134.54df9e38.async.js +0 -1
- package/static/dist/2208.85285476.async.js +0 -1
- package/static/dist/2286.f371c743.async.js +0 -1
- package/static/dist/3191.545ab873.async.js +0 -1
- package/static/dist/4902.555f92ab.async.js +0 -1
- package/static/dist/5520.ff2cfd6b.async.js +0 -1
- package/static/dist/6431.c50479be.async.js +0 -1
- package/static/dist/8826.db34ad8d.async.js +0 -1
- package/static/dist/layouts__index.a7a2bfe0.async.js +0 -1
- package/static/dist/preload_helper.3048fe5b.js +0 -1
- package/static/dist/src__pages__crontab__detail.b98f0084.async.js +0 -1
- package/static/dist/src__pages__crontab__index.68e78a33.async.js +0 -1
- package/static/dist/src__pages__crontab__modal.f7041c7c.async.js +0 -1
- package/static/dist/src__pages__crontab__viewCreateModal.4d589f66.async.js +0 -1
- package/static/dist/src__pages__crontab__viewManageModal.0e317746.async.js +0 -1
- package/static/dist/src__pages__dashboard__index.58177357.async.js +0 -1
- package/static/dist/src__pages__dependence__index.b7bbc795.async.js +0 -1
- package/static/dist/src__pages__dependence__logModal.0681830b.async.js +0 -1
- package/static/dist/src__pages__dependence__modal.f7bb47ba.async.js +0 -1
- package/static/dist/src__pages__env__editNameModal.48715576.async.js +0 -1
- package/static/dist/src__pages__env__index.452cdc47.async.js +0 -1
- package/static/dist/src__pages__env__modal.e1234834.async.js +0 -1
- package/static/dist/src__pages__error__index.dedb2b90.async.js +0 -1
- package/static/dist/src__pages__initialization__index.22620a77.async.js +0 -1
- package/static/dist/src__pages__log__index.9c66639f.async.js +0 -1
- package/static/dist/src__pages__script__editModal.cbf4ec0e.async.js +0 -1
- package/static/dist/src__pages__script__editNameModal.532a3044.async.js +0 -1
- package/static/dist/src__pages__script__index.1fc20f22.async.js +0 -1
- package/static/dist/src__pages__script__renameModal.5cdde919.async.js +0 -1
- package/static/dist/src__pages__script__saveModal.5ffed35f.async.js +0 -1
- package/static/dist/src__pages__script__setting.1a82c6d7.async.js +0 -1
- package/static/dist/src__pages__setting__appModal.43b7758a.async.js +0 -1
- package/static/dist/src__pages__setting__dependence.9c04c79a.async.js +0 -1
- package/static/dist/src__pages__setting__index.7e070838.async.js +0 -1
- package/static/dist/src__pages__setting__loginLog.cea6056c.async.js +0 -1
- package/static/dist/src__pages__setting__notification.bac481c2.async.js +0 -1
- package/static/dist/src__pages__setting__other.707cfafe.async.js +0 -1
- package/static/dist/src__pages__setting__security.b7235753.async.js +0 -1
- package/static/dist/src__pages__setting__systemLog.b81a8c1d.async.js +0 -1
- package/static/dist/src__pages__subscription__index.d0ab2abc.async.js +0 -1
- package/static/dist/src__pages__subscription__logModal.3864b37f.async.js +0 -1
- package/static/dist/src__pages__subscription__modal.562448e2.async.js +0 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const assert = require('node:assert/strict');
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
const jwt = require('jsonwebtoken');
|
|
5
|
+
const load = require('../helpers/load-security-module.cjs');
|
|
6
|
+
const { isValidToken } = load(
|
|
7
|
+
path.join(__dirname, '../../back/shared/auth.ts'),
|
|
8
|
+
);
|
|
9
|
+
const { hashPassword, verifyPassword } = load(
|
|
10
|
+
path.join(__dirname, '../../back/shared/password.ts'),
|
|
11
|
+
);
|
|
12
|
+
const secret = 'security-test-secret';
|
|
13
|
+
const token = (payload = {}, options = {}) =>
|
|
14
|
+
jwt.sign(payload, secret, {
|
|
15
|
+
algorithm: 'HS384',
|
|
16
|
+
expiresIn: '1h',
|
|
17
|
+
...options,
|
|
18
|
+
});
|
|
19
|
+
const info = (value) => ({ token: value, tokens: {} });
|
|
20
|
+
|
|
21
|
+
test('valid legacy and platform sessions retain compatibility', () => {
|
|
22
|
+
const value = token();
|
|
23
|
+
for (const auth of [
|
|
24
|
+
info(value),
|
|
25
|
+
{ tokens: { desktop: value } },
|
|
26
|
+
{ tokens: { desktop: [{ value }] } },
|
|
27
|
+
]) {
|
|
28
|
+
assert.equal(isValidToken(auth, value, 'desktop', secret), true);
|
|
29
|
+
}
|
|
30
|
+
assert.equal(
|
|
31
|
+
isValidToken({ tokens: { mobile: value } }, value, 'desktop', secret),
|
|
32
|
+
false,
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('session membership never bypasses JWT signature, expiry, algorithm or nbf', () => {
|
|
37
|
+
const values = [
|
|
38
|
+
token({}, { expiresIn: -1 }),
|
|
39
|
+
token({}, { algorithm: 'HS256' }),
|
|
40
|
+
token({ nbf: Math.floor(Date.now() / 1000) + 60 }),
|
|
41
|
+
jwt.sign({}, 'wrong-secret', { algorithm: 'HS384', expiresIn: '1h' }),
|
|
42
|
+
jwt.sign({}, secret, { algorithm: 'HS384' }),
|
|
43
|
+
'not-a-token',
|
|
44
|
+
];
|
|
45
|
+
for (const value of values)
|
|
46
|
+
assert.equal(isValidToken(info(value), value, 'desktop', secret), false);
|
|
47
|
+
assert.equal(isValidToken({ tokens: {} }, token(), 'desktop', secret), false);
|
|
48
|
+
assert.equal(isValidToken(null, token(), 'desktop', secret), false);
|
|
49
|
+
assert.equal(isValidToken(info(''), '', 'desktop', secret), false);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('platform token metadata can shorten but cannot extend JWT expiration', () => {
|
|
53
|
+
const value = token();
|
|
54
|
+
assert.equal(
|
|
55
|
+
isValidToken(
|
|
56
|
+
{ tokens: { desktop: [{ value, expiration: 1 }] } },
|
|
57
|
+
value,
|
|
58
|
+
'desktop',
|
|
59
|
+
secret,
|
|
60
|
+
),
|
|
61
|
+
false,
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('passwords are salted and legacy plaintext can migrate without changing the password', async () => {
|
|
66
|
+
const first = await hashPassword('owner-password');
|
|
67
|
+
const second = await hashPassword('owner-password');
|
|
68
|
+
assert.notEqual(first, second);
|
|
69
|
+
assert.equal(await verifyPassword('owner-password', first), true);
|
|
70
|
+
assert.equal(await verifyPassword('wrong-password', first), false);
|
|
71
|
+
assert.equal(await verifyPassword(first, first), false);
|
|
72
|
+
assert.equal(await verifyPassword('old-password', 'old-password'), true);
|
|
73
|
+
assert.equal(await verifyPassword('wrong', 'old-password'), false);
|
|
74
|
+
});
|
|
@@ -0,0 +1,150 @@
|
|
|
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 { execFileSync, spawnSync } = require('node:child_process');
|
|
7
|
+
|
|
8
|
+
test('build verification accepts matching source and rejects stale or dirty artifacts', (t) => {
|
|
9
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'ql-build-source-'));
|
|
10
|
+
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
|
|
11
|
+
const git = (...args) =>
|
|
12
|
+
execFileSync('git', args, { cwd: dir, stdio: 'pipe' });
|
|
13
|
+
git('init');
|
|
14
|
+
git('config', 'user.name', 'Build test');
|
|
15
|
+
git('config', 'user.email', 'build-test@example.invalid');
|
|
16
|
+
fs.writeFileSync(path.join(dir, 'pnpm-lock.yaml'), 'lockfileVersion: 6.0\n');
|
|
17
|
+
fs.writeFileSync(path.join(dir, '.gitignore'), 'static/\n');
|
|
18
|
+
git('add', '.');
|
|
19
|
+
git('commit', '-m', 'fixture');
|
|
20
|
+
fs.mkdirSync(path.join(dir, 'static/build'), { recursive: true });
|
|
21
|
+
fs.mkdirSync(path.join(dir, 'static/dist'), { recursive: true });
|
|
22
|
+
fs.writeFileSync(path.join(dir, 'static/build/app.js'), '');
|
|
23
|
+
fs.writeFileSync(path.join(dir, 'static/dist/index.html'), '');
|
|
24
|
+
const write = path.resolve('scripts/write-build-info.cjs');
|
|
25
|
+
const verify = path.resolve('docker/verify-build.cjs');
|
|
26
|
+
execFileSync(process.execPath, [write], { cwd: dir });
|
|
27
|
+
execFileSync(process.execPath, [verify], { cwd: dir });
|
|
28
|
+
const manifestPath = path.join(dir, 'static/build-info.json');
|
|
29
|
+
const manifest = JSON.parse(fs.readFileSync(manifestPath));
|
|
30
|
+
for (const invalid of [
|
|
31
|
+
{ ...manifest, sourceCommit: '0'.repeat(40) },
|
|
32
|
+
{ ...manifest, dirty: true },
|
|
33
|
+
{ ...manifest, lockfileSha256: '0'.repeat(64) },
|
|
34
|
+
]) {
|
|
35
|
+
fs.writeFileSync(manifestPath, JSON.stringify(invalid));
|
|
36
|
+
assert.notEqual(
|
|
37
|
+
spawnSync(process.execPath, [verify], { cwd: dir }).status,
|
|
38
|
+
0,
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('release images receive the same-run artifact and verify it before use', () => {
|
|
44
|
+
const yaml = require('js-yaml');
|
|
45
|
+
const workflow = yaml.load(
|
|
46
|
+
fs.readFileSync('.github/workflows/build-docker-image.yml', 'utf8'),
|
|
47
|
+
);
|
|
48
|
+
assert.equal(workflow.jobs['build-static'].needs, 'validate');
|
|
49
|
+
const upload = workflow.jobs['build-static'].steps.find(step => step.uses?.startsWith('actions/upload-artifact@'));
|
|
50
|
+
assert.equal(upload.with['include-hidden-files'], true);
|
|
51
|
+
for (const name of [
|
|
52
|
+
'build-alpine',
|
|
53
|
+
'build-debian',
|
|
54
|
+
'build-alpine310',
|
|
55
|
+
'build-debian310',
|
|
56
|
+
]) {
|
|
57
|
+
const job = workflow.jobs[name];
|
|
58
|
+
assert.equal(job.needs, 'build-static');
|
|
59
|
+
const download = job.steps.find((step) =>
|
|
60
|
+
step.uses?.startsWith('actions/download-artifact@'),
|
|
61
|
+
);
|
|
62
|
+
assert.equal(download.with.name, 'qinglong-static-${{ github.sha }}');
|
|
63
|
+
assert.equal(download.with.path, 'static/');
|
|
64
|
+
const build = job.steps.find((step) =>
|
|
65
|
+
step.uses?.startsWith('docker/build-push-action@'),
|
|
66
|
+
);
|
|
67
|
+
assert.match(
|
|
68
|
+
build.with['build-args'],
|
|
69
|
+
/SOURCE_COMMIT=\$\{\{ github.sha \}\}/,
|
|
70
|
+
);
|
|
71
|
+
const dockerfile = fs.readFileSync(build.with.file, 'utf8');
|
|
72
|
+
assert.doesNotMatch(dockerfile, /git clone.*qinglong-static/);
|
|
73
|
+
assert.match(
|
|
74
|
+
dockerfile,
|
|
75
|
+
/git fetch --depth=1 origin "\$\{SOURCE_COMMIT\}"/,
|
|
76
|
+
);
|
|
77
|
+
assert.match(dockerfile, /node \/tmp\/verify-build.cjs/);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('complete artifact manifests reject changed, missing, extra files and untracked build inputs', (t) => {
|
|
82
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'ql-build-manifest-'));
|
|
83
|
+
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
|
|
84
|
+
const git = (...args) =>
|
|
85
|
+
execFileSync('git', args, { cwd: dir, stdio: 'pipe' });
|
|
86
|
+
git('init');
|
|
87
|
+
git('config', 'user.name', 'Build test');
|
|
88
|
+
git('config', 'user.email', 'build-test@example.invalid');
|
|
89
|
+
fs.writeFileSync(path.join(dir, '.gitignore'), 'static/\n');
|
|
90
|
+
fs.writeFileSync(path.join(dir, 'pnpm-lock.yaml'), 'lockfileVersion: 6.0\n');
|
|
91
|
+
git('add', '.');
|
|
92
|
+
git('commit', '-m', 'fixture');
|
|
93
|
+
const artifacts = [
|
|
94
|
+
'build/app.js',
|
|
95
|
+
'build/services/http.js',
|
|
96
|
+
'dist/index.html',
|
|
97
|
+
'dist/chunks/main.js',
|
|
98
|
+
'dist/assets/main.css',
|
|
99
|
+
'dist/.well-known/config',
|
|
100
|
+
];
|
|
101
|
+
for (const file of artifacts) {
|
|
102
|
+
fs.mkdirSync(path.dirname(path.join(dir, 'static', file)), {
|
|
103
|
+
recursive: true,
|
|
104
|
+
});
|
|
105
|
+
fs.writeFileSync(path.join(dir, 'static', file), file);
|
|
106
|
+
}
|
|
107
|
+
const write = path.resolve('scripts/write-build-info.cjs');
|
|
108
|
+
const verify = path.resolve('docker/verify-build.cjs');
|
|
109
|
+
const run = (script) =>
|
|
110
|
+
spawnSync(process.execPath, [script], { cwd: dir, encoding: 'utf8' });
|
|
111
|
+
assert.equal(run(write).status, 0);
|
|
112
|
+
const manifestFile = path.join(dir, 'static/build-info.json');
|
|
113
|
+
const original = fs.readFileSync(manifestFile, 'utf8');
|
|
114
|
+
assert.deepEqual(
|
|
115
|
+
Object.keys(JSON.parse(original).files).sort(),
|
|
116
|
+
artifacts.sort(),
|
|
117
|
+
);
|
|
118
|
+
assert.equal(run(write).status, 0);
|
|
119
|
+
assert.equal(fs.readFileSync(manifestFile, 'utf8'), original);
|
|
120
|
+
assert.equal(run(verify).status, 0);
|
|
121
|
+
for (const name of [
|
|
122
|
+
'build/services/http.js',
|
|
123
|
+
'dist/chunks/main.js',
|
|
124
|
+
'dist/assets/main.css',
|
|
125
|
+
'dist/.well-known/config',
|
|
126
|
+
]) {
|
|
127
|
+
const file = path.join(dir, 'static', name);
|
|
128
|
+
fs.writeFileSync(file, 'stale');
|
|
129
|
+
assert.notEqual(run(verify).status, 0);
|
|
130
|
+
fs.unlinkSync(file);
|
|
131
|
+
assert.notEqual(run(verify).status, 0);
|
|
132
|
+
fs.writeFileSync(file, name);
|
|
133
|
+
assert.equal(run(verify).status, 0);
|
|
134
|
+
}
|
|
135
|
+
const extra = path.join(dir, 'static/build/stale.js');
|
|
136
|
+
fs.writeFileSync(extra, 'extra');
|
|
137
|
+
assert.notEqual(run(verify).status, 0);
|
|
138
|
+
fs.unlinkSync(extra);
|
|
139
|
+
const source = path.join(dir, 'custom.config.js');
|
|
140
|
+
fs.writeFileSync(source, 'untracked build input');
|
|
141
|
+
assert.equal(run(write).status, 0);
|
|
142
|
+
assert.equal(JSON.parse(fs.readFileSync(manifestFile)).dirty, true);
|
|
143
|
+
assert.notEqual(run(verify).status, 0);
|
|
144
|
+
fs.unlinkSync(source);
|
|
145
|
+
assert.equal(run(write).status, 0);
|
|
146
|
+
assert.equal(run(verify).status, 0);
|
|
147
|
+
fs.symlinkSync(path.join(dir, 'pnpm-lock.yaml'), extra);
|
|
148
|
+
assert.notEqual(run(write).status, 0);
|
|
149
|
+
assert.notEqual(run(verify).status, 0);
|
|
150
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
const assert = require('node:assert/strict');
|
|
2
|
+
const fs = require('node:fs');
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
const test = require('node:test');
|
|
5
|
+
const ts = require('typescript');
|
|
6
|
+
const loadModule = require('../helpers/load-security-module.cjs');
|
|
7
|
+
|
|
8
|
+
const { commonCronSchema } = loadModule(
|
|
9
|
+
path.join(__dirname, '../../back/validation/schedule.ts'),
|
|
10
|
+
{ '../config': { logPath: '/ql/data/log/' } },
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
// Execute the actual form validator without mounting the entire task modal.
|
|
14
|
+
const source = ts.createSourceFile(
|
|
15
|
+
'modal.tsx',
|
|
16
|
+
fs.readFileSync(
|
|
17
|
+
path.join(__dirname, '../../src/pages/crontab/modal.tsx'),
|
|
18
|
+
'utf8',
|
|
19
|
+
),
|
|
20
|
+
ts.ScriptTarget.Latest,
|
|
21
|
+
true,
|
|
22
|
+
ts.ScriptKind.TSX,
|
|
23
|
+
);
|
|
24
|
+
let validateForm;
|
|
25
|
+
function visit(node) {
|
|
26
|
+
if (
|
|
27
|
+
ts.isJsxOpeningElement(node) &&
|
|
28
|
+
node.attributes.properties.some(
|
|
29
|
+
(attr) =>
|
|
30
|
+
ts.isJsxAttribute(attr) &&
|
|
31
|
+
attr.name.text === 'name' &&
|
|
32
|
+
attr.initializer?.text === 'log_name',
|
|
33
|
+
)
|
|
34
|
+
) {
|
|
35
|
+
const rules = node.attributes.properties.find(
|
|
36
|
+
(attr) => ts.isJsxAttribute(attr) && attr.name.text === 'rules',
|
|
37
|
+
);
|
|
38
|
+
const validator = rules.initializer.expression.elements[0].properties.find(
|
|
39
|
+
(property) => property.name.text === 'validator',
|
|
40
|
+
).initializer;
|
|
41
|
+
const { outputText } = ts.transpileModule(
|
|
42
|
+
`const validate = ${validator.getText(source)};`,
|
|
43
|
+
{ compilerOptions: { target: ts.ScriptTarget.ES2017 } },
|
|
44
|
+
);
|
|
45
|
+
validateForm = new Function('intl', `${outputText}\nreturn validate;`)({
|
|
46
|
+
get: (key) => key,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
ts.forEachChild(node, visit);
|
|
50
|
+
}
|
|
51
|
+
visit(source);
|
|
52
|
+
assert.equal(typeof validateForm, 'function');
|
|
53
|
+
|
|
54
|
+
test('form and API accept Chinese log names and existing supported names', async () => {
|
|
55
|
+
for (const value of [
|
|
56
|
+
'',
|
|
57
|
+
null,
|
|
58
|
+
undefined,
|
|
59
|
+
'测试',
|
|
60
|
+
'任务_測試-2026.log',
|
|
61
|
+
'分组/每日签到/',
|
|
62
|
+
'𠮷/扩展汉字',
|
|
63
|
+
'legacy_name-123.log',
|
|
64
|
+
'legacy/path/',
|
|
65
|
+
'/ql/data/log/中文日志',
|
|
66
|
+
'/dev/null',
|
|
67
|
+
'中'.repeat(100),
|
|
68
|
+
]) {
|
|
69
|
+
await validateForm(undefined, value);
|
|
70
|
+
assert.equal(
|
|
71
|
+
commonCronSchema.log_name.validate(value).error,
|
|
72
|
+
undefined,
|
|
73
|
+
value,
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('form and API still reject unsafe relative names and excessive length', async () => {
|
|
79
|
+
for (const value of [
|
|
80
|
+
'.',
|
|
81
|
+
'..',
|
|
82
|
+
'../测试',
|
|
83
|
+
'测试/../日志',
|
|
84
|
+
'测试/./日志',
|
|
85
|
+
'测试//日志',
|
|
86
|
+
'测试\\日志',
|
|
87
|
+
'测试 日志',
|
|
88
|
+
'测试;echo',
|
|
89
|
+
'测试$(id)',
|
|
90
|
+
'测试`id`',
|
|
91
|
+
'测试\n日志',
|
|
92
|
+
'测试\0日志',
|
|
93
|
+
'测试😀',
|
|
94
|
+
'中'.repeat(101),
|
|
95
|
+
]) {
|
|
96
|
+
await assert.rejects(validateForm(undefined, value), undefined, value);
|
|
97
|
+
assert.ok(commonCronSchema.log_name.validate(value).error, value);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test('API restricts absolute log paths to the configured directory or /dev/null', () => {
|
|
102
|
+
for (const value of [
|
|
103
|
+
'/tmp/测试',
|
|
104
|
+
'/ql/data/log/../测试',
|
|
105
|
+
'/ql/data/log-other/测试',
|
|
106
|
+
]) {
|
|
107
|
+
const { error } = commonCronSchema.log_name.validate(value);
|
|
108
|
+
assert.equal(error.details[0].type, 'string.unsafePath', value);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const assert = require('node:assert/strict');
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
|
|
4
|
+
const configPath = require.resolve('../../back/config');
|
|
5
|
+
require.cache[configPath] = {
|
|
6
|
+
id: configPath,
|
|
7
|
+
filename: configPath,
|
|
8
|
+
loaded: true,
|
|
9
|
+
exports: { __esModule: true, default: { logPath: '/ql/data/log' } },
|
|
10
|
+
children: [],
|
|
11
|
+
paths: [],
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const { commonCronSchema } = require('../../back/validation/schedule');
|
|
15
|
+
const { Joi } = require('celebrate');
|
|
16
|
+
|
|
17
|
+
const schema = Joi.object(commonCronSchema);
|
|
18
|
+
|
|
19
|
+
test('cron validation accepts leading-zero schedules and legacy null labels', () => {
|
|
20
|
+
const result = schema.validate({
|
|
21
|
+
name: 'legacy cron',
|
|
22
|
+
command: 'task legacy.js',
|
|
23
|
+
schedule: '01 7 * * *',
|
|
24
|
+
labels: null,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
assert.equal(result.error, undefined);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('cron validation identifies invalid fields', () => {
|
|
31
|
+
const result = schema.validate(
|
|
32
|
+
{
|
|
33
|
+
name: 'invalid cron',
|
|
34
|
+
command: 'task invalid.js',
|
|
35
|
+
schedule: '01 7 * * *',
|
|
36
|
+
allow_multiple_instances: '',
|
|
37
|
+
},
|
|
38
|
+
{ abortEarly: false },
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
assert.deepEqual(
|
|
42
|
+
[...new Set(result.error.details.map((detail) => detail.path.join('.')))],
|
|
43
|
+
['allow_multiple_instances'],
|
|
44
|
+
);
|
|
45
|
+
});
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
require('ts-node/register/transpile-only');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const { test } = require('node:test');
|
|
4
|
+
const { Sequelize, DataTypes } = require('sequelize');
|
|
5
|
+
const dayjs = require('dayjs');
|
|
6
|
+
const express = require('express');
|
|
7
|
+
|
|
8
|
+
test('today result lists include mixed and deleted tasks and exclude other dates', async (t) => {
|
|
9
|
+
const db = new Sequelize({
|
|
10
|
+
dialect: 'sqlite',
|
|
11
|
+
storage: ':memory:',
|
|
12
|
+
logging: false,
|
|
13
|
+
});
|
|
14
|
+
t.after(() => db.close());
|
|
15
|
+
const crons = db.define('Cron', {
|
|
16
|
+
name: DataTypes.STRING,
|
|
17
|
+
command: DataTypes.STRING,
|
|
18
|
+
});
|
|
19
|
+
const stats = db.define('Stat', {
|
|
20
|
+
ref_id: DataTypes.INTEGER,
|
|
21
|
+
date: DataTypes.STRING,
|
|
22
|
+
fail_count: DataTypes.INTEGER,
|
|
23
|
+
success_count: DataTypes.INTEGER,
|
|
24
|
+
});
|
|
25
|
+
const replacements = {
|
|
26
|
+
'../../back/data/cron': { CrontabModel: crons },
|
|
27
|
+
'../../back/data/cronStats': { CrontabStatModel: stats },
|
|
28
|
+
'../../back/data/runningInstance': {},
|
|
29
|
+
'../../back/shared/i18n': { tf: (format, id) => format.replace('%s', id) },
|
|
30
|
+
};
|
|
31
|
+
for (const [modulePath, exports] of Object.entries(replacements)) {
|
|
32
|
+
const resolved = require.resolve(modulePath);
|
|
33
|
+
const original = require.cache[resolved];
|
|
34
|
+
require.cache[resolved] = {
|
|
35
|
+
id: resolved,
|
|
36
|
+
filename: resolved,
|
|
37
|
+
loaded: true,
|
|
38
|
+
exports,
|
|
39
|
+
};
|
|
40
|
+
t.after(() => {
|
|
41
|
+
if (original) require.cache[resolved] = original;
|
|
42
|
+
else delete require.cache[resolved];
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
await db.sync();
|
|
46
|
+
await crons.bulkCreate([
|
|
47
|
+
{ id: 1, name: 'Recovered task', command: 'task recovered.js' },
|
|
48
|
+
{ id: 2, name: '', command: 'task unnamed.js' },
|
|
49
|
+
{ id: 3, name: 'Successful task', command: 'task success.js' },
|
|
50
|
+
]);
|
|
51
|
+
const today = dayjs().format('YYYY-MM-DD');
|
|
52
|
+
await stats.bulkCreate([
|
|
53
|
+
{ ref_id: 1, date: today, fail_count: 2, success_count: 1 },
|
|
54
|
+
{ ref_id: 2, date: today, fail_count: 1, success_count: 0 },
|
|
55
|
+
{ ref_id: 3, date: today, fail_count: 0, success_count: 4 },
|
|
56
|
+
{ ref_id: 4, date: today, fail_count: 3, success_count: 2 },
|
|
57
|
+
{
|
|
58
|
+
ref_id: 3,
|
|
59
|
+
date: dayjs().subtract(1, 'day').format('YYYY-MM-DD'),
|
|
60
|
+
fail_count: 10,
|
|
61
|
+
success_count: 20,
|
|
62
|
+
},
|
|
63
|
+
]);
|
|
64
|
+
const router = express.Router();
|
|
65
|
+
require('../../back/api/dashboard').default(router);
|
|
66
|
+
const dashboard = router.stack.find(
|
|
67
|
+
(layer) => layer.name === 'router',
|
|
68
|
+
).handle;
|
|
69
|
+
const handler = dashboard.stack.find(
|
|
70
|
+
(layer) => layer.route?.path === '/failures',
|
|
71
|
+
).route.stack[0].handle;
|
|
72
|
+
const successHandler = dashboard.stack.find(
|
|
73
|
+
(layer) => layer.route?.path === '/successes',
|
|
74
|
+
).route.stack[0].handle;
|
|
75
|
+
let response;
|
|
76
|
+
await handler(
|
|
77
|
+
{},
|
|
78
|
+
{
|
|
79
|
+
send: (value) => {
|
|
80
|
+
response = value;
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
(error) => {
|
|
84
|
+
throw error;
|
|
85
|
+
},
|
|
86
|
+
);
|
|
87
|
+
assert.deepEqual(response, {
|
|
88
|
+
code: 200,
|
|
89
|
+
data: [
|
|
90
|
+
{ id: 4, name: '任务#4', command: '', failCount: 3, deleted: true },
|
|
91
|
+
{
|
|
92
|
+
id: 1,
|
|
93
|
+
name: 'Recovered task',
|
|
94
|
+
command: 'task recovered.js',
|
|
95
|
+
failCount: 2,
|
|
96
|
+
deleted: false,
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
id: 2,
|
|
100
|
+
name: 'task unnamed.js',
|
|
101
|
+
command: 'task unnamed.js',
|
|
102
|
+
failCount: 1,
|
|
103
|
+
deleted: false,
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
});
|
|
107
|
+
await successHandler(
|
|
108
|
+
{},
|
|
109
|
+
{
|
|
110
|
+
send: (value) => {
|
|
111
|
+
response = value;
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
(error) => {
|
|
115
|
+
throw error;
|
|
116
|
+
},
|
|
117
|
+
);
|
|
118
|
+
assert.deepEqual(response, {
|
|
119
|
+
code: 200,
|
|
120
|
+
data: [
|
|
121
|
+
{
|
|
122
|
+
id: 3,
|
|
123
|
+
name: 'Successful task',
|
|
124
|
+
command: 'task success.js',
|
|
125
|
+
successCount: 4,
|
|
126
|
+
deleted: false,
|
|
127
|
+
},
|
|
128
|
+
{ id: 4, name: '任务#4', command: '', successCount: 2, deleted: true },
|
|
129
|
+
{
|
|
130
|
+
id: 1,
|
|
131
|
+
name: 'Recovered task',
|
|
132
|
+
command: 'task recovered.js',
|
|
133
|
+
successCount: 1,
|
|
134
|
+
deleted: false,
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
});
|
|
138
|
+
await stats.destroy({ where: {} });
|
|
139
|
+
await successHandler(
|
|
140
|
+
{},
|
|
141
|
+
{
|
|
142
|
+
send: (value) => {
|
|
143
|
+
response = value;
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
(error) => {
|
|
147
|
+
throw error;
|
|
148
|
+
},
|
|
149
|
+
);
|
|
150
|
+
assert.deepEqual(response, { code: 200, data: [] });
|
|
151
|
+
await handler(
|
|
152
|
+
{},
|
|
153
|
+
{
|
|
154
|
+
send: (value) => {
|
|
155
|
+
response = value;
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
(error) => {
|
|
159
|
+
throw error;
|
|
160
|
+
},
|
|
161
|
+
);
|
|
162
|
+
assert.deepEqual(response, { code: 200, data: [] });
|
|
163
|
+
await stats.drop();
|
|
164
|
+
let forwarded;
|
|
165
|
+
await handler(
|
|
166
|
+
{},
|
|
167
|
+
{ send: () => assert.fail('must forward database errors') },
|
|
168
|
+
(error) => {
|
|
169
|
+
forwarded = error;
|
|
170
|
+
},
|
|
171
|
+
);
|
|
172
|
+
assert.ok(forwarded instanceof Error);
|
|
173
|
+
});
|