@whyour/qinglong 2.21.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/.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 +9 -1
- package/back/protos/cron.proto +8 -1
- package/deploy/kubernetes/README.md +81 -0
- package/deploy/kubernetes/base/kustomization.yaml +5 -0
- package/deploy/kubernetes/base/qinglong.yaml +95 -0
- package/deploy/kubernetes/overlays/example/kustomization.yaml +10 -0
- 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/development/node-cron-migration.md +49 -0
- package/docs/development/task-startup.md +78 -0
- package/docs/releases/2.22.0-validation.md +49 -0
- package/docs/releases/2.22.0.md +62 -0
- package/docs/releases/2.23.0.md +33 -0
- package/docs/script-history.md +53 -0
- package/ecosystem.config.js +10 -1
- package/package.json +19 -13
- package/sample/config.sample.sh +17 -2
- package/sample/notify.js +118 -0
- package/sample/notify.py +93 -0
- package/scripts/benchmark-execution.cjs +96 -0
- 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/scripts/write-build-info.cjs +27 -0
- package/shell/api.sh +96 -83
- 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 +136 -0
- package/shell/otask.sh +17 -10
- package/shell/preload/sitecustomize.js +11 -3
- package/shell/preload/sitecustomize.py +4 -2
- package/shell/share.sh +27 -10
- package/shell/start.sh +6 -3
- package/shell/task-timeout.sh +63 -0
- package/shell/task.sh +21 -9
- package/shell/update.sh +104 -98
- package/shell/upgrade.cjs +8 -0
- package/static/build/api/clientIp.js +42 -0
- package/static/build/api/config.js +9 -21
- package/static/build/api/cron.js +39 -3
- package/static/build/api/dashboard.js +50 -6
- package/static/build/api/env.js +17 -16
- package/static/build/api/health.js +2 -2
- package/static/build/api/index.js +4 -0
- package/static/build/api/log.js +39 -19
- package/static/build/api/open.js +2 -1
- package/static/build/api/retention.js +63 -0
- package/static/build/api/script.js +172 -25
- package/static/build/api/subscription.js +19 -8
- package/static/build/api/system.js +66 -12
- package/static/build/api/user.js +75 -15
- package/static/build/app.js +63 -54
- package/static/build/bootstrap/database.js +51 -0
- package/static/build/config/const.js +2 -0
- package/static/build/config/grpcCerts.js +93 -44
- package/static/build/config/index.js +0 -4
- package/static/build/config/share.js +5 -4
- package/static/build/config/subscription.js +19 -11
- package/static/build/config/util.js +142 -45
- package/static/build/data/cron.js +1 -0
- package/static/build/data/notify.js +18 -1
- package/static/build/data/sock.js +1 -0
- package/static/build/loaders/app.js +8 -6
- package/static/build/loaders/db.js +5 -35
- package/static/build/loaders/deps.js +30 -22
- package/static/build/loaders/express.js +46 -32
- package/static/build/loaders/initData.js +26 -33
- package/static/build/loaders/initFile.js +1 -1
- package/static/build/loaders/initTask.js +14 -3
- package/static/build/loaders/server.js +1 -1
- 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/middlewares/uniqueConstraintError.js +15 -0
- package/static/build/protos/api.js +78 -2
- package/static/build/protos/cron.js +83 -5
- package/static/build/protos/health.js +1 -1
- package/static/build/schedule/addCron.js +67 -19
- package/static/build/schedule/api.js +5 -2
- package/static/build/schedule/client.js +56 -6
- package/static/build/schedule/delCron.js +11 -1
- package/static/build/schedule/health.js +72 -7
- package/static/build/schedule/setConcurrency.js +27 -0
- package/static/build/services/config.js +5 -43
- package/static/build/services/cron.js +389 -174
- package/static/build/services/dependence.js +66 -18
- package/static/build/services/env.js +1 -1
- package/static/build/services/grpc.js +4 -3
- package/static/build/services/health.js +4 -7
- package/static/build/services/http.js +9 -3
- package/static/build/services/log.js +2 -3
- package/static/build/services/metrics.js +46 -14
- package/static/build/services/notify.js +73 -5
- package/static/build/services/open.js +106 -31
- package/static/build/services/retention.js +123 -0
- package/static/build/services/schedule.js +77 -43
- package/static/build/services/script.js +4 -5
- package/static/build/services/scriptHistory.js +30 -0
- package/static/build/services/sshKey.js +39 -14
- package/static/build/services/subscription.js +161 -87
- package/static/build/services/system.js +116 -43
- package/static/build/services/user.js +255 -37
- package/static/build/shared/auth.js +22 -3
- 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/cronCommand.js +17 -0
- package/static/build/shared/cronSchedule.js +101 -0
- package/static/build/shared/cronScheduler.js +73 -0
- package/static/build/shared/errors.js +9 -0
- package/static/build/shared/fileAccess.js +60 -0
- package/static/build/shared/i18n.js +63 -4
- package/static/build/shared/logPath.js +15 -0
- package/static/build/shared/logReader.js +85 -0
- package/static/build/shared/logStreamManager.js +80 -60
- package/static/build/shared/loginThrottle.js +45 -0
- package/static/build/shared/pLimit.js +22 -8
- package/static/build/shared/password.js +30 -0
- package/static/build/shared/retention.js +58 -0
- package/static/build/shared/runCron.js +39 -17
- 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/scriptHistory.js +445 -0
- package/static/build/shared/shellQuote.js +11 -0
- package/static/build/shared/startupProcess.js +48 -0
- package/static/build/shared/store.js +7 -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/trustProxy.js +119 -0
- package/static/build/shared/utils.js +2 -1
- package/static/build/token.js +3 -14
- package/static/build/validation/schedule.js +6 -12
- 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/292.264757f0.async.js +1 -0
- package/static/dist/3512.95e41255.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/{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.01fcd534.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.0b8cce8c.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.0fa8b421.async.js +1 -0
- package/static/dist/src__pages__diff__index.b94e5dc5.async.js +1 -0
- 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.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__renameModal.0ab029e7.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__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.d175b154.async.js +1 -0
- 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.30868ba8.async.js +1 -0
- package/static/dist/{umi.ca04a019.js → umi.3a24a9fa.js} +1 -1
- package/test/back/advisory-input-security.test.cjs +416 -0
- package/test/back/auth-security.test.cjs +74 -0
- package/test/back/build-provenance.test.cjs +150 -0
- package/test/back/code-scanning-security.test.cjs +189 -0
- package/test/back/cron-log-name.test.cjs +110 -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/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/draft-path-security.test.cjs +235 -0
- package/test/back/ecosystem.test.cjs +28 -0
- package/test/back/env-import-security.test.cjs +91 -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-scope.test.cjs +180 -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/grpc-mtls-security.test.cjs +136 -0
- package/test/back/http-exclusive-listen.test.cjs +31 -0
- package/test/back/http-security.test.cjs +313 -0
- 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 +68 -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/mirror-status.test.cjs +257 -0
- package/test/back/monitoring.test.cjs +73 -0
- package/test/back/node-cron-migration.test.cjs +65 -0
- package/test/back/node-path-cache.test.cjs +202 -0
- package/test/back/node-path-lock.test.cjs +182 -0
- package/test/back/npm-publication.test.cjs +70 -0
- package/test/back/preload-lazy-notify.test.cjs +168 -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/queued-cron-invalidation.test.cjs +98 -0
- package/test/back/restart-instance-recovery.test.cjs +116 -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-bulk-recovery.test.cjs +40 -0
- package/test/back/scheduler-concurrency.test.cjs +411 -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 +206 -0
- package/test/back/scheduler-rpc-timeout.test.cjs +49 -0
- package/test/back/schema-migrations.test.cjs +127 -0
- 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 +184 -0
- 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/sock-polling.test.cjs +297 -0
- package/test/back/sock-security.test.cjs +72 -0
- package/test/back/ssh-config-home.test.cjs +113 -0
- package/test/back/start-env-preservation.test.cjs +53 -0
- package/test/back/static-mirror-trigger.test.cjs +441 -0
- package/test/back/static-mirror.test.cjs +179 -0
- package/test/back/stop-failure-feedback.test.cjs +158 -0
- package/test/back/stop-race.test.cjs +171 -0
- package/test/back/subscription-cleanup.test.cjs +53 -0
- package/test/back/subscription-mutation-lock.test.cjs +83 -0
- package/test/back/subscription-review-regression.test.cjs +607 -0
- package/test/back/subscription-stop-state.test.cjs +66 -0
- package/test/back/subscription-storage-regression.test.cjs +553 -0
- package/test/back/system-dependence-cache.test.cjs +127 -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/task-time.test.cjs +116 -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-api.test.cjs +99 -0
- package/test/back/user-security.test.cjs +349 -0
- package/test/back/worker-apm.test.cjs +84 -0
- package/test/back/wpush-grpc.test.cjs +116 -0
- package/test/fixtures/legacy-cron.json +1371 -0
- package/test/front/cron-log-pagination.test.cjs +214 -0
- package/test/front/diff-file-routing.test.cjs +126 -0
- package/test/front/http-auth.test.cjs +152 -0
- package/test/front/http-error.test.cjs +29 -0
- package/test/front/script-history-save.test.cjs +121 -0
- package/test/helpers/load-security-module.cjs +42 -0
- package/test/helpers/upgrade-fixture.cjs +30 -0
- package/version.yaml +14 -34
- package/CLAUDE.md +0 -43
- package/static/dist/1147.c420132e.async.js +0 -1
- package/static/dist/134.54df9e38.async.js +0 -1
- package/static/dist/2096.6d98fd12.async.js +0 -1
- package/static/dist/2208.f7ba3dfa.async.js +0 -1
- package/static/dist/2286.164bb089.async.js +0 -1
- package/static/dist/3191.63263871.async.js +0 -1
- package/static/dist/4859.6592cebb.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/6707.801b886b.async.js +0 -1
- package/static/dist/8826.2447a104.async.js +0 -1
- package/static/dist/layouts__index.a7a2bfe0.async.js +0 -1
- package/static/dist/preload_helper.0431c0f3.js +0 -1
- package/static/dist/src__pages__crontab__detail.b9c36808.async.js +0 -1
- package/static/dist/src__pages__crontab__index.fed99fd0.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.b30f2f47.async.js +0 -1
- package/static/dist/src__pages__dependence__index.3d87ceac.async.js +0 -1
- package/static/dist/src__pages__dependence__logModal.0681830b.async.js +0 -1
- package/static/dist/src__pages__dependence__modal.11124896.async.js +0 -1
- package/static/dist/src__pages__diff__index.013b7c75.async.js +0 -1
- package/static/dist/src__pages__env__editNameModal.5d264b25.async.js +0 -1
- package/static/dist/src__pages__env__index.baa27d4e.async.js +0 -1
- package/static/dist/src__pages__env__modal.7f2ef1bc.async.js +0 -1
- package/static/dist/src__pages__error__index.f156b45e.async.js +0 -1
- package/static/dist/src__pages__initialization__index.e96d4ba8.async.js +0 -1
- package/static/dist/src__pages__log__index.e0978bae.async.js +0 -1
- package/static/dist/src__pages__script__editModal.cbf4ec0e.async.js +0 -1
- package/static/dist/src__pages__script__editNameModal.3e7e100d.async.js +0 -1
- package/static/dist/src__pages__script__index.2765d1b8.async.js +0 -1
- package/static/dist/src__pages__script__index.60b6f827.chunk.css +0 -1
- package/static/dist/src__pages__script__renameModal.5e987ef5.async.js +0 -1
- package/static/dist/src__pages__script__saveModal.3f9d23d6.async.js +0 -1
- package/static/dist/src__pages__script__setting.a535793a.async.js +0 -1
- package/static/dist/src__pages__setting__appModal.251cd14f.async.js +0 -1
- package/static/dist/src__pages__setting__checkUpdate.46efe057.async.js +0 -1
- package/static/dist/src__pages__setting__dependence.8a7a9529.async.js +0 -1
- package/static/dist/src__pages__setting__index.cc85fdfb.async.js +0 -1
- package/static/dist/src__pages__setting__loginLog.cea6056c.async.js +0 -1
- package/static/dist/src__pages__setting__notification.390fc905.async.js +0 -1
- package/static/dist/src__pages__setting__other.b22d2165.async.js +0 -1
- package/static/dist/src__pages__setting__security.598720a8.async.js +0 -1
- package/static/dist/src__pages__setting__systemLog.67406721.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.3562c670.async.js +0 -1
- /package/static/dist/{4859.1b962b29.chunk.css → 292.1b962b29.chunk.css} +0 -0
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
const assert = require('node:assert/strict');
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const { EventEmitter } = require('node:events');
|
|
6
|
+
const ts = require('typescript');
|
|
7
|
+
const jwt = require('jsonwebtoken');
|
|
8
|
+
const { isValidToken } = require('../../back/shared/auth');
|
|
9
|
+
|
|
10
|
+
async function setup() {
|
|
11
|
+
const secret = 'polling-test';
|
|
12
|
+
const token = jwt.sign({}, secret, { algorithm: 'HS384', expiresIn: '1h' });
|
|
13
|
+
let auth = { token };
|
|
14
|
+
let read = async () => auth;
|
|
15
|
+
let reads = 0;
|
|
16
|
+
const validations = [];
|
|
17
|
+
let onConnection;
|
|
18
|
+
const clients = new Set();
|
|
19
|
+
const timers = new Set();
|
|
20
|
+
const mocks = {
|
|
21
|
+
sockjs: {
|
|
22
|
+
createServer: () => ({
|
|
23
|
+
on: (_, fn) => {
|
|
24
|
+
onConnection = fn;
|
|
25
|
+
},
|
|
26
|
+
installHandlers() {},
|
|
27
|
+
}),
|
|
28
|
+
},
|
|
29
|
+
typedi: {
|
|
30
|
+
Container: {
|
|
31
|
+
get: () => ({
|
|
32
|
+
addClient: (c) => clients.add(c),
|
|
33
|
+
removeClient: (c) => clients.delete(c),
|
|
34
|
+
}),
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
'../services/sock': class {},
|
|
38
|
+
'../config/util': { getPlatform: (agent) => agent || 'desktop' },
|
|
39
|
+
'../shared/store': {
|
|
40
|
+
shareStore: {
|
|
41
|
+
getAuthInfo: () => {
|
|
42
|
+
reads++;
|
|
43
|
+
return read();
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
'../shared/auth': {
|
|
48
|
+
isValidToken: (...args) => {
|
|
49
|
+
validations.push({ token: args[1], platform: args[2] });
|
|
50
|
+
return isValidToken(...args);
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
'../config': { baseUrl: '', jwt: { secret } },
|
|
54
|
+
};
|
|
55
|
+
const source = fs.readFileSync(
|
|
56
|
+
path.join(__dirname, '../../back/loaders/sock.ts'),
|
|
57
|
+
'utf8',
|
|
58
|
+
);
|
|
59
|
+
const { outputText } = ts.transpileModule(source, {
|
|
60
|
+
compilerOptions: {
|
|
61
|
+
module: ts.ModuleKind.CommonJS,
|
|
62
|
+
target: ts.ScriptTarget.ES2020,
|
|
63
|
+
esModuleInterop: true,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
const module = { exports: {} };
|
|
67
|
+
new Function(
|
|
68
|
+
'require',
|
|
69
|
+
'module',
|
|
70
|
+
'exports',
|
|
71
|
+
'setInterval',
|
|
72
|
+
'clearInterval',
|
|
73
|
+
outputText,
|
|
74
|
+
)(
|
|
75
|
+
(name) => {
|
|
76
|
+
assert.ok(Object.hasOwn(mocks, name), name);
|
|
77
|
+
return mocks[name];
|
|
78
|
+
},
|
|
79
|
+
module,
|
|
80
|
+
module.exports,
|
|
81
|
+
(callback, delay) => {
|
|
82
|
+
assert.equal(delay, 1000);
|
|
83
|
+
const timer = { callback, unref() {} };
|
|
84
|
+
timers.add(timer);
|
|
85
|
+
return timer;
|
|
86
|
+
},
|
|
87
|
+
(timer) => timers.delete(timer),
|
|
88
|
+
);
|
|
89
|
+
await module.exports.default({ server: {} });
|
|
90
|
+
function connection(value = token) {
|
|
91
|
+
const conn = new EventEmitter();
|
|
92
|
+
Object.assign(conn, {
|
|
93
|
+
headers: {},
|
|
94
|
+
pathname: '/api/ws/a/b/websocket',
|
|
95
|
+
url: `/api/ws/a/b/websocket?token=${value}`,
|
|
96
|
+
write() {},
|
|
97
|
+
close(code) {
|
|
98
|
+
this.closeCode = code;
|
|
99
|
+
this.emit('close');
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
return conn;
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
token,
|
|
106
|
+
secret,
|
|
107
|
+
clients,
|
|
108
|
+
timers,
|
|
109
|
+
validations,
|
|
110
|
+
connection,
|
|
111
|
+
connect: (c) => onConnection(c),
|
|
112
|
+
get reads() {
|
|
113
|
+
return reads;
|
|
114
|
+
},
|
|
115
|
+
setAuth(value) {
|
|
116
|
+
auth = value;
|
|
117
|
+
},
|
|
118
|
+
setRead(fn) {
|
|
119
|
+
read = fn;
|
|
120
|
+
},
|
|
121
|
+
tick: () => Promise.all([...timers].map((t) => t.callback())),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function deferred() {
|
|
126
|
+
let resolve, reject;
|
|
127
|
+
const promise = new Promise((a, b) => {
|
|
128
|
+
resolve = a;
|
|
129
|
+
reject = b;
|
|
130
|
+
});
|
|
131
|
+
return { promise, resolve, reject };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
test('multiple sockets share one periodic read, revoke together, and stop polling when empty', async () => {
|
|
135
|
+
const h = await setup();
|
|
136
|
+
assert.equal(h.timers.size, 0);
|
|
137
|
+
const sockets = Array.from({ length: 20 }, () => h.connection());
|
|
138
|
+
await Promise.all(sockets.map(h.connect));
|
|
139
|
+
assert.equal(h.reads, 20, 'initial authentication remains per connection');
|
|
140
|
+
assert.equal(h.timers.size, 1);
|
|
141
|
+
await h.tick();
|
|
142
|
+
assert.equal(h.reads, 21);
|
|
143
|
+
assert.equal(h.clients.size, 20);
|
|
144
|
+
h.setAuth({ token: '' });
|
|
145
|
+
await h.tick();
|
|
146
|
+
assert.ok(sockets.every((c) => c.closeCode === '401'));
|
|
147
|
+
assert.equal(h.clients.size, 0);
|
|
148
|
+
assert.equal(h.timers.size, 0);
|
|
149
|
+
const c = h.connection();
|
|
150
|
+
h.setAuth({ token: h.token });
|
|
151
|
+
await h.connect(c);
|
|
152
|
+
assert.equal(h.timers.size, 1);
|
|
153
|
+
c.close();
|
|
154
|
+
assert.equal(h.timers.size, 0);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
test('slow reads do not overlap and old snapshots do not reject newly accepted sockets', async () => {
|
|
158
|
+
const h = await setup();
|
|
159
|
+
const old = h.connection();
|
|
160
|
+
await h.connect(old);
|
|
161
|
+
const pending = deferred();
|
|
162
|
+
h.setRead(() => pending.promise);
|
|
163
|
+
const tick = h.tick();
|
|
164
|
+
await h.tick();
|
|
165
|
+
assert.equal(h.reads, 2);
|
|
166
|
+
old.close();
|
|
167
|
+
h.setRead(async () => ({ token: h.token }));
|
|
168
|
+
const fresh = h.connection();
|
|
169
|
+
await h.connect(fresh);
|
|
170
|
+
pending.resolve({ token: '' });
|
|
171
|
+
await tick;
|
|
172
|
+
assert.equal(h.clients.has(fresh), true);
|
|
173
|
+
assert.equal(fresh.closeCode, undefined);
|
|
174
|
+
await h.tick();
|
|
175
|
+
assert.equal(h.reads, 4);
|
|
176
|
+
fresh.close();
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test('periodic store failures disconnect the checked sessions', async () => {
|
|
180
|
+
const h = await setup();
|
|
181
|
+
const c = h.connection();
|
|
182
|
+
await h.connect(c);
|
|
183
|
+
h.setRead(async () => {
|
|
184
|
+
throw new Error('database unavailable');
|
|
185
|
+
});
|
|
186
|
+
await h.tick();
|
|
187
|
+
assert.equal(c.closeCode, '401');
|
|
188
|
+
assert.equal(h.clients.size, 0);
|
|
189
|
+
assert.equal(h.timers.size, 0);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test('closed connections cannot be added after initial authentication finishes', async () => {
|
|
193
|
+
const h = await setup();
|
|
194
|
+
const pending = deferred();
|
|
195
|
+
h.setRead(() => pending.promise);
|
|
196
|
+
const c = h.connection();
|
|
197
|
+
const connecting = h.connect(c);
|
|
198
|
+
c.close();
|
|
199
|
+
pending.resolve({ token: h.token });
|
|
200
|
+
await connecting;
|
|
201
|
+
assert.equal(h.clients.size, 0);
|
|
202
|
+
assert.equal(h.timers.size, 0);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
test('initial store errors reject the connection without creating a timer', async () => {
|
|
206
|
+
const h = await setup();
|
|
207
|
+
h.setRead(async () => {
|
|
208
|
+
throw new Error('database unavailable');
|
|
209
|
+
});
|
|
210
|
+
const c = h.connection();
|
|
211
|
+
await h.connect(c);
|
|
212
|
+
assert.equal(c.closeCode, '401');
|
|
213
|
+
assert.equal(h.clients.size, 0);
|
|
214
|
+
assert.equal(h.timers.size, 0);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test('each periodic check still validates JWT expiry and platform session membership', async () => {
|
|
218
|
+
const h = await setup();
|
|
219
|
+
const expired = h.connection(
|
|
220
|
+
jwt.sign({}, h.secret, { algorithm: 'HS384', expiresIn: -1 }),
|
|
221
|
+
);
|
|
222
|
+
await h.connect(expired);
|
|
223
|
+
assert.equal(expired.closeCode, '404');
|
|
224
|
+
const c = h.connection();
|
|
225
|
+
await h.connect(c);
|
|
226
|
+
h.setAuth({ tokens: { desktop: [{ value: h.token, expiration: 1 }] } });
|
|
227
|
+
await h.tick();
|
|
228
|
+
assert.equal(c.closeCode, '401');
|
|
229
|
+
assert.equal(h.timers.size, 0);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
test('an accepted JWT is disconnected when it expires without a store change', async () => {
|
|
233
|
+
const h = await setup();
|
|
234
|
+
const c = h.connection();
|
|
235
|
+
await h.connect(c);
|
|
236
|
+
const now = Date.now;
|
|
237
|
+
try {
|
|
238
|
+
Date.now = () => now() + 2 * 60 * 60 * 1000;
|
|
239
|
+
await h.tick();
|
|
240
|
+
} finally {
|
|
241
|
+
Date.now = now;
|
|
242
|
+
}
|
|
243
|
+
assert.equal(c.closeCode, '401');
|
|
244
|
+
assert.equal(h.timers.size, 0);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
test('same token and platform share validation only within the current round', async () => {
|
|
248
|
+
const h = await setup();
|
|
249
|
+
const sockets = Array.from({ length: 20 }, () => h.connection());
|
|
250
|
+
await Promise.all(sockets.map(h.connect));
|
|
251
|
+
assert.equal(
|
|
252
|
+
h.validations.length,
|
|
253
|
+
20,
|
|
254
|
+
'initial authentication stays independent',
|
|
255
|
+
);
|
|
256
|
+
h.validations.length = 0;
|
|
257
|
+
await h.tick();
|
|
258
|
+
assert.equal(h.validations.length, 1);
|
|
259
|
+
await h.tick();
|
|
260
|
+
assert.equal(h.validations.length, 2, 'new rounds revalidate');
|
|
261
|
+
h.setAuth({ token: '' });
|
|
262
|
+
await h.tick();
|
|
263
|
+
assert.equal(
|
|
264
|
+
h.validations.length,
|
|
265
|
+
3,
|
|
266
|
+
'invalid results are also shared for this round',
|
|
267
|
+
);
|
|
268
|
+
assert.ok(sockets.every((c) => c.closeCode === '401'));
|
|
269
|
+
assert.equal(h.timers.size, 0);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
test('validation results never cross tokens or platforms', async () => {
|
|
273
|
+
const h = await setup();
|
|
274
|
+
const other = jwt.sign({ account: 'other' }, h.secret, {
|
|
275
|
+
algorithm: 'HS384',
|
|
276
|
+
expiresIn: '1h',
|
|
277
|
+
});
|
|
278
|
+
h.setAuth({
|
|
279
|
+
tokens: {
|
|
280
|
+
desktop: [{ value: h.token }, { value: other }],
|
|
281
|
+
mobile: [{ value: h.token }],
|
|
282
|
+
},
|
|
283
|
+
});
|
|
284
|
+
const desktop = h.connection();
|
|
285
|
+
const mobile = h.connection();
|
|
286
|
+
mobile.headers['user-agent'] = 'mobile';
|
|
287
|
+
const separate = h.connection(other);
|
|
288
|
+
await Promise.all([desktop, mobile, separate].map(h.connect));
|
|
289
|
+
h.validations.length = 0;
|
|
290
|
+
h.setAuth({ tokens: { desktop: [{ value: h.token }], mobile: [] } });
|
|
291
|
+
await h.tick();
|
|
292
|
+
assert.equal(h.validations.length, 3);
|
|
293
|
+
assert.equal(desktop.closeCode, undefined);
|
|
294
|
+
assert.equal(mobile.closeCode, '401');
|
|
295
|
+
assert.equal(separate.closeCode, '401');
|
|
296
|
+
desktop.close();
|
|
297
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const assert = require('node:assert/strict');
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
const { EventEmitter } = require('node:events');
|
|
5
|
+
const jwt = require('jsonwebtoken');
|
|
6
|
+
const load = require('../helpers/load-security-module.cjs');
|
|
7
|
+
|
|
8
|
+
test('WebSocket connections reject expired tokens and close when sessions are revoked', async () => {
|
|
9
|
+
const secret = 'sock-test';
|
|
10
|
+
const valid = jwt.sign({}, secret, { algorithm: 'HS384', expiresIn: '1h' });
|
|
11
|
+
const expired = jwt.sign({}, secret, { algorithm: 'HS384', expiresIn: -1 });
|
|
12
|
+
let auth = { token: valid, tokens: { desktop: [{ value: expired }] } };
|
|
13
|
+
let onConnection;
|
|
14
|
+
const clients = new Set();
|
|
15
|
+
const Sock = class {};
|
|
16
|
+
const loader = load(path.join(__dirname, '../../back/loaders/sock.ts'), {
|
|
17
|
+
sockjs: {
|
|
18
|
+
createServer: () => ({
|
|
19
|
+
on: (_event, fn) => {
|
|
20
|
+
onConnection = fn;
|
|
21
|
+
},
|
|
22
|
+
installHandlers() {},
|
|
23
|
+
}),
|
|
24
|
+
},
|
|
25
|
+
typedi: {
|
|
26
|
+
Container: {
|
|
27
|
+
get: () => ({
|
|
28
|
+
addClient: (c) => clients.add(c),
|
|
29
|
+
removeClient: (c) => clients.delete(c),
|
|
30
|
+
}),
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
'../services/sock': Sock,
|
|
34
|
+
'../config': { jwt: { secret }, baseUrl: '' },
|
|
35
|
+
'../config/util': { getPlatform: () => 'desktop' },
|
|
36
|
+
'../shared/store': { shareStore: { getAuthInfo: async () => auth } },
|
|
37
|
+
}).default;
|
|
38
|
+
await loader({ server: {} });
|
|
39
|
+
const connection = (token) => {
|
|
40
|
+
const c = new EventEmitter();
|
|
41
|
+
Object.assign(c, {
|
|
42
|
+
headers: {},
|
|
43
|
+
pathname: '/api/ws/a/b/websocket',
|
|
44
|
+
url: `/api/ws/a/b/websocket?token=${token}`,
|
|
45
|
+
close() {
|
|
46
|
+
this.closed = true;
|
|
47
|
+
this.emit('close');
|
|
48
|
+
},
|
|
49
|
+
write() {},
|
|
50
|
+
});
|
|
51
|
+
return c;
|
|
52
|
+
};
|
|
53
|
+
const rejected = connection(expired);
|
|
54
|
+
await onConnection(rejected);
|
|
55
|
+
assert.equal(rejected.closed, true);
|
|
56
|
+
assert.equal(clients.size, 0);
|
|
57
|
+
const accepted = connection(valid);
|
|
58
|
+
await onConnection(accepted);
|
|
59
|
+
assert.equal(clients.size, 1);
|
|
60
|
+
auth = { token: '', tokens: {} };
|
|
61
|
+
await new Promise((resolve, reject) => {
|
|
62
|
+
const timeout = setTimeout(() => {
|
|
63
|
+
accepted.close();
|
|
64
|
+
reject(new Error('revoked socket remained open'));
|
|
65
|
+
}, 3000);
|
|
66
|
+
accepted.once('close', () => {
|
|
67
|
+
clearTimeout(timeout);
|
|
68
|
+
resolve();
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
assert.equal(clients.size, 0);
|
|
72
|
+
});
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
const assert = require('node:assert/strict');
|
|
2
|
+
const fs = require('node:fs/promises');
|
|
3
|
+
const os = require('node:os');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const test = require('node:test');
|
|
6
|
+
const load = require('../helpers/load-security-module.cjs');
|
|
7
|
+
|
|
8
|
+
async function fixture(t, sameHome = false, missingUser = false) {
|
|
9
|
+
const directory = await fs.mkdtemp(path.join(os.tmpdir(), 'ql-ssh-home-'));
|
|
10
|
+
t.after(() => fs.rm(directory, { recursive: true, force: true }));
|
|
11
|
+
const userHome = path.join(directory, 'user');
|
|
12
|
+
const envHome = sameHome ? userHome : path.join(directory, 'env');
|
|
13
|
+
const sshdPath = path.join(directory, 'ssh.d');
|
|
14
|
+
await fs.mkdir(sshdPath);
|
|
15
|
+
const util = {
|
|
16
|
+
fileExist: async (file) =>
|
|
17
|
+
fs.stat(file).then(
|
|
18
|
+
() => true,
|
|
19
|
+
() => false,
|
|
20
|
+
),
|
|
21
|
+
rmPath: async (file) => fs.rm(file, { force: true }),
|
|
22
|
+
};
|
|
23
|
+
const { writeFileWithLock } = load('back/shared/utils.ts', {
|
|
24
|
+
'../config/util': util,
|
|
25
|
+
});
|
|
26
|
+
let initialized;
|
|
27
|
+
const ready = new Promise((resolve) => (initialized = resolve));
|
|
28
|
+
const SshKeyService = load('back/services/sshKey.ts', {
|
|
29
|
+
os: {
|
|
30
|
+
...os,
|
|
31
|
+
homedir: () => envHome,
|
|
32
|
+
userInfo: () => {
|
|
33
|
+
if (missingUser) throw Error('No passwd entry');
|
|
34
|
+
return { homedir: userHome };
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
'../config': { sshdPath },
|
|
38
|
+
'../config/util': util,
|
|
39
|
+
'../shared/utils': {
|
|
40
|
+
writeFileWithLock: async (file, content, options) => {
|
|
41
|
+
await writeFileWithLock(file, content, options);
|
|
42
|
+
if (content.includes('Include ')) {
|
|
43
|
+
initialized();
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
}).default;
|
|
48
|
+
const service = new SshKeyService({ error: assert.fail, warn: assert.fail });
|
|
49
|
+
await ready;
|
|
50
|
+
return { service, userHome, envHome, sshdPath };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
for (const sameHome of [false, true]) {
|
|
54
|
+
test(`SSH configuration uses the effective user home with ${
|
|
55
|
+
sameHome ? 'matching' : 'overridden'
|
|
56
|
+
} HOME`, async (t) => {
|
|
57
|
+
const { service, userHome, envHome, sshdPath } = await fixture(t, sameHome);
|
|
58
|
+
const configFile = path.join(userHome, '.ssh/config');
|
|
59
|
+
assert.equal(
|
|
60
|
+
await fs.readFile(configFile, 'utf8'),
|
|
61
|
+
`Include ${sshdPath}/*.config\n\n`,
|
|
62
|
+
);
|
|
63
|
+
assert.equal((await fs.stat(path.dirname(configFile))).mode & 0o777, 0o700);
|
|
64
|
+
assert.equal((await fs.stat(configFile)).mode & 0o777, 0o600);
|
|
65
|
+
if (!sameHome)
|
|
66
|
+
await assert.rejects(fs.stat(path.join(envHome, '.ssh/config')), {
|
|
67
|
+
code: 'ENOENT',
|
|
68
|
+
});
|
|
69
|
+
await fs.appendFile(
|
|
70
|
+
configFile,
|
|
71
|
+
'Host existing\n Hostname example.com\n',
|
|
72
|
+
);
|
|
73
|
+
await service.initSshConfigFile();
|
|
74
|
+
const content = await fs.readFile(configFile, 'utf8');
|
|
75
|
+
assert.equal(content.split('Include ').length, 2);
|
|
76
|
+
assert.match(content, /Host existing/);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
test('SSH initialization still works for a custom UID without a passwd entry', async (t) => {
|
|
81
|
+
const { envHome, sshdPath } = await fixture(t, true, true);
|
|
82
|
+
assert.equal(
|
|
83
|
+
await fs.readFile(path.join(envHome, '.ssh/config'), 'utf8'),
|
|
84
|
+
`Include ${sshdPath}/*.config\n\n`,
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('SSH alias changes retain private key permissions and remove old credentials', async (t) => {
|
|
89
|
+
const { service, sshdPath } = await fixture(t);
|
|
90
|
+
const {
|
|
91
|
+
getSubscriptionSshAlias,
|
|
92
|
+
} = require('../../back/shared/subscriptionPath');
|
|
93
|
+
const original = 'private/中文@v1';
|
|
94
|
+
const renamed = 'renamed/中文@v2';
|
|
95
|
+
await service.addSSHKey('fixture-private-key', original, '127.0.0.1');
|
|
96
|
+
const first = getSubscriptionSshAlias(original);
|
|
97
|
+
assert.equal((await fs.stat(path.join(sshdPath, first))).mode & 0o777, 0o400);
|
|
98
|
+
assert.match(
|
|
99
|
+
await fs.readFile(path.join(sshdPath, `${first}.config`), 'utf8'),
|
|
100
|
+
/Hostname 127\.0\.0\.1/,
|
|
101
|
+
);
|
|
102
|
+
await service.removeSSHKey(original, '127.0.0.1');
|
|
103
|
+
await service.addSSHKey('fixture-private-key', renamed, '127.0.0.1');
|
|
104
|
+
await assert.rejects(fs.stat(path.join(sshdPath, first)), { code: 'ENOENT' });
|
|
105
|
+
await assert.rejects(fs.stat(path.join(sshdPath, `${first}.config`)), {
|
|
106
|
+
code: 'ENOENT',
|
|
107
|
+
});
|
|
108
|
+
assert.equal(
|
|
109
|
+
(await fs.stat(path.join(sshdPath, getSubscriptionSshAlias(renamed))))
|
|
110
|
+
.mode & 0o777,
|
|
111
|
+
0o400,
|
|
112
|
+
);
|
|
113
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const test = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const os = require('node:os');
|
|
5
|
+
const path = require('node:path');
|
|
6
|
+
const { spawnSync } = require('node:child_process');
|
|
7
|
+
|
|
8
|
+
// Run the actual startup prefix, stopping before service initialization.
|
|
9
|
+
const source = fs
|
|
10
|
+
.readFileSync('shell/start.sh', 'utf8')
|
|
11
|
+
.split('. ${QL_DIR}/shell/share.sh')[0];
|
|
12
|
+
for (const command of ['start', 'reload']) {
|
|
13
|
+
for (const existing of [false, true]) {
|
|
14
|
+
test(`${command} ${
|
|
15
|
+
existing ? 'preserves existing' : 'initializes missing'
|
|
16
|
+
} .env`, (t) => {
|
|
17
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'ql-env-'));
|
|
18
|
+
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
19
|
+
fs.mkdirSync(path.join(root, 'shell'));
|
|
20
|
+
fs.writeFileSync(path.join(root, 'shell/test.sh'), '# fixture');
|
|
21
|
+
fs.writeFileSync(path.join(root, '.env.example'), 'BACK_PORT=5700\n');
|
|
22
|
+
const custom = 'BACK_PORT=5800\nJWT_SECRET=synthetic-test-only\n';
|
|
23
|
+
if (existing)
|
|
24
|
+
fs.writeFileSync(path.join(root, '.env'), custom, { mode: 0o600 });
|
|
25
|
+
const result = spawnSync(
|
|
26
|
+
'/bin/bash',
|
|
27
|
+
[
|
|
28
|
+
'-c',
|
|
29
|
+
'npm(){ :; }; pip3(){ :; }; apk(){ :; }; sudo(){ "$@"; }; python3(){ printf 3.11; };\n' +
|
|
30
|
+
source,
|
|
31
|
+
'startup-test',
|
|
32
|
+
command,
|
|
33
|
+
],
|
|
34
|
+
{
|
|
35
|
+
encoding: 'utf8',
|
|
36
|
+
env: {
|
|
37
|
+
...process.env,
|
|
38
|
+
QL_DIR: root,
|
|
39
|
+
QL_DATA_DIR: root + '/data',
|
|
40
|
+
QL_OS_TYPE: 'alpine',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
);
|
|
44
|
+
assert.equal(result.status, 0, result.stderr);
|
|
45
|
+
assert.equal(
|
|
46
|
+
fs.readFileSync(path.join(root, '.env'), 'utf8'),
|
|
47
|
+
existing ? custom : 'BACK_PORT=5700\n',
|
|
48
|
+
);
|
|
49
|
+
if (existing)
|
|
50
|
+
assert.equal(fs.statSync(path.join(root, '.env')).mode & 0o777, 0o600);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|