bend_puzzle/test/v4792-apache-bridge-smoke-test.js
2026-08-01 16:06:14 +09:00

40 lines
1.9 KiB
JavaScript

'use strict';
const assert=require('assert/strict');
const fs=require('fs');
const fsp=fs.promises;
const os=require('os');
const path=require('path');
const {renderApacheBridge,replaceManagedBlock,installApacheBridge,BEGIN_MARKER,END_MARKER}=require('../server/apache-bridge');
(async()=>{
const rendered=renderApacheBridge(8080);
assert.match(rendered,/RewriteRule \^api\/\(\.\*\)\$ http:\/\/127\.0\.0\.1:8080\/api\/\$1 \[P,L\]/);
assert.match(rendered,/ws:\/\/127\.0\.0\.1:8080\/api\/realtime/);
assert.match(rendered,/api-bridge\.php\?path=\/api\/\$1 \[QSA,L\]/);
assert.equal((rendered.match(new RegExp(BEGIN_MARKER,'g'))||[]).length,1);
assert.equal((rendered.match(new RegExp(END_MARKER,'g'))||[]).length,1);
const custom='Options -Indexes\n\n# custom rule\n';
const first=replaceManagedBlock(custom,rendered);
assert.match(first,/Options -Indexes/);
assert.match(first,/# custom rule/);
assert.match(first,/127\.0\.0\.1:8080/);
const replaced=replaceManagedBlock(first,renderApacheBridge(4312));
assert.match(replaced,/127\.0\.0\.1:4312/);
assert.doesNotMatch(replaced,/127\.0\.0\.1:8080/);
assert.equal((replaced.match(new RegExp(BEGIN_MARKER,'g'))||[]).length,1);
const root=await fsp.mkdtemp(path.join(os.tmpdir(),'linkfield-apache-'));
try{
await fsp.writeFile(path.join(root,'.htaccess'),custom);
const installed=await installApacheBridge({fsp,root,port:9123});
assert.equal(installed.enabled,true);
assert.equal(installed.written,true);
const actual=await fsp.readFile(path.join(root,'.htaccess'),'utf8');
assert.match(actual,/Options -Indexes/);
assert.match(actual,/127\.0\.0\.1:9123/);
const unchanged=await installApacheBridge({fsp,root,port:9123});
assert.equal(unchanged.written,false);
}finally{await fsp.rm(root,{recursive:true,force:true})}
console.log('LinkField v48.0 Apache bridge smoke test passed');
})().catch(error=>{console.error(error);process.exitCode=1});