mirror of
https://github.com/whyour/qinglong.git
synced 2026-11-16 12:45:44 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3989f86aa |
@@ -550,14 +550,10 @@ jobs:
|
||||
cache-from: type=registry,ref=whyour/qinglong:cache-debian-python3.10
|
||||
cache-to: type=registry,ref=whyour/qinglong:cache-debian-python3.10,mode=max
|
||||
|
||||
# Unmodified amd64 packages for glibc and musl migration acceptance. This does not
|
||||
# One unmodified amd64 package for migration acceptance only. This does not
|
||||
# publish bundles or advance development/formal channel indexes.
|
||||
build-npm-migration-bundle:
|
||||
needs: [build-debian, build-alpine]
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
libc: [glibc, musl]
|
||||
needs: build-debian
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 20
|
||||
steps:
|
||||
@@ -565,7 +561,7 @@ jobs:
|
||||
- uses: docker/setup-buildx-action@v4
|
||||
- name: Export the official platform package from this run's image digest
|
||||
env:
|
||||
IMAGE_DIGEST: ${{ matrix.libc == 'musl' && needs.build-alpine.outputs.image-digest || needs.build-debian.outputs.image-digest }}
|
||||
IMAGE_DIGEST: ${{ needs.build-debian.outputs.image-digest }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
[[ "$IMAGE_DIGEST" =~ ^sha256:[a-f0-9]{64}$ ]]
|
||||
@@ -573,21 +569,20 @@ jobs:
|
||||
docker buildx build --platform linux/amd64 --build-arg "BASE_IMAGE=$image" --file docker/Dockerfile.upgrade-bundle --output "type=local,dest=$RUNNER_TEMP/npm-migration-bundle" .
|
||||
- uses: actions/upload-artifact@v6
|
||||
with:
|
||||
name: npm-migration-bundle-${{ matrix.libc }}-${{ github.sha }}
|
||||
name: npm-migration-bundle-${{ github.sha }}
|
||||
path: ${{ runner.temp }}/npm-migration-bundle/*
|
||||
if-no-files-found: error
|
||||
retention-days: 3
|
||||
|
||||
verify-npm-package:
|
||||
needs: [build-static, build-npm-migration-bundle, build-alpine]
|
||||
needs: [build-static, build-npm-migration-bundle]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
node: ['20.18.1', '22.17.0', '24', 'alpine']
|
||||
container:
|
||||
image: ${{ matrix.node == 'alpine' && format('ghcr.io/{0}@{1}', github.repository, needs.build-alpine.outputs.image-digest) || format('node:{0}-bookworm', matrix.node) }}
|
||||
node: ['20.18.1', '22.17.0', '24']
|
||||
container: node:${{ matrix.node }}-bookworm
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/download-artifact@v6
|
||||
@@ -596,16 +591,12 @@ jobs:
|
||||
path: ${{ runner.temp }}/npm-panel/
|
||||
- uses: actions/download-artifact@v6
|
||||
with:
|
||||
name: npm-migration-bundle-${{ matrix.node == 'alpine' && 'musl' || 'glibc' }}-${{ github.sha }}
|
||||
name: npm-migration-bundle-${{ github.sha }}
|
||||
path: ${{ runner.temp }}/npm-migration-bundle/
|
||||
- name: Install isolated service test tools
|
||||
run: |
|
||||
if [ -f /etc/alpine-release ]; then
|
||||
apk add --no-cache python3 openssl curl jq nginx procps make g++
|
||||
else
|
||||
apt-get update
|
||||
apt-get install -y --no-install-recommends python3 openssl curl jq nginx procps
|
||||
fi
|
||||
apt-get update
|
||||
apt-get install -y --no-install-recommends python3 openssl curl jq nginx procps
|
||||
# The published legacy launcher resets PATH to standard directories.
|
||||
# /usr/local is confined to this disposable job container; PM2_HOME
|
||||
# remains private to each verification run.
|
||||
|
||||
+67
-74
@@ -16,7 +16,6 @@ import { t } from '../shared/i18n';
|
||||
import { AppScope } from '../data/open';
|
||||
import uniqueConstraintError from '../middlewares/uniqueConstraintError';
|
||||
import protectedPathCase from '../middlewares/protectedPathCase';
|
||||
import { withAuthAvailability } from '../middlewares/authAvailability';
|
||||
function resolveTrustProxy(value = process.env.QL_TRUST_PROXY) {
|
||||
const setting = value?.trim();
|
||||
if (!setting) {
|
||||
@@ -85,82 +84,76 @@ export default ({ app }: { app: Application }) => {
|
||||
}
|
||||
return next();
|
||||
});
|
||||
app.use(
|
||||
withAuthAvailability(async (req: Request, res, next) => {
|
||||
const pathLower = req.path.toLowerCase();
|
||||
if (!['/open/', '/api/'].some((x) => pathLower.startsWith(x))) {
|
||||
return next();
|
||||
}
|
||||
const headerToken = getToken(req);
|
||||
if (pathLower.startsWith('/open/')) {
|
||||
const apps = await shareStore.getApps();
|
||||
const doc = apps?.filter((x) =>
|
||||
x.tokens?.find((y) => y.value === headerToken),
|
||||
)?.[0];
|
||||
if (doc && doc.tokens && doc.tokens.length > 0) {
|
||||
const currentToken = doc.tokens.find((x) => x.value === headerToken);
|
||||
const keyMatch = pathLower.match(/\/open\/([a-z]+)\/*/);
|
||||
const key = keyMatch && keyMatch[1];
|
||||
if (!doc.scopes.includes(key as AppScope)) {
|
||||
const err = new UnauthorizedError('credentials_bad_scheme', {
|
||||
message: t('暂无权限'),
|
||||
});
|
||||
return next(err);
|
||||
}
|
||||
if (
|
||||
!currentToken ||
|
||||
currentToken.expiration < Math.round(Date.now() / 1000)
|
||||
) {
|
||||
const err = new UnauthorizedError('invalid_token', {
|
||||
message: t('Token 已失效'),
|
||||
});
|
||||
return next(err);
|
||||
}
|
||||
return next();
|
||||
app.use(async (req: Request, res, next) => {
|
||||
const pathLower = req.path.toLowerCase();
|
||||
if (!['/open/', '/api/'].some((x) => pathLower.startsWith(x))) {
|
||||
return next();
|
||||
}
|
||||
const headerToken = getToken(req);
|
||||
if (pathLower.startsWith('/open/')) {
|
||||
const apps = await shareStore.getApps();
|
||||
const doc = apps?.filter((x) =>
|
||||
x.tokens?.find((y) => y.value === headerToken),
|
||||
)?.[0];
|
||||
if (doc && doc.tokens && doc.tokens.length > 0) {
|
||||
const currentToken = doc.tokens.find((x) => x.value === headerToken);
|
||||
const keyMatch = pathLower.match(/\/open\/([a-z]+)\/*/);
|
||||
const key = keyMatch && keyMatch[1];
|
||||
if (!doc.scopes.includes(key as AppScope)) {
|
||||
const err = new UnauthorizedError('credentials_bad_scheme', {
|
||||
message: t('暂无权限'),
|
||||
});
|
||||
return next(err);
|
||||
}
|
||||
if (
|
||||
!currentToken ||
|
||||
currentToken.expiration < Math.round(Date.now() / 1000)
|
||||
) {
|
||||
const err = new UnauthorizedError('invalid_token', {
|
||||
message: t('Token 已失效'),
|
||||
});
|
||||
return next(err);
|
||||
}
|
||||
}
|
||||
const originPath = `${req.baseUrl}${pathLower === '/' ? '' : pathLower}`;
|
||||
if (
|
||||
!headerToken &&
|
||||
originPath &&
|
||||
config.apiWhiteList.includes(originPath)
|
||||
) {
|
||||
return next();
|
||||
}
|
||||
const authInfo = await shareStore.getAuthInfo();
|
||||
if (
|
||||
isValidToken(authInfo, headerToken, req.platform, config.jwt.secret)
|
||||
) {
|
||||
return next();
|
||||
}
|
||||
const errorCode = headerToken ? 'invalid_token' : 'credentials_required';
|
||||
const errorMessage = headerToken ? t('Token 已失效') : t('请先登录');
|
||||
const err = new UnauthorizedError(errorCode, { message: errorMessage });
|
||||
next(err);
|
||||
}),
|
||||
);
|
||||
app.use(
|
||||
withAuthAvailability(async (req, res, next) => {
|
||||
const pathLower = req.path.toLowerCase();
|
||||
if (
|
||||
![
|
||||
'/api/user/init',
|
||||
'/api/user/notification/init',
|
||||
'/open/user/init',
|
||||
'/open/user/notification/init',
|
||||
].includes(pathLower)
|
||||
) {
|
||||
return next();
|
||||
}
|
||||
const authInfo = (await shareStore.getAuthInfo()) || ({} as AuthInfo);
|
||||
let isInitialized = !isDefaultAuthInfo(authInfo);
|
||||
if (isInitialized) {
|
||||
return res.send({ code: 450, message: t('未知错误') });
|
||||
} else {
|
||||
return next();
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
const originPath = `${req.baseUrl}${pathLower === '/' ? '' : pathLower}`;
|
||||
if (
|
||||
!headerToken &&
|
||||
originPath &&
|
||||
config.apiWhiteList.includes(originPath)
|
||||
) {
|
||||
return next();
|
||||
}
|
||||
const authInfo = await shareStore.getAuthInfo();
|
||||
if (isValidToken(authInfo, headerToken, req.platform, config.jwt.secret)) {
|
||||
return next();
|
||||
}
|
||||
const errorCode = headerToken ? 'invalid_token' : 'credentials_required';
|
||||
const errorMessage = headerToken ? t('Token 已失效') : t('请先登录');
|
||||
const err = new UnauthorizedError(errorCode, { message: errorMessage });
|
||||
next(err);
|
||||
});
|
||||
app.use(async (req, res, next) => {
|
||||
const pathLower = req.path.toLowerCase();
|
||||
if (
|
||||
![
|
||||
'/api/user/init',
|
||||
'/api/user/notification/init',
|
||||
'/open/user/init',
|
||||
'/open/user/notification/init',
|
||||
].includes(pathLower)
|
||||
) {
|
||||
return next();
|
||||
}
|
||||
const authInfo = (await shareStore.getAuthInfo()) || ({} as AuthInfo);
|
||||
let isInitialized = !isDefaultAuthInfo(authInfo);
|
||||
if (isInitialized) {
|
||||
return res.send({ code: 450, message: t('未知错误') });
|
||||
} else {
|
||||
return next();
|
||||
}
|
||||
});
|
||||
app.use(rewrite('/open/*', '/api/$1'));
|
||||
app.use(config.api.prefix, routes());
|
||||
app.get('*', (req, res, next) => {
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
import type { RequestHandler } from 'express';
|
||||
import { t } from '../shared/i18n';
|
||||
|
||||
// Express 4 does not forward rejected async middleware promises itself.
|
||||
export function withAuthAvailability(handler: RequestHandler): RequestHandler {
|
||||
return (req, res, next) => {
|
||||
void Promise.resolve()
|
||||
.then(() => handler(req, res, next))
|
||||
.catch(() => {
|
||||
res.setHeader('Retry-After', '1');
|
||||
next(
|
||||
Object.assign(new Error(t('认证服务暂时不可用,请稍后重试')), {
|
||||
status: 503,
|
||||
}),
|
||||
);
|
||||
});
|
||||
};
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
const messages: Record<string, Record<string, string>> = {
|
||||
zh: {},
|
||||
en: {
|
||||
'认证服务暂时不可用,请稍后重试':
|
||||
'Authentication service is temporarily unavailable; try again shortly.',
|
||||
'升级任务启动失败,请检查日志后重试':
|
||||
'Failed to start the update. Check the logs and try again.',
|
||||
'[schedule][停止已运行任务] 任务ID: %s, PID: %s':
|
||||
|
||||
@@ -16,11 +16,7 @@ export interface IKeyvStore {
|
||||
}
|
||||
|
||||
const keyvSqlite = new CacheStore();
|
||||
// A stopped database is unavailable, not a cache miss or an expired session.
|
||||
export const keyvStore = new Keyv<IKeyvStore>({
|
||||
store: keyvSqlite,
|
||||
throwOnErrors: true,
|
||||
});
|
||||
export const keyvStore = new Keyv<IKeyvStore>({ store: keyvSqlite });
|
||||
|
||||
export const shareStore = {
|
||||
getAuthInfo() {
|
||||
|
||||
@@ -22,16 +22,8 @@ RUN set -x \
|
||||
npm_config_target_libc=musl \
|
||||
QL_BUILD_ONLY=1 pnpm install --prod --frozen-lockfile
|
||||
|
||||
# The amd64 APK runtime has crashed in native URL parsing on dev. Keep its
|
||||
# URL implementation bundled with the pinned upstream musl Node binary.
|
||||
FROM --platform=linux/amd64 node:24.18.1-alpine3.24@sha256:f70403e87646dc51b45295f4b8b70cdad0b63d2297c4c9899119b03f7af7a6b3 AS node-runtime-amd64
|
||||
|
||||
FROM python:3.11-alpine
|
||||
|
||||
ARG TARGETARCH
|
||||
ARG TARGETVARIANT
|
||||
COPY --from=node-runtime-amd64 /usr/local/bin/node /tmp/node-runtime-amd64
|
||||
|
||||
ARG QL_MAINTAINER="whyour"
|
||||
LABEL maintainer="${QL_MAINTAINER}"
|
||||
ARG QL_URL=https://github.com/${QL_MAINTAINER}/qinglong.git
|
||||
@@ -70,10 +62,6 @@ RUN set -x \
|
||||
netcat-openbsd \
|
||||
unzip \
|
||||
npm \
|
||||
&& if [ "$TARGETARCH" = amd64 ]; then \
|
||||
mv /tmp/node-runtime-amd64 /usr/local/bin/node; \
|
||||
ln -sf /usr/local/bin/node /usr/bin/node; \
|
||||
else rm /tmp/node-runtime-amd64; fi \
|
||||
&& rm -rf /var/cache/apk/* \
|
||||
&& apk update \
|
||||
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
|
||||
@@ -98,10 +86,6 @@ COPY static/ /ql/static/
|
||||
COPY docker/verify-build.cjs docker/build-manifest.cjs /tmp/
|
||||
COPY --from=builder /tmp/build/pnpm-lock.yaml /tmp/dependency-lock.yaml
|
||||
RUN cd ${QL_DIR} && node /tmp/verify-build.cjs /tmp/dependency-lock.yaml
|
||||
RUN if [ "$TARGETARCH" = arm ] && [ "${TARGETVARIANT:-}" = v6 ]; then \
|
||||
QEMU_CPU=arm1176 node --jitless ${QL_DIR}/shell/node-runtime-probe.cjs; \
|
||||
else node ${QL_DIR}/shell/node-runtime-probe.cjs; fi
|
||||
|
||||
|
||||
ENV PNPM_HOME=${QL_DIR}/data/dep_cache/node \
|
||||
PYTHON_HOME=${QL_DIR}/data/dep_cache/python3 \
|
||||
|
||||
@@ -22,16 +22,8 @@ RUN set -x \
|
||||
npm_config_target_libc=musl \
|
||||
QL_BUILD_ONLY=1 pnpm install --prod --frozen-lockfile
|
||||
|
||||
# The amd64 APK runtime has crashed in native URL parsing on dev. Keep its
|
||||
# URL implementation bundled with the pinned upstream musl Node binary.
|
||||
FROM --platform=linux/amd64 node:24.18.1-alpine3.24@sha256:f70403e87646dc51b45295f4b8b70cdad0b63d2297c4c9899119b03f7af7a6b3 AS node-runtime-amd64
|
||||
|
||||
FROM python:3.10-alpine
|
||||
|
||||
ARG TARGETARCH
|
||||
ARG TARGETVARIANT
|
||||
COPY --from=node-runtime-amd64 /usr/local/bin/node /tmp/node-runtime-amd64
|
||||
|
||||
ARG QL_MAINTAINER="whyour"
|
||||
LABEL maintainer="${QL_MAINTAINER}"
|
||||
ARG QL_URL=https://github.com/${QL_MAINTAINER}/qinglong.git
|
||||
@@ -70,10 +62,6 @@ RUN set -x \
|
||||
netcat-openbsd \
|
||||
unzip \
|
||||
npm \
|
||||
&& if [ "$TARGETARCH" = amd64 ]; then \
|
||||
mv /tmp/node-runtime-amd64 /usr/local/bin/node; \
|
||||
ln -sf /usr/local/bin/node /usr/bin/node; \
|
||||
else rm /tmp/node-runtime-amd64; fi \
|
||||
&& rm -rf /var/cache/apk/* \
|
||||
&& apk update \
|
||||
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
|
||||
@@ -98,10 +86,6 @@ COPY static/ /ql/static/
|
||||
COPY docker/verify-build.cjs docker/build-manifest.cjs /tmp/
|
||||
COPY --from=builder /tmp/build/pnpm-lock.yaml /tmp/dependency-lock.yaml
|
||||
RUN cd ${QL_DIR} && node /tmp/verify-build.cjs /tmp/dependency-lock.yaml
|
||||
RUN if [ "$TARGETARCH" = arm ] && [ "${TARGETVARIANT:-}" = v6 ]; then \
|
||||
QEMU_CPU=arm1176 node --jitless ${QL_DIR}/shell/node-runtime-probe.cjs; \
|
||||
else node ${QL_DIR}/shell/node-runtime-probe.cjs; fi
|
||||
|
||||
|
||||
ENV PNPM_HOME=${QL_DIR}/data/dep_cache/node \
|
||||
PYTHON_HOME=${QL_DIR}/data/dep_cache/python3 \
|
||||
|
||||
+1
-1
@@ -148,7 +148,7 @@
|
||||
"ip2region": "2.3.0",
|
||||
"js-yaml": "^4.1.0",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"keyv": "5.6.0",
|
||||
"keyv": "^5.2.3",
|
||||
"lodash": "^4.17.21",
|
||||
"multer": "2.4.0",
|
||||
"node-cron": "4.6.0",
|
||||
|
||||
Generated
+16
-9
@@ -89,8 +89,8 @@ dependencies:
|
||||
specifier: ^9.0.2
|
||||
version: 9.0.2
|
||||
keyv:
|
||||
specifier: 5.6.0
|
||||
version: 5.6.0
|
||||
specifier: ^5.2.3
|
||||
version: 5.2.3
|
||||
lodash:
|
||||
specifier: ^4.17.21
|
||||
version: 4.17.21
|
||||
@@ -3186,8 +3186,10 @@ packages:
|
||||
resolution: {integrity: sha512-iUKgm52T8HOE/makSxjqoWhe95ZJA1/G1sYsGev2JDKUSS14KAgg1LHb+Ba+IPow0xflbnSkOsZcO08C7w1gYw==}
|
||||
dev: false
|
||||
|
||||
/@keyv/serialize@1.1.1:
|
||||
resolution: {integrity: sha512-dXn3FZhPv0US+7dtJsIi2R+c7qWYiReoEh5zUntWCf4oSpMNib8FDhSoed6m3QyZdx5hK7iLFkYk3rNxwt8vTA==}
|
||||
/@keyv/serialize@1.0.2:
|
||||
resolution: {integrity: sha512-+E/LyaAeuABniD/RvUezWVXKpeuvwLEA9//nE9952zBaOdBd2mQ3pPoM8cUe2X6IcMByfuSLzmYqnYshG60+HQ==}
|
||||
dependencies:
|
||||
buffer: 6.0.3
|
||||
dev: false
|
||||
|
||||
/@lezer/common@1.2.3:
|
||||
@@ -6318,7 +6320,6 @@ packages:
|
||||
|
||||
/base64-js@1.5.1:
|
||||
resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==}
|
||||
dev: true
|
||||
|
||||
/before@0.0.1:
|
||||
resolution: {integrity: sha512-1J5SWbkoVJH9DTALN8igB4p+nPKZzPrJ/HomqBDLpfUvDXCdjdBmBUcH5McZfur0lftVssVU6BZug5NYh87zTw==}
|
||||
@@ -6529,6 +6530,13 @@ packages:
|
||||
isarray: 1.0.0
|
||||
dev: true
|
||||
|
||||
/buffer@6.0.3:
|
||||
resolution: {integrity: sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==}
|
||||
dependencies:
|
||||
base64-js: 1.5.1
|
||||
ieee754: 1.2.1
|
||||
dev: false
|
||||
|
||||
/builtin-status-codes@3.0.0:
|
||||
resolution: {integrity: sha512-HpGFw18DgFWlncDfjTa2rcQ4W88O1mC8e8yZ2AvQY5KDaktSTwo+KRf6nHK6FRI5FyRyb/5T6+TSxfP7QyGsmQ==}
|
||||
dev: true
|
||||
@@ -9521,7 +9529,6 @@ packages:
|
||||
|
||||
/ieee754@1.2.1:
|
||||
resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==}
|
||||
dev: true
|
||||
|
||||
/ignore-by-default@1.0.1:
|
||||
resolution: {integrity: sha512-Ius2VYcGNk7T90CppJqcIkS5ooHUZyIQK+ClZfMfMNFEF9VSE73Fq+906u/CWu92x4gzZMWOwfFYckPObzdEbA==}
|
||||
@@ -10247,10 +10254,10 @@ packages:
|
||||
json-buffer: 3.0.1
|
||||
dev: true
|
||||
|
||||
/keyv@5.6.0:
|
||||
resolution: {integrity: sha512-CYDD3SOtsHtyXeEORYRx2qBtpDJFjRTGXUtmNEMGyzYOKj1TE3tycdlho7kA1Ufx9OYWZzg52QFBGALTirzDSw==}
|
||||
/keyv@5.2.3:
|
||||
resolution: {integrity: sha512-AGKecUfzrowabUv0bH1RIR5Vf7w+l4S3xtQAypKaUpTdIR1EbrAcTxHCrpo9Q+IWeUlFE2palRtgIQcgm+PQJw==}
|
||||
dependencies:
|
||||
'@keyv/serialize': 1.1.1
|
||||
'@keyv/serialize': 1.0.2
|
||||
dev: false
|
||||
|
||||
/kind-of@6.0.3:
|
||||
|
||||
@@ -33,7 +33,6 @@ const requiredFiles = [
|
||||
'shell/install-package.cjs',
|
||||
'shell/upgrade-lock.yaml',
|
||||
'shell/runtime-guard.cjs',
|
||||
'shell/node-runtime-probe.cjs',
|
||||
'shell/start.sh',
|
||||
'shell/start-simplify.sh',
|
||||
'shell/task.sh',
|
||||
@@ -302,12 +301,7 @@ async function verifyPanel(input, output) {
|
||||
signal: AbortSignal.timeout(5000),
|
||||
});
|
||||
const result = await response.json();
|
||||
try {
|
||||
assert.equal(result.code, 200, `${method} ${route}: ${result.message}`);
|
||||
} catch (error) {
|
||||
error.status = response.status;
|
||||
throw error;
|
||||
}
|
||||
assert.equal(result.code, 200, `${method} ${route}: ${result.message}`);
|
||||
return result.data;
|
||||
};
|
||||
const healthy = async () => {
|
||||
@@ -332,7 +326,6 @@ async function verifyPanel(input, output) {
|
||||
throw new Error(value.error);
|
||||
} catch (error) {
|
||||
if (
|
||||
error.status !== 503 &&
|
||||
!/fetch failed|ECONNRESET|ECONNREFUSED|aborted|timeout/i.test(
|
||||
error.message,
|
||||
)
|
||||
@@ -382,16 +375,6 @@ async function verifyPanel(input, output) {
|
||||
).stdout.trim();
|
||||
root = path.join(globalRoot, '@whyour/qinglong');
|
||||
env.QL_DIR = root;
|
||||
const runtimeProbes = [];
|
||||
const checkRuntime = async () => {
|
||||
const result = await run(
|
||||
process.execPath,
|
||||
[path.join(root, 'shell/node-runtime-probe.cjs')],
|
||||
{ cwd: temp, env },
|
||||
);
|
||||
runtimeProbes.push(JSON.parse(result.stdout.trim()));
|
||||
};
|
||||
await checkRuntime();
|
||||
// Use a subprocess: cached candidate modules must not mask missing files
|
||||
// after old-package installation and the real npm overwrite below.
|
||||
await run(
|
||||
@@ -577,7 +560,6 @@ async function verifyPanel(input, output) {
|
||||
const applying = await api('update/system', 'PUT');
|
||||
await job(applying.id, 'completed');
|
||||
const afterOnline = await healthy();
|
||||
await checkRuntime();
|
||||
assert.notEqual(afterOnline.build.instanceId, original.build.instanceId);
|
||||
assert.equal(afterOnline.build.sourceCommit, fixture.sourceCommit);
|
||||
await fs.access(path.join(root, 'node_modules/.pnpm'));
|
||||
@@ -629,7 +611,6 @@ async function verifyPanel(input, output) {
|
||||
timeout: 240000,
|
||||
});
|
||||
const afterOffline = await healthy();
|
||||
await checkRuntime();
|
||||
assert.notEqual(
|
||||
afterOffline.build.instanceId,
|
||||
afterOnline.build.instanceId,
|
||||
@@ -675,7 +656,6 @@ async function verifyPanel(input, output) {
|
||||
},
|
||||
migratedFromNpmToOfficialPnpmLayout: true,
|
||||
existingNodePreserved: true,
|
||||
nativeUrlRuntimeProbes: runtimeProbes,
|
||||
frontendAndBackendStarted: true,
|
||||
checksumFailureKeptOldService: true,
|
||||
prestartBeforeReady: true,
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const os = require('node:os');
|
||||
const path = require('node:path');
|
||||
const { createHash } = require('node:crypto');
|
||||
const { spawnSync } = require('node:child_process');
|
||||
|
||||
// Run in new processes: a healthy parent can outlive a broken native runtime.
|
||||
function probeNodeRuntime(executable = process.execPath) {
|
||||
const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'ql-node-url-'));
|
||||
const source = `
|
||||
const assert = require('node:assert/strict');
|
||||
const { pathToFileURL, fileURLToPath } = require('node:url');
|
||||
for (let i = 0; i < 1000; i++) {
|
||||
assert.equal(new URL('/任务?q=' + i, 'https://example.com').hostname, 'example.com');
|
||||
assert.equal(new URL('https://例子.测试').hostname, 'xn--fsqu00a.xn--0zwm56d');
|
||||
assert.equal(new URL('http://[::1]:5700').port, '5700');
|
||||
const filename = '/tmp/中文 path/' + i + '.cjs';
|
||||
assert.equal(fileURLToPath(pathToFileURL(filename)), filename);
|
||||
}
|
||||
console.log('QINGLONG_NODE_URL_OK');
|
||||
`;
|
||||
const file = path.join(directory, 'probe.cjs');
|
||||
fs.writeFileSync(file, source);
|
||||
try {
|
||||
for (let i = 0; i < 4; i++) {
|
||||
const args = process.execArgv.includes('--jitless') ? ['--jitless'] : [];
|
||||
args.push(...(i % 2 ? [file] : ['-e', source]));
|
||||
const child = spawnSync(executable, args, {
|
||||
encoding: 'utf8',
|
||||
timeout: 20000,
|
||||
maxBuffer: 65536,
|
||||
env: { ...process.env, NODE_OPTIONS: '' },
|
||||
});
|
||||
assert.equal(
|
||||
child.status,
|
||||
0,
|
||||
`Node URL runtime probe failed (${i % 2 ? 'file' : 'eval'}): signal=${
|
||||
child.signal
|
||||
}; status=${child.status}; ${child.error?.message || child.stderr}`,
|
||||
);
|
||||
assert.match(child.stdout, /QINGLONG_NODE_URL_OK/);
|
||||
}
|
||||
return {
|
||||
ok: true,
|
||||
node: process.version,
|
||||
architecture: process.arch,
|
||||
ada: process.versions.ada,
|
||||
processes: 4,
|
||||
urlIterationsPerProcess: 1000,
|
||||
nodeSha256: createHash('sha256')
|
||||
.update(fs.readFileSync(executable))
|
||||
.digest('hex'),
|
||||
};
|
||||
} finally {
|
||||
fs.rmSync(directory, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { probeNodeRuntime };
|
||||
if (require.main === module) console.log(JSON.stringify(probeNodeRuntime()));
|
||||
@@ -1,129 +0,0 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const path = require('node:path');
|
||||
const os = require('node:os');
|
||||
const fs = require('node:fs/promises');
|
||||
const express = require('express');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const load = require('../helpers/load-security-module.cjs');
|
||||
|
||||
test('authentication cache propagates database read and write failures', async () => {
|
||||
const failure = new Error('synthetic unavailable database');
|
||||
const CacheStore = load(path.resolve('back/data/cacheStore.ts'), {
|
||||
'.': {
|
||||
database: {
|
||||
request: async () => {
|
||||
throw failure;
|
||||
},
|
||||
},
|
||||
},
|
||||
}).CacheStore;
|
||||
const { shareStore } = load(path.resolve('back/shared/store.ts'), {
|
||||
'../data/cacheStore': { CacheStore },
|
||||
});
|
||||
await assert.rejects(shareStore.getAuthInfo(), (error) => error === failure);
|
||||
await assert.rejects(
|
||||
shareStore.updateAuthInfo({ username: 'qa' }),
|
||||
(error) => error === failure,
|
||||
);
|
||||
});
|
||||
|
||||
test('HTTP authentication distinguishes unavailable storage from an invalid session', async (t) => {
|
||||
const root = await fs.mkdtemp(
|
||||
path.join(os.tmpdir(), 'ql-auth-availability-'),
|
||||
);
|
||||
const secret = 'synthetic-auth-availability';
|
||||
const token = jwt.sign({}, secret, { algorithm: 'HS384', expiresIn: '1h' });
|
||||
const auth = { username: 'qa', password: 'configured', token };
|
||||
let unavailable = false;
|
||||
let initialized = 0;
|
||||
const read = async (value) => {
|
||||
if (unavailable) throw new Error(`SQL failure must not expose ${token}`);
|
||||
return value;
|
||||
};
|
||||
const router = express.Router();
|
||||
router.get('/system/update-status', (_req, res) => res.json({ code: 200 }));
|
||||
router.get('/envs', (_req, res) => res.json({ code: 200 }));
|
||||
router.get('/health', (_req, res) => res.json({ code: 200 }));
|
||||
router.put('/user/init', (_req, res) => {
|
||||
initialized++;
|
||||
res.json({ code: 200 });
|
||||
});
|
||||
const app = express();
|
||||
load(path.resolve('back/loaders/express.ts'), {
|
||||
'../config': {
|
||||
rootPath: root,
|
||||
uploadPath: path.join(root, 'upload'),
|
||||
configPath: path.join(root, 'config'),
|
||||
api: { prefix: '/api' },
|
||||
apiWhiteList: ['/api/health', '/api/user/init'],
|
||||
jwt: { secret },
|
||||
},
|
||||
'../api': () => router,
|
||||
'../config/util': {
|
||||
getToken: (req) =>
|
||||
(req.headers.authorization || '').replace(/^Bearer /, ''),
|
||||
getPlatform: () => 'desktop',
|
||||
},
|
||||
'../shared/store': {
|
||||
shareStore: {
|
||||
getAuthInfo: () => read(auth),
|
||||
getApps: () =>
|
||||
read([
|
||||
{
|
||||
scopes: ['envs'],
|
||||
tokens: [
|
||||
{ value: 'app-token', expiration: Date.now() / 1000 + 3600 },
|
||||
],
|
||||
},
|
||||
]),
|
||||
},
|
||||
},
|
||||
'../shared/i18n': { t: (value) => value },
|
||||
'../config/serverEnv': { serveEnv: (_req, res) => res.end() },
|
||||
'../data/open': {},
|
||||
'../data/system': {},
|
||||
}).default({ app });
|
||||
const server = app.listen(0, '127.0.0.1');
|
||||
t.after(async () => {
|
||||
await new Promise((resolve) => server.close(resolve));
|
||||
await fs.rm(root, { recursive: true, force: true });
|
||||
});
|
||||
await new Promise((resolve) => server.once('listening', resolve));
|
||||
const request = async (route, value, method = 'GET') => {
|
||||
const response = await fetch(
|
||||
`http://127.0.0.1:${server.address().port}${route}`,
|
||||
{
|
||||
method,
|
||||
headers: value ? { Authorization: `Bearer ${value}` } : {},
|
||||
signal: AbortSignal.timeout(3000),
|
||||
},
|
||||
);
|
||||
return { status: response.status, body: await response.text() };
|
||||
};
|
||||
assert.equal((await request('/api/system/update-status', token)).status, 200);
|
||||
unavailable = true;
|
||||
for (const [route, value, method] of [
|
||||
['/api/system/update-status', token],
|
||||
['/open/envs', 'app-token'],
|
||||
['/api/user/init', undefined, 'PUT'],
|
||||
]) {
|
||||
const response = await request(route, value, method);
|
||||
assert.equal(response.status, 503);
|
||||
assert.equal(JSON.parse(response.body).code, 503);
|
||||
assert.ok(!response.body.includes(token));
|
||||
assert.ok(!response.body.includes('SQL failure'));
|
||||
}
|
||||
assert.equal(initialized, 0);
|
||||
assert.equal((await request('/api/health')).status, 200);
|
||||
unavailable = false;
|
||||
assert.equal((await request('/api/system/update-status', token)).status, 200);
|
||||
const invalid = jwt.sign({ unrecognized: true }, secret, {
|
||||
algorithm: 'HS384',
|
||||
expiresIn: '1h',
|
||||
});
|
||||
assert.equal(
|
||||
(await request('/api/system/update-status', invalid)).status,
|
||||
401,
|
||||
);
|
||||
});
|
||||
@@ -1,25 +0,0 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const os = require('node:os');
|
||||
const path = require('node:path');
|
||||
const { probeNodeRuntime } = require('../../shell/node-runtime-probe.cjs');
|
||||
|
||||
test('the retained Node handles URL, IDNA and file paths in fresh eval and file processes', () => {
|
||||
const result = probeNodeRuntime();
|
||||
assert.equal(result.ok, true);
|
||||
assert.equal(result.processes, 4);
|
||||
assert.match(result.nodeSha256, /^[0-9a-f]{64}$/);
|
||||
});
|
||||
|
||||
test('a native child crash fails the runtime probe instead of accepting its healthy parent', (t) => {
|
||||
if (process.platform === 'win32') return t.skip('POSIX crash fixture');
|
||||
const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'ql-node-crash-'));
|
||||
t.after(() => fs.rmSync(directory, { recursive: true, force: true }));
|
||||
const executable = path.join(directory, 'node');
|
||||
fs.writeFileSync(executable, '#!/bin/sh\nkill -SEGV $$\n', { mode: 0o700 });
|
||||
assert.throws(
|
||||
() => probeNodeRuntime(executable),
|
||||
/Node URL runtime probe failed.*SIGSEGV/,
|
||||
);
|
||||
});
|
||||
@@ -484,18 +484,14 @@ test('npm publication consumes the exact archive whose isolated installation pas
|
||||
assert.deepEqual(verify.needs, [
|
||||
'build-static',
|
||||
'build-npm-migration-bundle',
|
||||
'build-alpine',
|
||||
]);
|
||||
assert.ok(
|
||||
verify.steps.some(
|
||||
(step) =>
|
||||
step.with?.name ===
|
||||
"npm-migration-bundle-${{ matrix.node == 'alpine' && 'musl' || 'glibc' }}-${{ github.sha }}",
|
||||
(step) => step.with?.name === 'npm-migration-bundle-${{ github.sha }}',
|
||||
),
|
||||
);
|
||||
const migration = workflow.jobs['build-npm-migration-bundle'];
|
||||
assert.deepEqual(migration.needs, ['build-debian', 'build-alpine']);
|
||||
assert.deepEqual(migration.strategy.matrix.libc, ['glibc', 'musl']);
|
||||
assert.equal(migration.needs, 'build-debian');
|
||||
assert.ok(
|
||||
migration.steps.some((step) =>
|
||||
/Dockerfile.upgrade-bundle/.test(step.run || ''),
|
||||
@@ -506,17 +502,8 @@ test('npm publication consumes the exact archive whose isolated installation pas
|
||||
/publish-upgrade-bundles/.test(step.run || ''),
|
||||
),
|
||||
);
|
||||
assert.deepEqual(verify.strategy.matrix.node, [
|
||||
'20.18.1',
|
||||
'22.17.0',
|
||||
'24',
|
||||
'alpine',
|
||||
]);
|
||||
assert.match(
|
||||
verify.container.image,
|
||||
/needs\.build-alpine\.outputs\.image-digest/,
|
||||
);
|
||||
assert.match(verify.container.image, /node:.*bookworm/);
|
||||
assert.deepEqual(verify.strategy.matrix.node, ['20.18.1', '22.17.0', '24']);
|
||||
assert.match(verify.container, /node:.*bookworm/);
|
||||
const tools = verify.steps.find(
|
||||
(step) => step.name === 'Install isolated service test tools',
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user