41 lines
1.8 KiB
JavaScript
41 lines
1.8 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
import test from 'node:test'
|
|
import { spawnSync } from 'node:child_process'
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
const php = process.env.IAM_TEST_PHP || 'php'
|
|
const router = fileURLToPath(new URL('../server/scripts/project-api-router.php', import.meta.url))
|
|
const wrapper = `
|
|
$_SERVER['REQUEST_URI'] = $argv[2];
|
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
|
parse_str(parse_url($argv[2], PHP_URL_QUERY) ?? '', $_GET);
|
|
putenv('IAM_SOURCE_PROJECT_ROOT=/fixture-original-project-does-not-exist');
|
|
register_shutdown_function(static function () { echo "\\nBOUNDARY_STATUS=" . http_response_code(); });
|
|
require $argv[1];
|
|
`
|
|
function status(url) {
|
|
const result = spawnSync(php, ['-r', wrapper, router, url], { encoding: 'utf8', windowsHide: true })
|
|
if (result.error) throw result.error
|
|
assert.equal(result.status, 0, 'Boundary fixture must exit cleanly without loading an original project')
|
|
const match = result.stdout.match(/BOUNDARY_STATUS=(\d+)/)
|
|
assert.ok(match, 'Boundary status is missing')
|
|
return Number(match[1])
|
|
}
|
|
|
|
test('兼容路由参数不能覆盖白名单中的原项目接口', () => {
|
|
for (const query of [
|
|
's=/adminapi/login/checkDbColumn',
|
|
'%73=%2Fadminapi%2Fauth.admin%2Fdelete',
|
|
's[]=/api/other-action',
|
|
's=&s=/adminapi/login/checkDbColumn',
|
|
's=',
|
|
]) {
|
|
assert.equal(status('/adminapi/auth.admin/mySelf?' + query), 404)
|
|
}
|
|
})
|
|
test('合法分页保留原路径,调试路径和未知路径在加载原项目之前被拒绝', () => {
|
|
assert.equal(status('/adminapi/auth.admin/lists?page_no=1&page_size=15'), 503, 'Allowed route reaches only the deliberately missing project check')
|
|
assert.equal(status('/adminapi/login/checkDbColumn'), 404)
|
|
assert.equal(status('/api/other-action'), 404)
|
|
})
|