Validate login redirects for actual Next.js data routes
waterfall-wiki CI and deployment / verify-and-deploy (push) Failing after 16m15s

This commit is contained in:
2026-10-27 01:18:04 +08:00
parent 86d7f5adf9
commit 01c0f6ca73
3 changed files with 17 additions and 5 deletions
+5 -4
View File
@@ -1,9 +1,9 @@
import { mkdirSync, writeFileSync, existsSync, renameSync, chmodSync, chownSync } from 'node:fs';
import { mkdirSync, writeFileSync, existsSync, readFileSync, renameSync, chmodSync, chownSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { pathToFileURL } from 'node:url';
import assert from 'node:assert/strict';
import QRCode from 'qrcode';
import { authConfig, newAuthConfig, signSession, totp } from '../src/lib/auth';
import { authConfig, newAuthConfig, signSession, totp, isLoginRedirect } from '../src/lib/auth';
import { db } from '../src/lib/db';
async function main() {
@@ -46,8 +46,9 @@ async function main() {
}
if (command === 'verify' || command === 'exercise') {
const request = (path:string,init:RequestInit={}) => fetch(base+path,{...init,redirect:'manual'});
for (const path of ['/','/library/import','/skills/shadow-puppet/egret-example.png','/studio','/_next/data/auth-test/index.json']) {
const response = await request(path); assert.equal(response.status,307,path); assert.match(response.headers.get('location') || response.headers.get('x-nextjs-redirect') || '',/\/login\?/,path+' must redirect to login');
const buildId = readFileSync('.next/BUILD_ID','utf8').trim();
for (const path of ['/','/library/import','/skills/shadow-puppet/egret-example.png','/studio',`/_next/data/${buildId}/index.json`]) {
const response = await request(path); assert.equal(response.status,307,path); const destination = response.headers.get('location') || response.headers.get('x-nextjs-redirect'); assert.ok(isLoginRedirect(destination,base),path+' must redirect to login: '+destination);
}
for (const path of ['/api/feed','/api/upload','/studio/api/export/test','/api/media/missing']) assert.equal((await request(path)).status,401,path);
assert.equal((await request('/api/posts',{method:'POST',body:'{}'})).status,401);