Release v0.1.2

This commit is contained in:
winlifes
2026-04-30 18:12:29 +08:00
parent 8c46313ac6
commit a903f7f0af
12 changed files with 423 additions and 24 deletions
+38
View File
@@ -0,0 +1,38 @@
'use strict';
const assert = require('node:assert/strict');
const path = require('node:path');
const test = require('node:test');
const { isPathInside, resolveProjectPath } = require('../lib/path-safety');
test('resolveProjectPath resolves project-relative paths inside the project root', () => {
const root = path.resolve('/tmp/funplay-cocos-test-project');
assert.equal(resolveProjectPath(root, 'assets/player.ts'), path.join(root, 'assets', 'player.ts'));
});
test('resolveProjectPath allows absolute paths only when they stay inside the project root', () => {
const root = path.resolve('/tmp/funplay-cocos-test-project');
const inside = path.join(root, 'assets', 'scene.scene');
assert.equal(resolveProjectPath(root, inside), inside);
});
test('resolveProjectPath rejects path traversal outside the project root', () => {
const root = path.resolve('/tmp/funplay-cocos-test-project');
assert.throws(
() => resolveProjectPath(root, '../secret.txt'),
/outside the Cocos project/
);
});
test('resolveProjectPath rejects absolute paths outside the project root', () => {
const root = path.resolve('/tmp/funplay-cocos-test-project');
assert.throws(
() => resolveProjectPath(root, '/tmp/secret.txt'),
/outside the Cocos project/
);
});
test('isPathInside treats the project root as inside itself', () => {
const root = path.resolve('/tmp/funplay-cocos-test-project');
assert.equal(isPathInside(root, root), true);
});