18 lines
1.7 KiB
JavaScript
18 lines
1.7 KiB
JavaScript
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());
|