forked from Crown-Studio/roblox-ts-template
62 lines
2.0 KiB
JavaScript
62 lines
2.0 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import test from "node:test";
|
|
import { URL } from "node:url";
|
|
import { runInNewContext } from "node:vm";
|
|
import ts from "typescript";
|
|
|
|
// Run the actual, engine-independent permission policy, not a duplicate of it.
|
|
const source = readFileSync(
|
|
new URL("../src/server/config/cmdr-permissions.ts", import.meta.url),
|
|
"utf8",
|
|
);
|
|
const compiled = ts.transpileModule(source, {
|
|
compilerOptions: { module: ts.ModuleKind.CommonJS },
|
|
}).outputText;
|
|
const policyModule = { exports: {} };
|
|
runInNewContext(compiled, {
|
|
exports: policyModule.exports,
|
|
module: policyModule,
|
|
});
|
|
const { isCmdrAllowed, CMDR_PERMISSIONS } = policyModule.exports;
|
|
|
|
test("published game denies ordinary players by default", () => {
|
|
assert.equal(isCmdrAllowed(42, false, 99), false);
|
|
});
|
|
|
|
test("Studio allows local testing without publishing or configuring an admin", () => {
|
|
assert.equal(isCmdrAllowed(-1, true, undefined), true);
|
|
});
|
|
|
|
test("experience owner is allowed in a user-owned published game", () => {
|
|
assert.equal(isCmdrAllowed(99, false, 99), true);
|
|
});
|
|
|
|
test("no user owner means no automatic permission in a group-owned game", () => {
|
|
assert.equal(isCmdrAllowed(99, false, undefined), false);
|
|
});
|
|
|
|
test("only explicitly listed users get allowlist access", () => {
|
|
const permissions = {
|
|
allowInStudio: false,
|
|
allowExperienceOwner: false,
|
|
adminUserIds: new Set([42]),
|
|
};
|
|
assert.equal(isCmdrAllowed(42, false, undefined, permissions), true);
|
|
assert.equal(isCmdrAllowed(43, false, undefined, permissions), false);
|
|
});
|
|
|
|
test("Studio and owner exceptions can both be disabled", () => {
|
|
const permissions = {
|
|
allowInStudio: false,
|
|
allowExperienceOwner: false,
|
|
adminUserIds: new Set(),
|
|
};
|
|
assert.equal(isCmdrAllowed(99, true, 99, permissions), false);
|
|
assert.equal(isCmdrAllowed(99, false, 99, permissions), false);
|
|
});
|
|
|
|
test("published default configuration contains no placeholder administrator", () => {
|
|
assert.equal(CMDR_PERMISSIONS.adminUserIds.size, 0);
|
|
});
|