Reframe AI-tlas as a public research journal with authenticator-protected editorial workspace
Validate / validate (push) Successful in 3m15s

This commit is contained in:
2026-10-30 20:02:22 +08:00
parent b5de41501b
commit 712046e86f
18 changed files with 353 additions and 68 deletions
+1 -1
View File
@@ -132,7 +132,7 @@ systemctl enable "$APP" >/dev/null 2>&1
systemctl restart "$APP"
ok=0
for i in 1 2 3 4 5 6 7 8 9 10; do
if curl -fsS -o /dev/null "http://127.0.0.1:$PORT/" && curl -fsS -o /dev/null "http://127.0.0.1:$PORT/papers?q=agent"; then ok=1; break; fi
if curl -fsS -o /dev/null "http://127.0.0.1:$PORT/" && curl -fsS -o /dev/null "http://127.0.0.1:$PORT/contents"; then ok=1; break; fi
sleep 2
done
[ "$ok" = 1 ] || { journalctl -u "$APP" -n 60 --no-pager; exit 1; }
+17
View File
@@ -0,0 +1,17 @@
const { spawn } = require('node:child_process');
const assert = require('node:assert/strict');
const server = spawn(process.execPath, ['node_modules/next/dist/bin/next','start','-p','19381','-H','127.0.0.1'], {env:{...process.env,EDITOR_SESSION_SECRET:'test-only-secret-that-is-at-least-32-characters',EDITOR_ORIGIN:'http://127.0.0.1:19381'},stdio:['ignore','pipe','pipe']});
(async()=>{
const origin='http://127.0.0.1:19381'; let ready=false;
for(let i=0;i<60;i++) {try {const r=await fetch(origin+'/editor/login');if(r.ok){ready=true;break;}}catch{}await new Promise(r=>setTimeout(r,500));}
assert(ready,'Next server did not become ready');
for(const path of ['/api/blocks','/api/tool-taxonomy','/api/blocks?page=content/tools-of-agents']) {
for(const headers of [{},{'x-middleware-subrequest':'middleware:middleware:middleware:middleware:middleware'}]) {
const r=await fetch(origin+path,{headers});assert.equal(r.status,401,path);
}
}
for(const path of ['/papers','/papers/11702','/overview','/landscape','/contents/unpublished'])assert.equal((await fetch(origin+path)).status,404,path);
for(const path of ['/editor','/editor/contents/tools-of-agents']) {const r=await fetch(origin+path,{redirect:'manual'});assert.equal(r.status,307,path);assert(r.headers.get('location').endsWith('/editor/login'));}
const csrf=await fetch(origin+'/api/editor/login',{method:'POST',headers:{'Content-Type':'application/json',Origin:'https://other.invalid'},body:JSON.stringify({code:'123456'})});assert.equal(csrf.status,403);
console.log('Anonymous route, middleware bypass and CSRF smoke checks: passed');
})().catch(e=>{console.error(e);process.exitCode=1;}).finally(()=>server.kill());
+24
View File
@@ -0,0 +1,24 @@
// Remote-runner tests: transpile only into memory, never emit artifacts.
const assert = require('node:assert/strict');
const vm = require('node:vm');
const fs = require('node:fs');
const ts = require('typescript');
const { webcrypto } = require('node:crypto');
const context = { exports: {}, crypto: webcrypto, TextEncoder, Uint8Array, Date, process: { env: { EDITOR_SESSION_SECRET: 'test-only-secret-with-at-least-32-characters' } } };
vm.runInNewContext(ts.transpileModule(fs.readFileSync('lib/editor-session.ts','utf8'), {compilerOptions:{module:ts.ModuleKind.CommonJS,target:ts.ScriptTarget.ES2020}}).outputText, context);
(async () => {
const {signSession,validSession} = context.exports;
const payload = `${Date.now()+60_000}.${'a'.repeat(32)}`;
const token = `${payload}.${await signSession(payload)}`;
assert.equal(await validSession(token),true);
for (const value of [undefined,'',token+'x',token+'.extra',token.replace(/^./,'0')]) assert.equal(await validSession(value),false);
const expired = `${Date.now()-1000}.${'a'.repeat(32)}`;
assert.equal(await validSession(`${expired}.${await signSession(expired)}`),false);
const future = `${Date.now()+9*3600_000}.${'a'.repeat(32)}`;
assert.equal(await validSession(`${future}.${await signSession(future)}`),false);
context.process.env.EDITOR_SESSION_SECRET = 'rotated-secret-with-at-least-32-characters';
assert.equal(await validSession(token),false);
context.process.env.EDITOR_SESSION_SECRET = '';
assert.equal(await validSession(token),false);
console.log('Editor session validation: passed');
})().catch(error => { console.error(error); process.exitCode=1; });